From 7d9786564dc4da6d6d0e668130d4a9213d6b97ce Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Fri, 24 Dec 2021 15:57:47 +0100 Subject: [PATCH] #2561 --- NETGenerator/NETGenerator.cs | 10 ++++++---- TestSuite/nullable12.pas | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 TestSuite/nullable12.pas diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 3b92f9ffa..a463c887c 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -8976,11 +8976,12 @@ namespace PascalABCCompiler.NETGenerator } else { - is_dot_expr = true; TypeInfo ti = helper.GetTypeReference(real_parameters[0].type); real_parameters[0].visit(this); - is_dot_expr = tmp; + LocalBuilder tmp_lb = il.DeclareLocal(ti.tp); + il.Emit(OpCodes.Stloc, tmp_lb); + il.Emit(OpCodes.Ldloca, tmp_lb); MethodInfo mi = null; if (real_parameters[0].type is IGenericTypeInstance) @@ -9007,10 +9008,11 @@ namespace PascalABCCompiler.NETGenerator } else { - is_dot_expr = true; TypeInfo ti = helper.GetTypeReference(real_parameters[1].type); real_parameters[1].visit(this); - is_dot_expr = tmp; + LocalBuilder tmp_lb = il.DeclareLocal(ti.tp); + il.Emit(OpCodes.Stloc, tmp_lb); + il.Emit(OpCodes.Ldloca, tmp_lb); MethodInfo mi = null; if (real_parameters[1].type is IGenericTypeInstance) mi = TypeBuilder.GetMethod(ti.tp, typeof(Nullable<>).GetMethod("get_HasValue")); diff --git a/TestSuite/nullable12.pas b/TestSuite/nullable12.pas new file mode 100644 index 000000000..f03401da6 --- /dev/null +++ b/TestSuite/nullable12.pas @@ -0,0 +1,17 @@ +begin + var o := new class(field := default(byte?)); + o := nil; + var a := o?.field = nil; + assert(a); + a := nil = o?.field; + assert(a); + a := o?.field <> nil; + assert(not a); + a := nil <> o?.field; + assert(not a); + var b: byte?; + a := o?.field = b; + assert(a); + a := o?.field <> b; + assert(not a); +end. \ No newline at end of file