diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 239342655..eca15665a 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -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; diff --git a/TestSuite/question7.pas b/TestSuite/question7.pas new file mode 100644 index 000000000..1b88b713d --- /dev/null +++ b/TestSuite/question7.pas @@ -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. \ No newline at end of file diff --git a/TestSuite/question8.pas b/TestSuite/question8.pas new file mode 100644 index 000000000..da7db4ca3 --- /dev/null +++ b/TestSuite/question8.pas @@ -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. \ No newline at end of file