diff dmd/VarDeclaration.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children af1bebfd96a4
line wrap: on
line diff
--- a/dmd/VarDeclaration.d	Sun Sep 05 15:32:22 2010 +0400
+++ b/dmd/VarDeclaration.d	Thu Sep 09 22:51:44 2010 +0100
@@ -33,7 +33,7 @@
 import dmd.Initializer;
 import dmd.TypeStruct;
 import dmd.TypeTuple;
-import dmd.Argument;
+import dmd.Parameter;
 import dmd.ExpInitializer;
 import dmd.ArrayTypes;
 import dmd.Dsymbol;
@@ -198,10 +198,31 @@
 		if (!type)
 		{	
 			inuse++;
-			type = init.inferType(sc);
+			
+			ArrayInitializer ai = init.isArrayInitializer();
+			if (ai)
+			{
+				Expression e;
+				if (ai.isAssociativeArray())
+					e = ai.toAssocArrayLiteral();
+				else
+					e = init.toExpression();
+				init = new ExpInitializer(e.loc, e);
+				type = init.inferType(sc);
+				if (type.ty == TY.Tsarray)
+					type = type.nextOf().arrayOf();
+			}
+			else
+				type = init.inferType(sc);
+			
 			inuse--;
 			inferred = 1;
 
+			if (init.isArrayInitializer() && type.toBasetype().ty == TY.Tsarray)
+			{   // Prefer array literals to give a T[] type rather than a T[dim]
+				type = type.toBasetype().nextOf().arrayOf();
+			}
+			
 			/* This is a kludge to support the existing syntax for RAII
 			 * declarations.
 			 */
@@ -226,11 +247,18 @@
 		//printf("storage_class = x%x\n", storage_class);
 
 version (DMDV2) {
+static if (true) {
+		if (storage_class & STC.STCgshared && sc.func && sc.func.isSafe())
+		{
+		error("__gshared not allowed in safe functions; use shared");
+		}
+} else {
 		if (storage_class & STC.STCgshared && global.params.safe && !sc.module_.safe)
 		{
 		error("__gshared not allowed in safe mode; use shared");
 		}
 }
+}
 
 		Dsymbol parent = toParent();
 		FuncDeclaration fd = parent.isFuncDeclaration();
@@ -260,15 +288,15 @@
 			* and add those.
 			*/
 		TypeTuple tt = cast(TypeTuple)tb;
-		size_t nelems = Argument.dim(tt.arguments);
+		size_t nelems = Parameter.dim(tt.arguments);
 		Objects exps = new Objects();
 		exps.setDim(nelems);
 		Expression ie = init ? init.toExpression() : null;
 
 		for (size_t i = 0; i < nelems; i++)
-		{   Argument arg = Argument.getNth(tt.arguments, i);
+		{   auto arg = Parameter.getNth(tt.arguments, i);
 
-			OutBuffer buf = new OutBuffer();
+			auto buf = new OutBuffer();
 			///buf.printf("_%s_field_%zu", ident.toChars(), i);
 			buf.printf("_%s_field_%s", ident.toChars(), i);
 			buf.writeByte(0);
@@ -473,7 +501,8 @@
 		ArrayInitializer ai = init.isArrayInitializer();
 		if (ai && tb.ty == TY.Taarray)
 		{
-			init = ai.toAssocArrayInitializer();
+			Expression e = ai.toAssocArrayLiteral();
+			init = new ExpInitializer(e.loc, e);
 		}
 
 		StructInitializer si = init.isStructInitializer();