未验证 提交 932e0f15 编写于 作者: J Julien Couvreur 提交者: GitHub

Avoid AmbigMember in lookup of interfaces with nullability differences only (#49338)

上级 9c1151af
......@@ -1058,11 +1058,20 @@ static void addAllInterfaces(NamedTypeSymbol @interface, HashSet<NamedTypeSymbol
if (interfaces.Length > 0)
{
var tmp = LookupResult.GetInstance();
foreach (TypeSymbol baseInterface in interfaces)
HashSet<NamedTypeSymbol> seenInterfaces = null;
if (interfaces.Length > 1)
{
LookupMembersWithoutInheritance(tmp, baseInterface, name, arity, options, originalBinder, accessThroughType, diagnose, ref useSiteDiagnostics, basesBeingResolved);
MergeHidingLookupResults(current, tmp, basesBeingResolved, ref useSiteDiagnostics);
tmp.Clear();
seenInterfaces = new HashSet<NamedTypeSymbol>(Symbols.SymbolEqualityComparer.IgnoringNullable);
}
foreach (NamedTypeSymbol baseInterface in interfaces)
{
if (seenInterfaces is null || seenInterfaces.Add(baseInterface))
{
LookupMembersWithoutInheritance(tmp, baseInterface, name, arity, options, originalBinder, accessThroughType, diagnose, ref useSiteDiagnostics, basesBeingResolved);
MergeHidingLookupResults(current, tmp, basesBeingResolved, ref useSiteDiagnostics);
tmp.Clear();
}
}
tmp.Free();
}
......
......@@ -57708,13 +57708,7 @@ interface D : A.E
compilation1.VerifyDiagnostics(
// (4,11): warning CS8645: 'C<object>' is already listed in the interface list on type 'A' with different nullability of reference types.
// interface A : B, C<object>
Diagnostic(ErrorCode.WRN_DuplicateInterfaceWithNullabilityMismatchInBaseList, "A").WithArguments("C<object>", "A").WithLocation(4, 11),
// (18,17): error CS0104: 'E' is an ambiguous reference between 'C<object?>.E' and 'C<object>.E'
// interface D : A.E
Diagnostic(ErrorCode.ERR_AmbigContext, "E").WithArguments("E", "C<object?>.E", "C<object>.E").WithLocation(18, 17),
// (20,7): error CS0104: 'E' is an ambiguous reference between 'C<object?>.E' and 'C<object>.E'
// A.E Test();
Diagnostic(ErrorCode.ERR_AmbigContext, "E").WithArguments("E", "C<object?>.E", "C<object>.E").WithLocation(20, 7)
Diagnostic(ErrorCode.WRN_DuplicateInterfaceWithNullabilityMismatchInBaseList, "A").WithArguments("C<object>", "A").WithLocation(4, 11)
);
}
......@@ -118,9 +118,10 @@ public static string[] ToTestDisplayStrings(this IEnumerable<ISymbol> symbols)
return symbols.Select(s => s.ToTestDisplayString()).ToArray();
}
public static string[] ToTestDisplayStrings(this IEnumerable<Symbol> symbols)
public static string[] ToTestDisplayStrings(this IEnumerable<Symbol> symbols, SymbolDisplayFormat format = null)
{
return symbols.Select(s => s.ToTestDisplayString()).ToArray();
format ??= SymbolDisplayFormat.TestFormat;
return symbols.Select(s => s.ToDisplayString(format)).ToArray();
}
public static string ToTestDisplayString(this ISymbol symbol, bool includeNonNullable)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册