Skip to content

Commit

Permalink
Fix Tuple Crefs causing null exception (dotnet#29513)
Browse files Browse the repository at this point in the history
Fix Tuple Crefs causing null exception:
  - fix the Cref binder so that we un-wrap any TupleTypeSymbols that get wrapped inside BindNamespaceOrTypeSymbol as crefs don't consider the higher order form tuples at all.
- Add tests
  • Loading branch information
chsienki authored Sep 11, 2018
1 parent 8474ba4 commit e82d1ad
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ private NamespaceOrTypeSymbol BindNamespaceOrTypeSymbolInCref(TypeSyntax syntax)
NamespaceOrTypeSymbol namespaceOrTypeSymbol = BindNamespaceOrTypeSymbol(syntax, unusedDiagnostics);
unusedDiagnostics.Free();

// BindNamespaceOrTypeSymbol will wrap any tuple types in a TupleTypeSymbol. We unwrap it here, as doc comments don't consider the (T,T) form of tuples
if(namespaceOrTypeSymbol is TupleTypeSymbol t)
{
namespaceOrTypeSymbol = t.UnderlyingNamedType;
}

Debug.Assert((object)namespaceOrTypeSymbol != null);
return namespaceOrTypeSymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6660,5 +6660,53 @@ void S()
var parameterSymbol = ((MethodSymbol)model.GetSymbolInfo(cref).Symbol).Parameters.Single();
Assert.Equal(RefKind.In, parameterSymbol.RefKind);
}

[Fact]
public void Cref_TupleType()
{
var source = @"
using System;
/// <summary>
/// See <see cref=""ValueTuple{T,T}""/>.
/// </summary>
class C
{
}
";
var parseOptions = TestOptions.RegularWithDocumentationComments;
var options = TestOptions.ReleaseDll.WithXmlReferenceResolver(XmlFileResolver.Default);
var compilation = CreateCompilation(source, parseOptions: parseOptions, options: options, targetFramework: TargetFramework.StandardAndCSharp);
var cMember = compilation.GetMember<NamedTypeSymbol>("C");
var xmlDocumentationString = cMember.GetDocumentationCommentXml();

var xml = System.Xml.Linq.XDocument.Parse(xmlDocumentationString);
var cref = xml.Descendants("see").Single().Attribute("cref").Value;

Assert.Equal("T:System.ValueTuple`2", cref);
}

[Fact]
public void Cref_TupleTypeField()
{
var source = @"
using System;
/// <summary>
/// See <see cref=""ValueTuple{Int32,Int32}.Item1""/>.
/// </summary>
class C
{
}
";
var parseOptions = TestOptions.RegularWithDocumentationComments;
var options = TestOptions.ReleaseDll.WithXmlReferenceResolver(XmlFileResolver.Default);
var compilation = CreateCompilation(source, parseOptions: parseOptions, options: options, targetFramework: TargetFramework.StandardAndCSharp);
var cMember = compilation.GetMember<NamedTypeSymbol>("C");
var xmlDocumentationString = cMember.GetDocumentationCommentXml();

var xml = System.Xml.Linq.XDocument.Parse(xmlDocumentationString);
var cref = xml.Descendants("see").Single().Attribute("cref").Value;

Assert.Equal("F:System.ValueTuple`2.Item1", cref);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12447,5 +12447,65 @@ End Class
Assert.Empty(model.LookupSymbols(name.SpanStart, typeParameter, "GetAwaiter"))
End Sub

<Fact>
Public Sub LookupOnCrefOfTupleType()

Dim sources =
<compilation>
<file name="a.vb">
<![CDATA[
Imports System
''' <summary>
''' <see cref="ValueTuple(Of U,U)"/>
''' </summary>
Public Class Test
End Class
]]>
</file>
</compilation>

Dim references = TargetFrameworkUtil.GetReferences(TargetFramework.StandardAndVBRuntime)
Dim compilation = CreateEmptyCompilationWithReferences(
sources,
references)

Dim cMember = compilation.GetMember(Of NamedTypeSymbol)("Test")
Dim xmlDocumentationString = cMember.GetDocumentationCommentXml()
Dim xml = System.Xml.Linq.XDocument.Parse(xmlDocumentationString)
Dim cref = xml.Descendants("see").Single().Attribute("cref").Value

Assert.Equal("T:System.ValueTuple`2", cref)
End Sub

<Fact>
Public Sub LookupOnCrefOfTupleTypeField()

Dim sources =
<compilation>
<file name="a.vb">
<![CDATA[
Imports System
''' <summary>
''' <see cref="ValueTuple(Of U,U).Item1"/>
''' </summary>
Public Class Test
End Class
]]>
</file>
</compilation>

Dim references = TargetFrameworkUtil.GetReferences(TargetFramework.StandardAndVBRuntime)
Dim compilation = CreateEmptyCompilationWithReferences(
sources,
references)

Dim cMember = compilation.GetMember(Of NamedTypeSymbol)("Test")
Dim xmlDocumentationString = cMember.GetDocumentationCommentXml()
Dim xml = System.Xml.Linq.XDocument.Parse(xmlDocumentationString)
Dim cref = xml.Descendants("see").Single().Attribute("cref").Value

Assert.Equal("F:System.ValueTuple`2.Item1", cref)
End Sub

End Class
End Namespace

0 comments on commit e82d1ad

Please sign in to comment.