This commit is contained in:
Ivan Bondarev 2022-09-04 12:40:00 +02:00
parent af7c8625ac
commit 749487e7a4
3 changed files with 26 additions and 1 deletions

View file

@ -7454,6 +7454,7 @@ namespace PascalABCCompiler.NETGenerator
&& !(value.obj is ICommonMethodCallNode) && !(value.obj is ICommonStaticMethodCallNode)
&& !(value.obj is ICommonConstructorCall) && !(value.obj is ICommonNamespaceFunctionCallNode)
&& !(value.obj is ICommonNestedInFunctionFunctionCallNode)
&& !(value.obj is IQuestionColonExpressionNode)
&& !(value.obj.conversion_type != null && !value.obj.conversion_type.is_value_type))
{
LocalBuilder lb = il.DeclareLocal(helper.GetTypeReference(value.obj.type).tp);
@ -10792,7 +10793,7 @@ namespace PascalABCCompiler.NETGenerator
}
else
value.condition.visit(this);
is_dot_expr = tmp_is_dot_expr;
is_addr = tmp_is_addr;
il.Emit(OpCodes.Brfalse, FalseLabel);
@ -10811,6 +10812,8 @@ namespace PascalABCCompiler.NETGenerator
EmitBox(value.ret_if_true, ti.tp);
il.Emit(OpCodes.Br, EndLabel);
il.MarkLabel(FalseLabel);
is_dot_expr = tmp_is_dot_expr;
is_addr = tmp_is_addr;
if (value.ret_if_false is INullConstantNode && value.ret_if_false.type.is_nullable_type)
{
Type tp = helper.GetTypeReference(value.ret_if_false.type).tp;

14
TestSuite/question7.pas Normal file
View file

@ -0,0 +1,14 @@
type
r1 = record
x := 5;
function ToString: string; override := x.ToString;
end;
begin
var a := new r1;
var s := (if true then a else new r1).ToString;
assert(s = '5');
s := '';
s := (if false then a else new r1).ToString;
assert(s = '5');
end.

8
TestSuite/question8.pas Normal file
View file

@ -0,0 +1,8 @@

begin
var i := new BigInteger(1);
var s := (if false then i else new BigInteger(2)).ToString;
assert(s = '2');
s := (if true then i else new BigInteger(2)).ToString;
assert(s = '1');
end.