2009-08-13 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / anonymous.cs
index e98f07b4887f2049643ce3270dd01b2a20d072b4..fed1f93bccd7a6b455189f083b9c4e8ae58c5a6b 100644 (file)
@@ -550,8 +550,11 @@ namespace Mono.CSharp {
                        if (TypeManager.IsGenericType (field.DeclaringType)) {
                                Type t = MutateGenericType (field.DeclaringType);
                                if (t != field.DeclaringType) {
-                                       // TODO: It should throw on imported types
-                                       return TypeBuilder.GetField (t, field);
+                                       field = TypeManager.DropGenericTypeArguments (field.DeclaringType).GetField (field.Name, TypeManager.AllMembers);
+                                       if (field.Module == Module.Builder)
+                                               return TypeBuilder.GetField (t, field);
+
+                                       return FieldInfo.GetFieldFromHandle (field.FieldHandle, t.TypeHandle);                                          
                                }
                        }
 #endif
@@ -561,7 +564,6 @@ namespace Mono.CSharp {
 #if GMCS_SOURCE
                protected Type MutateArrayType (Type array)
                {
-                       int rank = array.GetArrayRank ();
                        Type element = TypeManager.GetElementType (array);
                        if (element.IsArray) {
                                element = MutateArrayType (element);
@@ -573,6 +575,10 @@ namespace Mono.CSharp {
                                return array;
                        }
 
+                       int rank = array.GetArrayRank ();
+                       if (rank == 1)
+                               return element.MakeArrayType ();
+
                        return element.MakeArrayType (rank);
                }
 
@@ -708,7 +714,10 @@ namespace Mono.CSharp {
                        }
 
                        if (inner_access == null) {
-                               inner_access = new FieldExpr (field.FieldBuilder, field.Location);
+                               inner_access = field.Parent.MemberName.IsGeneric ?
+                                       new FieldExpr (field.FieldBuilder, field.Parent.CurrentType, field.Location) :
+                                       new FieldExpr (field.FieldBuilder, field.Location);
+                                                       
                                inner_access.InstanceExpression = storey.GetStoreyInstanceExpression (ec);
                                inner_access.Resolve (ec);
                                cached_inner_access.Add (ec.CurrentAnonymousMethod, inner_access);
@@ -999,16 +1008,12 @@ namespace Mono.CSharp {
                {
                        AnonymousMethodBody am;
                        using (ec.Set (EmitContext.Flags.ProbingMode | EmitContext.Flags.InferReturnType)) {
-                               am = CompatibleMethod (ec, tic, TypeManager.null_type, delegate_type);
+                               am = CompatibleMethod (ec, tic, InternalType.Arglist, delegate_type);
                        }
                        
                        if (am == null)
                                return null;
 
-                       // Stop referencing gmcs NullLiteral type
-                       if (am.ReturnType == TypeManager.null_type)
-                               am.ReturnType = null;
-
                        return am.ReturnType;
                }
 
@@ -1302,8 +1307,10 @@ namespace Mono.CSharp {
 
                        IDisposable aec_dispose = null;
                        EmitContext.Flags flags = 0;
-                       if (ec.InferReturnType)
+                       if (ec.InferReturnType) {
                                flags |= EmitContext.Flags.InferReturnType;
+                               aec.ReturnTypeInference = new TypeInferenceContext ();
+                       }
 
                        if (ec.IsInProbingMode)
                                flags |= EmitContext.Flags.ProbingMode;
@@ -1321,8 +1328,10 @@ namespace Mono.CSharp {
                        bool unreachable;
                        bool res = aec.ResolveTopBlock (ec, Block, Block.Parameters, null, out unreachable);
 
-                       if (ec.InferReturnType)
-                               ReturnType = aec.ReturnType;
+                       if (ec.InferReturnType) {
+                               aec.ReturnTypeInference.FixAllTypes ();
+                               ReturnType = aec.ReturnTypeInference.InferredTypeArguments [0];
+                       }
 
                        if (aec_dispose != null) {
                                aec_dispose.Dispose ();
@@ -1806,9 +1815,10 @@ namespace Mono.CSharp {
 
                        //
                        // Equals (object obj) override
-                       //
+                       //              
+                       LocalVariableReference other_variable_assign = new LocalVariableReference (equals_block, "other", loc);
                        equals_block.AddStatement (new StatementExpression (
-                               new SimpleAssign (other_variable,
+                               new SimpleAssign (other_variable_assign,
                                        new As (equals_block.GetParameterReference ("obj", loc),
                                                current_type, loc), loc)));
 
@@ -1849,8 +1859,9 @@ namespace Mono.CSharp {
 
                        hashcode_block.AddVariable (TypeManager.system_int32_expr, "hash", loc);
                        LocalVariableReference hash_variable = new LocalVariableReference (hashcode_block, "hash", loc);
+                       LocalVariableReference hash_variable_assign = new LocalVariableReference (hashcode_block, "hash", loc);
                        hashcode_block.AddStatement (new StatementExpression (
-                               new SimpleAssign (hash_variable, rs_hashcode)));
+                               new SimpleAssign (hash_variable_assign, rs_hashcode)));
 
                        hashcode_block.AddStatement (new StatementExpression (
                                new CompoundAssign (Binary.Operator.Addition, hash_variable,