Skip to content
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

Specially handle tuple methods in CodeGenerator.EmitMethodInfoExpression for VB. #43553

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Compilers/VisualBasic/Portable/CodeGen/EmitExpression.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2178,15 +2178,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGen
End Sub

Private Sub EmitMethodInfoExpression(node As BoundMethodInfo, used As Boolean)
Dim method As MethodSymbol = node.Method

If method.IsTupleMethod Then
method = method.TupleUnderlyingMethod
End If

_builder.EmitOpCode(ILOpCode.Ldtoken)
EmitSymbolToken(node.Method, node.Syntax)
EmitSymbolToken(method, node.Syntax)
Dim getMethod As MethodSymbol
If Not node.Method.ContainingType.IsGenericType AndAlso Not node.Method.ContainingType.IsAnonymousType Then ' anonymous types are generic under the hood.
If Not method.ContainingType.IsGenericType AndAlso Not method.ContainingType.IsAnonymousType Then ' anonymous types are generic under the hood.
_builder.EmitOpCode(ILOpCode.Call, stackAdjustment:=0) ' argument off, return value on
getMethod = DirectCast(Me._module.Compilation.GetWellKnownTypeMember(WellKnownMember.System_Reflection_MethodBase__GetMethodFromHandle), MethodSymbol)
Else
_builder.EmitOpCode(ILOpCode.Ldtoken)
EmitSymbolToken(node.Method.ContainingType, node.Syntax)
EmitSymbolToken(method.ContainingType, node.Syntax)
_builder.EmitOpCode(ILOpCode.Call, stackAdjustment:=-1) ' 2 arguments off, return value on
getMethod = DirectCast(Me._module.Compilation.GetWellKnownTypeMember(WellKnownMember.System_Reflection_MethodBase__GetMethodFromHandle2), MethodSymbol)
End If
Expand Down
40 changes: 40 additions & 0 deletions src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
Original file line number Diff line number Diff line change
Expand Up @@ -23050,6 +23050,46 @@ End Class"
End Select
End Sub

<Fact>
<WorkItem(27322, "https://github.com/dotnet/roslyn/issues/27322")>
Public Sub Issue27322()
Dim source0 = "
Imports System
Imports System.Collections.Generic
Imports System.Linq.Expressions

Module Module1

Sub Main()
Dim tupleA = (1, 3)
Dim tupleB = (1, ""123"".Length)

Dim ok1 As Expression(Of Func(Of Integer)) = Function() tupleA.Item1
Dim ok2 As Expression(Of Func(Of Integer)) = Function() tupleA.GetHashCode()
Dim ok3 As Expression(Of Func(Of Tuple(Of Integer, Integer))) = Function() tupleA.ToTuple()
Dim ok4 As Expression(Of Func(Of Boolean)) = Function() Equals(tupleA, tupleB)
Dim ok5 As Expression(Of Func(Of Integer)) = Function() Comparer(Of (Integer, Integer)).Default.Compare(tupleA, tupleB)
ok1.Compile()()
ok2.Compile()()
ok3.Compile()()
ok4.Compile()()
ok5.Compile()()

Dim err1 As Expression(Of Func(Of Boolean)) = Function() tupleA.Equals(tupleB)
Dim err2 As Expression(Of Func(Of Integer)) = Function() tupleA.CompareTo(tupleB)

err1.Compile()()
err2.Compile()()

System.Console.WriteLine(""Done"")
End Sub

End Module
"

Dim comp1 = CreateCompilation(source0, options:=TestOptions.DebugExe)
CompileAndVerify(comp1, expectedOutput:="Done")
End Sub
End Class

End Namespace
Expand Down