diff dmd/FuncDeclaration.d @ 79:43073c7c7769

updated to 2.035 also implemented a few missing functions still crashes in Import.importAll though
author Trass3r
date Mon, 30 Aug 2010 03:57:51 +0200
parents ad4792a1cfd6
children be2ab491772e b17640f0e4e8
line wrap: on
line diff
--- a/dmd/FuncDeclaration.d	Sun Aug 29 14:39:08 2010 +0100
+++ b/dmd/FuncDeclaration.d	Mon Aug 30 03:57:51 2010 +0200
@@ -278,7 +278,8 @@
 		InterfaceDeclaration id;
 		Dsymbol pd;
 
-static if (false) {
+static if (false)
+{
 		printf("FuncDeclaration.semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc.linkage);
 		if (isFuncLiteralDeclaration())
 			printf("\tFuncLiteralDeclaration()\n");
@@ -288,12 +289,12 @@
 
 		if (semanticRun && isFuncLiteralDeclaration())
 		{
-		/* Member functions that have return types that are
-		 * forward references can have semantic() run more than
-		 * once on them.
-		 * See test\interface2.d, test20
-		 */
-		return;
+			/* Member functions that have return types that are
+			 * forward references can have semantic() run more than
+			 * once on them.
+			 * See test\interface2.d, test20
+			 */
+			return;
 		}
 		assert(semanticRun <= 1);
 		semanticRun = 1;
@@ -302,52 +303,53 @@
 		//printf("function storage_class = x%x\n", storage_class);
 
 		if (!originalType)
-		originalType = type;
+			originalType = type;
 		if (!type.deco)
 		{
-		/* Apply const and invariant storage class
-		 * to the function type
-		 */
-		type = type.semantic(loc, sc);
-		STC stc = storage_class;
-		if (type.isInvariant())
-			stc |= STC.STCimmutable;
-		if (type.isConst())
-			stc |= STC.STCconst;
-		if (type.isShared() || storage_class & STC.STCsynchronized)
-			stc |= STC.STCshared;
-		switch (stc & STC.STC_TYPECTOR)
-		{
-			case STC.STCimmutable:
-			case STC.STCimmutable | STC.STCconst:
-			case STC.STCimmutable | STC.STCconst | STC.STCshared:
-			case STC.STCimmutable | STC.STCshared:
-			// Don't use toInvariant(), as that will do a merge()
-			type = type.makeInvariant();
-			type.deco = type.merge().deco;
-			break;
-
-			case STC.STCconst:
-			type = type.makeConst();
-			type.deco = type.merge().deco;
-			break;
-
-			case STC.STCshared | STC.STCconst:
-			type = type.makeSharedConst();
-			type.deco = type.merge().deco;
-			break;
-
-			case STC.STCshared:
-			type = type.makeShared();
-			type.deco = type.merge().deco;
-			break;
-
-			case STC.STCundefined:
-			break;
-
-			default:
-			assert(0);
-		}
+			/* Apply const and invariant storage class
+			 * to the function type
+			 */
+			type = type.semantic(loc, sc);
+			STC stc = storage_class;
+			if (type.isInvariant())
+				stc |= STC.STCimmutable;
+			if (type.isConst())
+				stc |= STC.STCconst;
+			if (type.isShared() || storage_class & STC.STCsynchronized)
+				stc |= STC.STCshared;
+			switch (stc & STC.STC_TYPECTOR)
+			{
+				case STC.STCimmutable:
+				case STC.STCimmutable | STC.STCconst:
+				case STC.STCimmutable | STC.STCconst | STC.STCshared:
+				case STC.STCimmutable | STC.STCshared:
+				// Don't use toInvariant(), as that will do a merge()
+				type = type.makeInvariant();
+				goto Lmerge;
+	
+				case STC.STCconst:
+				type = type.makeConst();
+				goto Lmerge;
+	
+				case STC.STCshared | STC.STCconst:
+				type = type.makeSharedConst();
+				goto Lmerge;
+	
+				case STC.STCshared:
+				type = type.makeShared();
+				Lmerge:
+					if (!(type.ty == Tfunction && !type.nextOf()))
+						/* Can't do merge if return type is not known yet
+					     */
+						type.deco = type.merge().deco;
+				break;
+	
+				case STC.STCundefined:
+				break;
+	
+				default:
+				assert(0);
+			}
 		}
 		//type.print();
 		if (type.ty != TY.Tfunction)
@@ -742,7 +744,9 @@
 			goto Lmainerr;
 		}
 
-		if (f.nextOf().ty != TY.Tint32 && f.nextOf().ty != TY.Tvoid)
+		if (!f.nextOf())
+			error("must return int or void");
+		else if (f.nextOf().ty != TY.Tint32 && f.nextOf().ty != TY.Tvoid)
 			error("must return int or void, not %s", f.nextOf().toChars());
 		if (f.varargs)
 		{
@@ -1155,8 +1159,19 @@
 		}
 
 		if (fensure || addPostInvariant())
-		{   /* fensure is composed of the [out] contracts
+		{
+			/* fensure is composed of the [out] contracts
 			 */
+			if (!type.nextOf())		// if return type is inferred
+		    {
+				/* This case:
+				 *   auto fp = function() out { } body { };
+				 * Can fix by doing semantic() onf fbody first.
+				 */
+				error("post conditions are not supported if the return type is inferred");
+				return;
+		    }
+			
 			ScopeDsymbol sym = new ScopeDsymbol();
 			sym.parent = sc2.scopesym;
 			sc2 = sc2.push(sym);
@@ -1275,11 +1290,11 @@
 			 */
 			if (isCtorDeclaration() && cd)
 			{
-			for (int i = 0; i < cd.fields.dim; i++)
-			{   VarDeclaration v = cast(VarDeclaration)cd.fields.data[i];
-
-				v.ctorinit = 0;
-			}
+				for (int i = 0; i < cd.fields.dim; i++)
+				{   VarDeclaration v = cast(VarDeclaration)cd.fields[i];
+	
+					v.ctorinit = 0;
+				}
 			}
 
 			if (inferRetType || f.retStyle() != RET.RETstack)
@@ -1328,7 +1343,7 @@
 				if (!(sc2.callSuper & CSX.CSXthis_ctor))
 				{
 					for (int i = 0; i < cd.fields.dim; i++)
-					{   VarDeclaration v = cast(VarDeclaration)cd.fields.data[i];
+					{   VarDeclaration v = cast(VarDeclaration)cd.fields[i];
 
 					if (v.ctorinit == 0 && v.isCtorinit())
 						error("missing initializer for final field %s", v.toChars());