readonly Dictionary<string, IList<MemberSpec>> member_hash;
Dictionary<string, MemberSpec[]> locase_members;
IList<MethodSpec> missing_abstract;
- StateFlags state;
+ StateFlags state; // TODO: Move to TypeSpec or ITypeDefinition
public static readonly string IndexerNameAlias = "<this>";
//
// Looks for extension methods with defined name and extension type
//
- public List<MethodSpec> FindExtensionMethods (TypeContainer invocationType, TypeSpec extensionType, string name, int arity)
+ public List<MethodSpec> FindExtensionMethods (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity)
{
IList<MemberSpec> entries;
if (!member_hash.TryGetValue (name, out entries))
if (!ms.IsExtensionMethod)
continue;
- if (!ms.IsAccessible (invocationType))
+ if (!ms.IsAccessible (invocationContext))
continue;
- if ((ms.DeclaringType.Modifiers & Modifiers.INTERNAL) != 0 && !ms.DeclaringType.MemberDefinition.IsInternalAsPublic (invocationType.DeclaringAssembly))
+ //
+ // Extension methods cannot be nested hence checking parent is enough
+ //
+ if ((ms.DeclaringType.Modifiers & Modifiers.INTERNAL) != 0 && !ms.DeclaringType.MemberDefinition.IsInternalAsPublic (invocationContext.Module.DeclaringAssembly))
continue;
if (candidates == null)
// Returns base members of @member member if no exact match is found @bestCandidate returns
// the best match
//
- public static MemberSpec FindBaseMember (MemberCore member, out MemberSpec bestCandidate)
+ public static MemberSpec FindBaseMember (MemberCore member, out MemberSpec bestCandidate, ref bool overrides)
{
bestCandidate = null;
var container = member.Parent.PartialContainer.Definition;
}
string name = GetLookupName (member);
- IList<MemberSpec> applicable;
var member_param = member is IParametersMember ? ((IParametersMember) member).Parameters : null;
var mkind = GetMemberCoreKind (member);
bool member_with_accessors = mkind == MemberKind.Indexer || mkind == MemberKind.Property;
+ IList<MemberSpec> applicable;
+ MemberSpec ambig_candidate = null;
+
do {
if (container.MemberCache.member_hash.TryGetValue (name, out applicable)) {
for (int i = 0; i < applicable.Count; ++i) {
}
//
- // Skip override members with accessors they may not fully implement the base member
+ // Skip override for member with accessors. It may not fully implement the base member
+ // but keep flag we found an implementation in case the base member is abstract
//
- if (member_with_accessors) {
- if ((entry.Modifiers & (Modifiers.OVERRIDE | Modifiers.SEALED)) == Modifiers.OVERRIDE) {
- //
- // Set candidate to member override to flag we found an implementation
- //
- bestCandidate = entry;
- continue;
- }
- } else {
+ if (member_with_accessors && ((entry.Modifiers & (Modifiers.OVERRIDE | Modifiers.SEALED)) == Modifiers.OVERRIDE)) {
+ //
+ // Set candidate to override implementation to flag we found an implementation
+ //
+ overrides = true;
+ continue;
+ }
+
+ //
+ // For members with parameters we can encounter an ambiguous candidates (they match exactly)
+ // because generic type parameters could be inflated into same types
+ //
+ if (ambig_candidate == null && (entry.Kind & mkind & (MemberKind.Method | MemberKind.Indexer)) != 0) {
bestCandidate = null;
+ ambig_candidate = entry;
+ continue;
}
+ bestCandidate = ambig_candidate;
return entry;
}
}
- if (container.IsInterface)
+ if (container.IsInterface || ambig_candidate != null)
break;
container = container.BaseType;
} while (container != null);
- return null;
+ return ambig_candidate;
}
//
//
// Returns members of @iface only, base members are ignored
//
- public static IList<MethodSpec> GetInterfaceMethods (TypeSpec iface)
+ public static List<MethodSpec> GetInterfaceMethods (TypeSpec iface)
{
//
// MemberCache flatten interfaces, therefore in cases like this one