From 76f0a58429b4cfb47c77935cfca6ce88ce9be53e Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 1 Jun 2017 15:25:31 +0200 Subject: [PATCH] [mcs] Moves using static lookup at the end of simple name lookup rules. Fixes #55348 --- mcs/mcs/context.cs | 3 ++- mcs/mcs/ecore.cs | 26 +++++++++++++++----------- mcs/mcs/namespace.cs | 2 +- mcs/tests/test-static-using-13.cs | 21 +++++++++++++++++++++ mcs/tests/ver-il-net_4_x.xml | 10 ++++++++++ 5 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 mcs/tests/test-static-using-13.cs diff --git a/mcs/mcs/context.cs b/mcs/mcs/context.cs index ddcb149f942..24bccb69187 100644 --- a/mcs/mcs/context.cs +++ b/mcs/mcs/context.cs @@ -22,7 +22,8 @@ namespace Mono.CSharp { Normal = 0, Probing = 1, - IgnoreAccessibility = 2 + IgnoreAccessibility = 2, + IgnoreStaticUsing = 1 << 10 } // diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index 99ba10dcb9d..4d472070a00 100644 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -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); diff --git a/mcs/mcs/namespace.cs b/mcs/mcs/namespace.cs index 5384ee13686..3314ca2d48c 100644 --- a/mcs/mcs/namespace.cs +++ b/mcs/mcs/namespace.cs @@ -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 index 00000000000..67605391800 --- /dev/null +++ b/mcs/tests/test-static-using-13.cs @@ -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; +} diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index ba198950ecb..84e616ca01f 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -72776,6 +72776,16 @@ + + + + 4 + + + 7 + + + -- 2.25.1