提交 55a2caad 编写于 作者: T Ty Overby

add csharp test. refactor vb emit

上级 03703689
......@@ -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:=True)
If used Then
EmitBox(typeFrom, conversion.Operand.Syntax)
End If
EmitBox(typeFrom, conversion.Operand.Syntax)
End If
ElseIf typeTo.IsNullableType Then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册