This commit is contained in:
Ivan Bondarev 2023-08-01 20:49:36 +02:00
parent 4e208d36a7
commit 148dac36c4
2 changed files with 17 additions and 1 deletions

View file

@ -11046,7 +11046,10 @@ namespace PascalABCCompiler.NETGenerator
is_dot_expr = tmp_is_dot_expr;
is_addr = tmp_is_addr;
il.Emit(OpCodes.Brtrue, NullLabel);
il.Emit(OpCodes.Ldloc, tmp_lb);
if (value.condition.type.is_nullable_type)
il.Emit(OpCodes.Ldloca, tmp_lb);
else
il.Emit(OpCodes.Ldloc, tmp_lb);
TypeInfo ti = helper.GetTypeReference(value.condition.type);
if (ti != null)
EmitBox(value.condition, ti.tp);

13
TestSuite/nullable14.pas Normal file
View file

@ -0,0 +1,13 @@
function f1 := 1;
function p1(n: integer?): integer;
begin
Result := (n??f1).Value;
end;
begin
// OK
assert(p1(nil) = 1);
// AccessViolationException
assert(p1(5) = 5);
end.