diff dmd/TypeClass.d @ 64:4290d870944a

More fixes
author korDen
date Mon, 23 Aug 2010 20:29:15 +0400
parents 51605de93870
children 2e2a5c3f943a
line wrap: on
line diff
--- a/dmd/TypeClass.d	Mon Aug 23 16:52:24 2010 +0400
+++ b/dmd/TypeClass.d	Mon Aug 23 20:29:15 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.Type;
 import dmd.ClassDeclaration;
+import dmd.TypeInstance;
 import dmd.Loc;
 import dmd.Dsymbol;
 import dmd.Scope;
@@ -10,6 +11,7 @@
 import dmd.Expression;
 import dmd.Identifier;
 import dmd.MATCH;
+import dmd.DYNCAST;
 import dmd.CppMangleState;
 import dmd.ArrayTypes;
 import dmd.TypeInfoDeclaration;
@@ -529,7 +531,53 @@
 	
     MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
 	{
-		assert(false);
+		//printf("TypeClass.deduceType(this = %s)\n", toChars());
+
+		/* If this class is a template class, and we're matching
+		 * it against a template instance, convert the class type
+		 * to a template instance, too, and try again.
+		 */
+		TemplateInstance ti = sym.parent.isTemplateInstance();
+
+		if (tparam && tparam.ty == Tinstance)
+		{
+			if (ti && ti.toAlias() == sym)
+			{
+				TypeInstance t = new TypeInstance(Loc(0), ti);
+				return t.deduceType(sc, tparam, parameters, dedtypes);
+			}
+
+			/* Match things like:
+			 *  S!(T).foo
+			 */
+			TypeInstance tpi = cast(TypeInstance)tparam;
+			if (tpi.idents.dim)
+			{   Identifier id = cast(Identifier)tpi.idents.data[tpi.idents.dim - 1];
+				if (id.dyncast() == DYNCAST.DYNCAST_IDENTIFIER && sym.ident.equals(id))
+				{
+					Type tparent = sym.parent.getType();
+					if (tparent)
+					{
+						/* Slice off the .foo in S!(T).foo
+						 */
+						tpi.idents.dim--;
+						MATCH m = tparent.deduceType(sc, tpi, parameters, dedtypes);
+						tpi.idents.dim++;
+						return m;
+					}
+				}
+			}
+		}
+
+		// Extra check
+		if (tparam && tparam.ty == Tclass)
+		{
+			TypeClass tp = cast(TypeClass)tparam;
+
+			//printf("\t%d\n", (MATCH) implicitConvTo(tp));
+			return implicitConvTo(tp);
+		}
+		return Type.deduceType(sc, tparam, parameters, dedtypes);
 	}
 	
     bool isauto()