-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract method refactoring should handle tuples in VB #13278
Changes from 5 commits
9e1fd73
502c896
405ab33
276c93f
2164545
69d24f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5146,6 +5146,17 @@ public void CreateTupleTypeSymbol_ElementTypeIsError() | |
Assert.Equal(SymbolKind.ErrorType, types[1].Kind); | ||
} | ||
|
||
[Fact, WorkItem(13277, "https://github.com/dotnet/roslyn/issues/13277")] | ||
public void CreateTupleTypeSymbol_UnderlyingTypeIsError() | ||
{ | ||
var comp = CSharpCompilation.Create("test", references: new[] { MscorlibRef }); | ||
|
||
TypeSymbol intType = comp.GetSpecialType(SpecialType.System_Int32); | ||
var vt2 = comp.CreateErrorTypeSymbol(null, "ValueTuple", 2).Construct(intType, intType); | ||
|
||
Assert.Throws<ArgumentException>(() => comp.CreateTupleTypeSymbol(vt2, default(ImmutableArray<string>))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor point: Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
} | ||
|
||
[Fact] | ||
public void CreateTupleTypeSymbol_BadNames() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5896,6 +5896,47 @@ fourth]]>) | |
|
||
End Sub | ||
|
||
<Fact(Skip:="https://github.com/dotnet/roslyn/issues/13277")> | ||
<WorkItem(13277, "https://github.com/dotnet/roslyn/issues/13277")> | ||
Public Sub CreateTupleTypeSymbol_UnderlyingTypeIsError() | ||
|
||
Dim comp = VisualBasicCompilation.Create("test", references:={MscorlibRef}) | ||
|
||
Dim intType As TypeSymbol = comp.GetSpecialType(SpecialType.System_Int32) | ||
Dim vt2 = comp.CreateErrorTypeSymbol(Nothing, "ValueTuple", 2).Construct(intType, intType) | ||
|
||
Dim tuple = comp.CreateTupleTypeSymbol(vt2, Nothing) | ||
' Crashes in IsTupleCompatible | ||
|
||
End Sub | ||
|
||
<Fact> | ||
<WorkItem(13042, "https://github.com/dotnet/roslyn/issues/13042")> | ||
Public Sub GetSymbolInfoOnTupleType() | ||
Dim verifier = CompileAndVerify( | ||
<compilation> | ||
<file name="a.vb"> | ||
Module C | ||
Function M() As (System.Int32, String) | ||
throw new System.Exception() | ||
End Function | ||
End Module | ||
|
||
</file> | ||
</compilation>, additionalRefs:={ValueTupleRef, SystemRuntimeFacadeRef}) | ||
|
||
Dim comp = verifier.Compilation | ||
Dim tree = comp.SyntaxTrees(0) | ||
Dim model = comp.GetSemanticModel(tree, ignoreAccessibility:=False) | ||
Dim nodes = tree.GetCompilationUnitRoot().DescendantNodes() | ||
|
||
Dim type = nodes.OfType(Of QualifiedNameSyntax)().First() | ||
Assert.Equal("System.Int32", type.ToString()) | ||
Assert.NotNull(model.GetSymbolInfo(type)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently not ;-) Removed |
||
Assert.NotNull(model.GetSymbolInfo(type).Symbol) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
|
||
End Sub | ||
|
||
End Class | ||
|
||
End Namespace | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions | |
Return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("DateTime")) | ||
End Select | ||
|
||
If symbol.IsTupleType Then | ||
Return CreateTupleTypeSyntax(symbol) | ||
End If | ||
|
||
If symbol.Name = String.Empty OrElse symbol.IsAnonymousType Then | ||
Return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Object")) | ||
End If | ||
|
@@ -119,6 +123,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions | |
SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList(symbol.TypeArguments.[Select](Function(t) t.Accept(Me))))) | ||
End Function | ||
|
||
Private Function CreateTupleTypeSyntax(symbol As INamedTypeSymbol) As TypeSyntax | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
Dim list = New SeparatedSyntaxList(Of TupleElementSyntax)() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about that. Removed |
||
Dim types = symbol.TupleElementTypes | ||
Dim names = symbol.TupleElementNames | ||
Dim hasNames = Not names.IsDefault | ||
|
||
Return SyntaxFactory.TupleType(SyntaxFactory.SeparatedList( | ||
types.Select(Function(t, i) SyntaxFactory.TupleElement( | ||
If(hasNames, SyntaxFactory.IdentifierName(names(i)), Nothing), GenerateTypeSyntax(t))))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor point: Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
End Function | ||
|
||
Public Overrides Function VisitNamedType(symbol As INamedTypeSymbol) As TypeSyntax | ||
Dim typeSyntax = CreateSimpleTypeSyntax(symbol) | ||
If Not (TypeOf typeSyntax Is SimpleNameSyntax) Then | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass
intType.ContainingNamespace
forcontainer
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is on purpose. I'm trying to do the equivalent of code that crashes the compiler in VB. See the VB test of the same name.