[mono/mono] [2 commits] 3fbd4b87: Cache only resolved types not expression to report correct error location. Fixes #15035

"Marek Safar ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <000001419374f0be-10e51b84-4409-46de-ac02-b2675d7b7ae3-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/2a52ec9e367b...43a0a9d47fb5

   Commit: 3fbd4b873c76d01f900a10a6e02dd6d38c376914
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-10-07 13:04:09 GMT
      URL: https://github.com/mono/mono/commit/3fbd4b873c76d01f900a10a6e02dd6d38c376914

Cache only resolved types not expression to report correct error location. Fixes #15035

Changed paths:
  M mcs/mcs/assembly.cs
  M mcs/mcs/dynamic.cs
  M mcs/mcs/namespace.cs

Modified: mcs/mcs/assembly.cs
===================================================================
@@ -919,7 +919,7 @@ void SetEntryPoint ()
 						return;
 					}
 
-					var mtype = texpr.Type.MemberDefinition as ClassOrStruct;
+					var mtype = texpr.MemberDefinition as ClassOrStruct;
 					if (mtype == null) {
 						Report.Error (1556, "`{0}' specified for Main method must be a valid class or struct", main_class);
 						return;

Modified: mcs/mcs/dynamic.cs
===================================================================
@@ -391,7 +391,7 @@ protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments,
 			if (!has_ref_out_argument) {
 				string d_name = isStatement ? "Action" : "Func";
 
-				TypeExpr te = null;
+				TypeSpec te = null;
 				Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true);
 				if (type_ns != null) {
 					te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, LookupMode.Normal, loc);
@@ -412,9 +412,9 @@ protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments,
 						targs[targs.Length - 1] = new TypeExpression (t, loc);
 					}
 
-					del_type = new GenericTypeExpr (te.Type, new TypeArguments (targs), loc);
+					del_type = new GenericTypeExpr (te, new TypeArguments (targs), loc);
 					if (targs_for_instance != null)
-						del_type_instance_access = new GenericTypeExpr (te.Type, new TypeArguments (targs_for_instance), loc);
+						del_type_instance_access = new GenericTypeExpr (te, new TypeArguments (targs_for_instance), loc);
 					else
 						del_type_instance_access = del_type;
 				}

Modified: mcs/mcs/namespace.cs
===================================================================
@@ -125,7 +125,7 @@ public class Namespace : FullNamedExpression
 		protected Dictionary<string, Namespace> namespaces;
 		protected Dictionary<string, IList<TypeSpec>> types;
 		List<TypeSpec> extension_method_types;
-		Dictionary<string, TypeExpr> cached_types;
+		Dictionary<string, TypeSpec> cached_types;
 		RootNamespace root;
 		bool cls_checked;
 
@@ -171,7 +171,7 @@ public Namespace (Namespace parent, string name)
 				MemberName = new MemberName (name, Location.Null);
 
 			namespaces = new Dictionary<string, Namespace> ();
-			cached_types = new Dictionary<string, TypeExpr> ();
+			cached_types = new Dictionary<string, TypeSpec> ();
 
 			root.RegisterNamespace (this);
 		}
@@ -204,14 +204,14 @@ public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int ar
 		{
 			var retval = LookupType (ctx, name, arity, LookupMode.IgnoreAccessibility, loc);
 			if (retval != null) {
-				ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (retval.Type);
+//				ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (retval.MemberDefinition);
 				ErrorIsInaccesible (ctx, retval.GetSignatureForError (), loc);
 				return;
 			}
 
 			retval = LookupType (ctx, name, -System.Math.Max (1, arity), LookupMode.Probing, loc);
 			if (retval != null) {
-				Error_TypeArgumentsCannotBeUsed (ctx, retval.Type, loc);
+				Error_TypeArgumentsCannotBeUsed (ctx, retval, loc);
 				return;
 			}
 
@@ -327,20 +327,21 @@ public IList<TypeSpec> GetAllTypes (string name)
 			return found;
 		}
 
