// return null;
var container = PartialContainer.CurrentType;
- return MemberCache.FindNestedType (container, name, arity);
+ return MemberCache.FindNestedType (container, name, arity, false);
}
public void Mark_HasEquals ()
TypeExpr texpr = left as TypeExpr;
if (texpr != null) {
- var found = MemberCache.FindNestedType (texpr.Type, mn.Name, mn.Arity);
+ var found = MemberCache.FindNestedType (texpr.Type, mn.Name, mn.Arity, false);
if (found != null)
return new TypeExpression (found, Location.Null);
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) {
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);
TypeSpec nested = null;
while (expr_type != null) {
- nested = MemberCache.FindNestedType (expr_type, Name, Arity);
+ nested = MemberCache.FindNestedType (expr_type, Name, Arity, false);
if (nested == null) {
if (expr_type == tnew_expr) {
Error_IdentifierNotFound (rc, expr_type);
}
expr_type = tnew_expr;
- nested = MemberCache.FindNestedType (expr_type, Name, Arity);
+ nested = MemberCache.FindNestedType (expr_type, Name, Arity, false);
ErrorIsInaccesible (rc, nested.GetSignatureForError (), loc);
break;
}
public void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type)
{
- var nested = MemberCache.FindNestedType (expr_type, Name, -System.Math.Max (1, Arity));
+ var nested = MemberCache.FindNestedType (expr_type, Name, -System.Math.Max (1, Arity), false);
if (nested != null) {
Error_TypeArgumentsCannotBeUsed (rc, nested, expr.Location);
// Parent was inflated, find the same type on inflated type
// to use same cache for nested types on same generic parent
//
- type = MemberCache.FindNestedType (parent, type.Name, type.Arity);
+ type = MemberCache.FindNestedType (parent, type.Name, type.Arity, false);
//
// Handle the tricky case where parent shares local type arguments
if (t.Kind == MemberKind.MissingType)
spec = t;
else
- spec = MemberCache.FindNestedType (spec, t.Name, t.Arity);
+ spec = MemberCache.FindNestedType (spec, t.Name, t.Arity, false);
if (t.Arity > 0) {
spec = spec.MakeGenericType (module, targs.Skip (targs_pos).Take (spec.Arity).ToArray ());
if (index > 0)
name = name.Substring (0, index);
- spec = MemberCache.FindNestedType (spec, name, targs.Length - targs_pos);
+ spec = MemberCache.FindNestedType (spec, name, targs.Length - targs_pos, false);
if (spec.Arity > 0) {
spec = spec.MakeGenericType (module, targs.Skip (targs_pos).ToArray ());
//
// Finds the nested type in container
//
- public static TypeSpec FindNestedType (TypeSpec container, string name, int arity)
+ public static TypeSpec FindNestedType (TypeSpec container, string name, int arity, bool declaredOnlyClass)
{
IList<MemberSpec> applicable;
TypeSpec best_match = null;
if (arity < 0) {
if (best_match == null) {
best_match = ts;
- } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (ts.Arity + arity)) {
+ } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best_match.Arity + arity)) {
best_match = ts;
}
}
}
container = container.BaseType;
- } while (container != null);
+ } while (container != null && !declaredOnlyClass);
return best_match;
}
if (types_using_table != null) {
foreach (var using_type in types_using_table) {
- var members = MemberCache.FindMembers (using_type, name, true);
- if (members == null)
+ var type = MemberCache.FindNestedType (using_type, name, arity, true);
+ if (type == null)
continue;
+
+ fne = new TypeExpression (type, loc);
+ if (match == null) {
+ match = fne;
+ continue;
+ }
- foreach (var member in members) {
- if (arity > 0 && member.Arity != arity)
- continue;
-
- if ((member.Kind & MemberKind.NestedMask) != 0) {
- // non-static nested type is included with using static
- } else {
- if ((member.Modifiers & Modifiers.STATIC) == 0)
- continue;
-
- if ((member.Modifiers & Modifiers.METHOD_EXTENSION) != 0)
- continue;
-
- if (mode == LookupMode.Normal)
- continue;
-
- return null;
- }
-
- fne = new TypeExpression ((TypeSpec) member, loc);
- if (match == null) {
- match = fne;
- continue;
- }
-
- if (mode == LookupMode.Normal) {
- Error_AmbiguousReference (name, match, fne, loc);
- }
+ if (mode == LookupMode.Normal) {
+ Error_AmbiguousReference (name, match, fne, loc);
}
}
}
--- /dev/null
+namespace A.B
+{
+ public static class G<T>
+ {
+ public class DD
+ {
+ }
+
+ public static object Dock () => null;
+ }
+}
+
+namespace N2
+{
+ using static A.B.G<int>;
+
+ class M : DD
+ {
+ public static void Main ()
+ {
+ Dock ();
+ }
+ }
+}
</method>
</type>
</test>
+ <test name="test-static-using-12.cs">
+ <type name="A.B.G`1[T]">
+ <method name="System.Object Dock()" attrs="150">
+ <size>9</size>
+ </method>
+ </type>
+ <type name="A.B.G`1+DD[T]">
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ <type name="N2.M">
+ <method name="Void Main()" attrs="150">
+ <size>8</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">