提交 7280be7f 编写于 作者: T Ty Overby 提交者: GitHub

Merge pull request #15466 from TyOverby/9703-vb-bad-emit

avoid double-pop in an ignored conversion expression
......@@ -15488,5 +15488,36 @@ public static void Main(string[] args)
expectedOutput: "0");
}
[Fact, WorkItem(9703, "https://github.com/dotnet/roslyn/issues/9703")]
public void IgnoredConversion()
{
string source = @"
using System;
public class Form1 {
public class BadCompiler {
public DateTime? Value {get; set;}
}
private BadCompiler TestObj = new BadCompiler();
public void IPE() {
object o;
o = TestObj.Value;
}
}";
var compilation = CompileAndVerify(source);
compilation.VerifyIL("Form1.IPE", @"
{
// Code size 13 (0xd)
.maxstack 1
IL_0000: ldarg.0
IL_0001: ldfld ""Form1.BadCompiler Form1.TestObj""
IL_0006: callvirt ""System.DateTime? Form1.BadCompiler.Value.get""
IL_000b: pop
IL_000c: ret
}");
}
}
}
......@@ -160,19 +160,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGen
ElseIf typeFrom.IsNullableType Then
Debug.Assert(typeTo.IsReferenceType)
EmitExpression(conversion.Operand, used:=True)
If (conversion.ConversionKind And ConversionKind.Narrowing) <> 0 Then
EmitExpression(conversion.Operand, True)
EmitBox(typeFrom, conversion.Operand.Syntax)
_builder.EmitOpCode(ILOpCode.Castclass)
EmitSymbolToken(typeTo, conversion.Syntax)
Else
ElseIf used Then
' boxing itself is CLR-widening, so no need to emit unused boxing
EmitExpression(conversion.Operand, used)
If used Then
EmitBox(typeFrom, conversion.Operand.Syntax)
End If
EmitBox(typeFrom, conversion.Operand.Syntax)
End If
ElseIf typeTo.IsNullableType Then
......
......@@ -13580,5 +13580,45 @@ End Class
]]>)
End Sub
<Fact, WorkItem(9703, "https://github.com/dotnet/roslyn/issues/9703")>
Public Sub IgnoredConversion()
CompileAndVerify(
<compilation>
<file name="ignoreNullableValue.vb">
Module MainModule
Public Class Form1
Public Class BadCompiler
Public Property Value As Date?
End Class
Private TestObj As BadCompiler = New BadCompiler()
Public Sub IPE()
Dim o as Object
o = TestObj.Value
End Sub
End Class
Public Sub Main()
Dim f = new Form1
f.IPE()
End Sub
End Module
</file>
</compilation>).
VerifyIL("MainModule.Form1.IPE",
<![CDATA[
{
// Code size 13 (0xd)
.maxstack 1
IL_0000: ldarg.0
IL_0001: ldfld "MainModule.Form1.TestObj As MainModule.Form1.BadCompiler"
IL_0006: callvirt "Function MainModule.Form1.BadCompiler.get_Value() As Date?"
IL_000b: pop
IL_000c: ret
}
]]>)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册