Skip to content
4 changes: 3 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ private ImmutableArray<Symbol> ProcessParameterlessCrefMemberLookupResults(
{
CrefSyntax crefSyntax = GetRootCrefSyntax(memberSyntax);
int otherIndex = symbolIndex == 0 ? 1 : 0;
diagnostics.Add(ErrorCode.WRN_AmbiguousXMLReference, crefSyntax.Location, crefSyntax.ToString(), symbol, symbols[otherIndex]);
diagnostics.Add(ErrorCode.WRN_AmbiguousXMLReference, crefSyntax.Location, crefSyntax.ToString(),
new FormattedSymbol(symbol, SymbolDisplayFormat.CSharpErrorMessageFormat),
new FormattedSymbol(symbols[otherIndex], SymbolDisplayFormat.CSharpErrorMessageFormat));

ambiguityWinner = ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, symbol);
return symbols.SelectAsArray(sym => ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, sym));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7029,5 +7029,78 @@ record CacheContext(string String)" + terminator;
var symbol = model.GetSymbolInfo(crefSyntaxes.Single()).Symbol;
Assert.Equal(SymbolKind.Property, symbol.Kind);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4031")]
public void AmbiguousReferenceInDifferentNamespaces()
{
var source = """
namespace System
{
class TypeA
{
}
}

namespace System.Goo
{
class TypeA
{
}
}

namespace A
{
using System;
using System.Goo;

/// <summary>
/// <see cref="TypeA"/>
/// </summary>
class Bar
{
}
}
""";
CreateCompilationWithMscorlib40AndDocumentationComments(source).VerifyDiagnostics(
// (21,24): warning CS0419: Ambiguous reference in cref attribute: 'TypeA'. Assuming 'System.Goo.TypeA', but could have also matched other overloads including 'System.TypeA'.
// <see cref="TypeA"/>
Diagnostic(ErrorCode.WRN_AmbiguousXMLReference, "TypeA").WithArguments("TypeA", "System.Goo.TypeA", "System.TypeA").WithLocation(21, 24));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/4031")]
public void AmbiguousReferenceInDifferentNamespaces_WithParameters()
{
var source = """
namespace System
{
class TypeA
{
}
}

namespace System.Goo
{
class TypeA
{
}
}

namespace A
{
/// <summary>
/// <see cref="M{T}"/>
/// </summary>
class Bar
{
void M<T>(System.TypeA a) { }
void M<T>(System.Goo.TypeA a) { }
}
}
""";
CreateCompilationWithMscorlib40AndDocumentationComments(source).VerifyDiagnostics(
// (18,24): warning CS0419: Ambiguous reference in cref attribute: 'M{T}'. Assuming 'A.Bar.M<T>(System.TypeA)', but could have also matched other overloads including 'A.Bar.M<T>(System.Goo.TypeA)'.
// /// <see cref="M{T}"/>
Diagnostic(ErrorCode.WRN_AmbiguousXMLReference, "M{T}").WithArguments("M{T}", "A.Bar.M<T>(System.TypeA)", "A.Bar.M<T>(System.Goo.TypeA)").WithLocation(18, 24));
}
}
}