Explorar o código

pastojs: ord(integer)

mattias %!s(int64=4) %!d(string=hai) anos
pai
achega
e1d0d3b185

+ 3 - 3
compiler/packages/fcl-passrc/src/pasresolver.pp

@@ -19050,19 +19050,19 @@ begin
     exit(cIncompatible);
   Params:=TParamsExpr(Expr);
 
-  // first param: bool, enum or char
+  // first param: bool, integer, enum or char
   Param:=Params.Params[0];
   ComputeElement(Param,ParamResolved,[]);
   Result:=cIncompatible;
   if rrfReadable in ParamResolved.Flags then
     begin
-    if ParamResolved.BaseType in (btAllBooleans+btAllChars) then
+    if ParamResolved.BaseType in btArrayRangeTypes then
       Result:=cExact
     else if (ParamResolved.BaseType=btContext) and (ParamResolved.LoTypeEl is TPasEnumType) then
       Result:=cExact
     else if ParamResolved.BaseType=btRange then
       begin
-      if ParamResolved.SubType in btAllBooleans+btAllChars then
+      if ParamResolved.SubType in btArrayRangeTypes then
         Result:=cExact
       else if ParamResolved.SubType=btContext then
         begin

+ 3 - 1
compiler/packages/fcl-passrc/tests/tcresolver.pas

@@ -3350,8 +3350,10 @@ begin
   '  i2: TInt2;',
   'begin',
   '  i:=i2;',
-  '  if i=i2 then ;']);
+  '  if i=i2 then ;',
+  '  i:=ord(i);']);
   ParseProgram;
+  CheckResolverUnexpectedHints;
 end;
 
 procedure TTestResolver.TestIntegerRangeHighLowerLowFail;

+ 9 - 0
compiler/packages/pastojs/src/fppas2js.pp

@@ -13348,6 +13348,15 @@ begin
     Result:=Add;
     exit;
     end
+  else if bt in btAllJSInteger then
+    begin
+    // ord(integer)
+    Result:=CheckOrdConstant(aResolver,Param);
+    if Result<>nil then exit;
+    // ord(integer) ->  integer
+    Result:=ConvertExpression(Param,AContext);
+    exit;
+    end
   else if bt=btContext then
     begin
     C:=ParamResolved.LoTypeEl.ClassType;

+ 6 - 1
compiler/packages/pastojs/tests/tcmodules.pas

@@ -7135,7 +7135,9 @@ begin
   'begin',
   '  i:=i2;',
   '  i:=default(TMyInt);',
-  '  if i=i2 then ;']);
+  '  if i=i2 then ;',
+  '  i:=ord(i2);',
+  '']);
   ConvertProgram;
   CheckSource('TestIntegerRange',
     LinesToStr([
@@ -7156,6 +7158,7 @@ begin
     '$mod.i = $mod.i2;',
     '$mod.i = -1;',
     'if ($mod.i === $mod.i2) ;',
+    '$mod.i = $mod.i2;',
     '']));
 end;
 
@@ -7270,6 +7273,7 @@ begin
   '  i:=system.high(i);',
   '  i:=system.pred(i);',
   '  i:=system.succ(i);',
+  '  i:=system.ord(i);',
   '']);
   ConvertProgram;
   CheckResolverUnexpectedHints;
@@ -7286,6 +7290,7 @@ begin
     '$mod.i = 255;',
     '$mod.i = $mod.i - 1;',
     '$mod.i = $mod.i + 1;',
+    '$mod.i = $mod.i;',
     '']));
 end;