[mcs] Moves using static lookup at the end of simple name lookup rules. Fixes #55348
authorMarek Safar <marek.safar@gmail.com>
Thu, 1 Jun 2017 13:25:31 +0000 (15:25 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 1 Jun 2017 13:27:30 +0000 (15:27 +0200)
mcs/mcs/context.cs
mcs/mcs/ecore.cs
mcs/mcs/namespace.cs
mcs/tests/test-static-using-13.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index ddcb149f942a7c818e78b848558ae693882132d1..24bccb69187473eb813014477e5d9c7db1f4ab81 100644 (file)
@@ -22,7 +22,8 @@ namespace Mono.CSharp
        {
                Normal = 0,
                Probing = 1,
-               IgnoreAccessibility = 2
+               IgnoreAccessibility = 2,
+               IgnoreStaticUsing = 1 << 10
        }
 
        //
index 99ba10dcb9dce06e5e15819cc5bbd6345131bc92..4d472070a006bf87d04ff839d8260f1a6d20a894 100644 (file)
@@ -2762,9 +2762,13 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               public bool IsPossibleTypeOrNamespace (IMemberContext mc)
+               bool IsPossibleTypeOrNamespace (IMemberContext mc)
                {
-                       return mc.LookupNamespaceOrType (Name, Arity, LookupMode.Probing, loc) != null;
+                       //
+                       // Has to ignore static usings because we are looking for any member not just type
+                       // in this context
+                       //
+                       return mc.LookupNamespaceOrType (Name, Arity, LookupMode.Probing | LookupMode.IgnoreStaticUsing, loc) != null;
                }
 
                public bool IsPossibleType (IMemberContext mc)
@@ -2886,6 +2890,15 @@ namespace Mono.CSharp {
                                        return me;
                                }
 
+                               //
+                               // Stage 3: Lookup nested types, namespaces and type parameters in the context
+                               //
+                               if ((restrictions & MemberLookupRestrictions.InvocableOnly) == 0 && !variable_found) {
+                                       if (IsPossibleTypeOrNamespace (rc)) {
+                                               return ResolveAsTypeOrNamespace (rc, false);
+                                       }
+                               }
+
                                var expr = NamespaceContainer.LookupStaticUsings (rc, Name, Arity, loc);
                                if (expr != null) {
                                        if (Arity > 0) {
@@ -2898,15 +2911,6 @@ namespace Mono.CSharp {
                                        return expr;
                                }
 
-                               //
-                               // Stage 3: Lookup nested types, namespaces and type parameters in the context
-                               //
-                               if ((restrictions & MemberLookupRestrictions.InvocableOnly) == 0 && !variable_found) {
-                                       if (IsPossibleTypeOrNamespace (rc)) {
-                                               return ResolveAsTypeOrNamespace (rc, false);
-                                       }
-                               }
-
                                if ((restrictions & MemberLookupRestrictions.NameOfExcluded) == 0 && Name == "nameof")
                                        return new NameOf (this);
 
index 5384ee1368607a30ea61290b5f19610aa15349e0..3314ca2d48c24d8341e6c44faf7523343d0fc182 100644 (file)
@@ -1157,7 +1157,7 @@ namespace Mono.CSharp {
                                        match = texpr_fne;
                        }
 
-                       if (types_using_table != null) {
+                       if (types_using_table != null && (mode & LookupMode.IgnoreStaticUsing) == 0) {
                                foreach (var using_type in types_using_table) {
                                        var type = MemberCache.FindNestedType (using_type, name, arity, true);
                                        if (type == null)
diff --git a/mcs/tests/test-static-using-13.cs b/mcs/tests/test-static-using-13.cs
new file mode 100644 (file)
index 0000000..6760539
--- /dev/null
@@ -0,0 +1,21 @@
+using System;
+using static TestClass;
+
+internal class Program
+{
+       public static void Main (string[] args)
+       {
+               var res = Directions.Up;
+       }
+}
+
+public enum Directions
+{
+       Up,
+       NotUp,
+}
+
+public static class TestClass
+{
+       public static int Directions;
+}
index ba198950ecb0d34e6f3ae94feaf94a94fdd5f11a..84e616ca01f884a29f29c11f935c004cb5d9b9be 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-static-using-13.cs">
+    <type name="Program">
+      <method name="Void Main(System.String[])" attrs="150">
+        <size>4</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-var-01.cs">
     <type name="Test">
       <method name="Int32 Main()" attrs="150">