fcl-passrc, pastojs: fixed crash on evaluating ord(int), #39260

This commit is contained in:
mattias 2023-07-12 10:22:02 +02:00 committed by Pierre Muller
parent 29adfc18ff
commit 7ec6d9e3c1
5 changed files with 13 additions and 11 deletions

View File

@ -19450,7 +19450,8 @@ begin
try
Evaluated:=fExprEvaluator.OrdValue(Value,Params);
finally
ReleaseEvalValue(Value);
if Evaluated<>Value then
ReleaseEvalValue(Value);
end;
if Proc=nil then ;
end;

View File

@ -198,6 +198,7 @@ begin
Inc(FErrorCount);
if aContext.Error is EParserError then
FLastErrorNumber:=EParserError(aContext.Error).ErrNo;
if Allow then ;
end;
procedure TTestParser.SetupParser;

View File

@ -637,8 +637,6 @@ begin
end;
procedure TTestConstParser.TestConstErrorRecovery;
Var
D : String;
begin
Add('Const');
Add(' A : 1;');

View File

@ -13640,16 +13640,16 @@ function TPasToJSConverter.ConvertBuiltIn_Ord(El: TParamsExpr;
Result:=nil;
OrdValue:=nil;
ParamValue:=aResolver.Eval(Param,[]);
if ParamValue=nil then exit;
try
if ParamValue<>nil then
OrdValue:=aResolver.ExprEvaluator.OrdValue(ParamValue,El);
if OrdValue=ParamValue then
ParamValue:=nil;
if OrdValue<>nil then
begin
OrdValue:=aResolver.ExprEvaluator.OrdValue(ParamValue,El);
if OrdValue<>nil then
begin
// ord(constant) -> constant
Result:=ConvertConstValue(OrdValue,AContext,El);
exit;
end;
// ord(constant) -> constant
Result:=ConvertConstValue(OrdValue,AContext,El);
exit;
end;
finally
ReleaseEvalValue(ParamValue);

View File

@ -7191,6 +7191,7 @@ begin
' Enum: byte;',
' Enums: tenums;',
'begin',
' Enum:=ord(1);',
' Enums:=[];',
' Enums:=[0];',
' Enums:=[1..2];',
@ -7206,6 +7207,7 @@ begin
'this.Enums = {};',
'']),
LinesToStr([
'$mod.Enum = 1;',
'$mod.Enums = {};',
'$mod.Enums = rtl.createSet(0);',
'$mod.Enums = rtl.createSet(null, 1, 2);',