-		public TypeExpr LookupType (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
+		public TypeSpec LookupType (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
 		{
 			if (types == null)
 				return null;
 
-			TypeExpr te;
-			if (arity == 0 && cached_types.TryGetValue (name, out te))
-				return te;
+			TypeSpec best = null;
+			if (arity == 0 && cached_types.TryGetValue (name, out best)) {
+				if (best != null || mode != LookupMode.IgnoreAccessibility)
+					return best;
+			}
 
 			IList<TypeSpec> found;
 			if (!types.TryGetValue (name, out found))
 				return null;
 
-			TypeSpec best = null;
 			foreach (var ts in found) {
 				if (ts.Arity == arity) {
 					if (best == null) {
@@ -391,16 +392,11 @@ public TypeExpr LookupType (IMemberContext ctx, string name, int arity, LookupMo
 				}
 			}
 
-			if (best == null)
-				return null;
-
-			te = new TypeExpression (best, Location.Null);
-
 			// TODO MemberCache: Cache more
 			if (arity == 0 && mode == LookupMode.Normal)
-				cached_types.Add (name, te);
+				cached_types.Add (name, best);
 
-			return te;
+			return best;
 		}
 
 		public FullNamedExpression LookupTypeOrNamespace (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
@@ -413,18 +409,21 @@ public FullNamedExpression LookupTypeOrNamespace (IMemberContext ctx, string nam
 					return ns;
 
 				if (mode != LookupMode.Probing) {
-					ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (texpr.Type);
+					//ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (texpr.Type);
 					// ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ns.loc, "");
 					ctx.Module.Compiler.Report.Warning (437, 2, loc,
 						"The type `{0}' conflicts with the imported namespace `{1}'. Using the definition found in the source file",
 						texpr.GetSignatureForError (), ns.GetSignatureForError ());
 				}
 
-				if (texpr.Type.MemberDefinition.IsImported)
+				if (texpr.MemberDefinition.IsImported)
 					return ns;
 			}
 
-			return texpr;
+			if (texpr == null)
+				return null;
+
+			return new TypeExpression (texpr, loc);
 		}
 
 		//
@@ -873,7 +872,7 @@ void AddAlias (UsingAliasNamespace un)
 		public override void AddPartial (TypeDefinition next_part)
 		{
 			var existing = ns.LookupType (this, next_part.MemberName.Name, next_part.MemberName.Arity, LookupMode.Probing, Location.Null);
-			var td = existing != null ? existing.Type.MemberDefinition as TypeDefinition : null;
+			var td = existing != null ? existing.MemberDefinition as TypeDefinition : null;
 			AddPartial (next_part, td);
 		}
 
@@ -1172,10 +1171,11 @@ FullNamedExpression Lookup (string name, int arity, LookupMode mode, Location lo
 				// A using directive imports only types contained in the namespace, it
 				// does not import any nested namespaces
 				//
-				fne = using_ns.LookupType (this, name, arity, mode, loc);
-				if (fne == null)
+				var t = using_ns.LookupType (this, name, arity, mode, loc);
+				if (t == null)
 					continue;
 
+				fne = new TypeExpression (t, loc);
 				if (match == null) {
 					match = fne;
 					continue;

   Commit: 43a0a9d47fb5e6cf997d7191df6e68284adf4414
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-10-07 15:04:13 GMT
      URL: https://github.com/mono/mono/commit/43a0a9d47fb5e6cf997d7191df6e68284adf4414

Inline more is instance checks

Changed paths:
  M mcs/mcs/expression.cs
  M mcs/mcs/statement.cs
  M mcs/tests/ver-il-net_4_5.xml

Modified: mcs/mcs/expression.cs
===================================================================
@@ -1536,11 +1536,17 @@ protected override Expression DoResolve (ResolveContext ec)
 					}
 				} else {
 					if (Convert.ImplicitReferenceConversionExists (d, t)) {
+						var c = expr as Constant;
+						if (c != null)
+							return CreateConstantResult (ec, !c.IsNull);
+
 						//
 						// Do not optimize for imported type
 						//
-						if (d.MemberDefinition.IsImported && d.BuiltinType != BuiltinTypeSpec.Type.None)
+						if (d.MemberDefinition.IsImported && d.BuiltinType != BuiltinTypeSpec.Type.None &&
+							d.MemberDefinition.DeclaringAssembly != t.MemberDefinition.DeclaringAssembly) {
 							return this;
+						}
 						
 						//
 						// Turn is check into simple null check for implicitly convertible reference types

Modified: mcs/mcs/statement.cs
===================================================================
@@ -51,6 +51,10 @@ public virtual bool ResolveUnreachable (BlockContext ec, bool warn)
 
 			bool unreachable = false;
 			if (warn && !ec.UnreachableReported) {
+
+				// TODO: This is wrong, need to form of flow-analysis branch specific flag
+				// or multiple unrelared unreachable code won't be reported
+				// if (false) { // ok } if (false) { // not reported }
 				ec.UnreachableReported = true;
 				unreachable = true;
 				ec.Report.Warning (162, 2, loc, "Unreachable code detected");
@@ -187,7 +191,6 @@ public override bool Resolve (BlockContext ec)
 				//
 				if (expr is Constant) {
 					bool take = !((Constant) expr).IsDefaultValue;
-
 					if (take) {
 						if (!TrueStatement.Resolve (ec))
 							return false;

Modified: mcs/tests/ver-il-net_4_5.xml
===================================================================
@@ -29946,7 +29946,7 @@
         <size>10</size>
       </method>
       <method name="Int32 Main()" attrs="150">
-        <size>125</size>
+        <size>115</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
@@ -42222,7 +42222,7 @@
   <test name="test-609.cs">
     <type name="Test">
       <method name="Int32 Main()" attrs="150">
-        <size>54</size>
+        <size>10</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>



_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.