Browse Source

pastojs: local var modifier absolute in method

git-svn-id: trunk@39977 -
Mattias Gaertner 6 years ago
parent
commit
b019d40c64
2 changed files with 20 additions and 8 deletions
  1. 3 4
      packages/pastojs/src/fppas2js.pp
  2. 17 4
      packages/pastojs/tests/tcmodules.pas

+ 3 - 4
packages/pastojs/src/fppas2js.pp

@@ -2850,14 +2850,13 @@ begin
     if ParentC=TProcedureBody then
     if ParentC=TProcedureBody then
       begin
       begin
       // local var
       // local var
-      if (AbsIdent.Parent=El.Parent)
-          or ((AbsIdent is TPasArgument)
-            and (AbsIdent.Parent.Parent=El.Parent.Parent)) then
+      if (AbsIdent.Parent is TProcedureBody)
+          or (AbsIdent is TPasArgument) then
         // ok
         // ok
       else
       else
         begin
         begin
         {$IFDEF VerbosePas2JS}
         {$IFDEF VerbosePas2JS}
-        writeln('TPas2JSResolver.FinishVariable absolute: Parent=',GetObjName(El.Parent),' AbsParent=',GetObjName(AbsIdent.Parent));
+        writeln('TPas2JSResolver.FinishVariable absolute: El.Parent=',GetObjName(El.Parent),'.Parent=',GetObjName(El.Parent.Parent),' AbsParent=',GetObjName(AbsIdent.Parent),'.Parent=',GetObjName(AbsIdent.Parent.Parent));
         {$ENDIF}
         {$ENDIF}
         RaiseMsg(20171226102424,nInvalidAbsoluteLocation,sInvalidAbsoluteLocation,[],El.AbsoluteExpr);
         RaiseMsg(20171226102424,nInvalidAbsoluteLocation,sInvalidAbsoluteLocation,[],El.AbsoluteExpr);
         end;
         end;

+ 17 - 4
packages/pastojs/tests/tcmodules.pas

@@ -3829,16 +3829,25 @@ begin
   'type',
   'type',
   '  TObject = class',
   '  TObject = class',
   '    Index: longint;',
   '    Index: longint;',
+  '    procedure DoAbs(Item: pointer);',
   '  end;',
   '  end;',
-  'procedure DoIt(i: longint);',
+  'procedure TObject.DoAbs(Item: pointer);',
+  'var',
+  '  o: TObject absolute Item;',
+  'begin',
+  '  if o.Index<o.Index then o.Index:=o.Index;',
+  'end;',
+  'procedure DoIt(i: longint; p: pointer);',
   'var',
   'var',
   '  d: double absolute i;',
   '  d: double absolute i;',
   '  s: string absolute d;',
   '  s: string absolute d;',
-  '  o: TObject absolute i;',
+  '  oi: TObject absolute i;',
+  '  op: TObject absolute p;',
   'begin',
   'begin',
   '  if d=d then d:=d;',
   '  if d=d then d:=d;',
   '  if s=s then s:=s;',
   '  if s=s then s:=s;',
-  '  if o.Index<o.Index then o.Index:=o.Index;',
+  '  if oi.Index<oi.Index then oi.Index:=oi.Index;',
+  '  if op.Index=op.Index then op.Index:=op.Index;',
   'end;',
   'end;',
   'begin']);
   'begin']);
   ConvertProgram;
   ConvertProgram;
@@ -3850,11 +3859,15 @@ begin
     '  };',
     '  };',
     '  this.$final = function () {',
     '  this.$final = function () {',
     '  };',
     '  };',
+    '  this.DoAbs = function (Item) {',
+    '    if (Item.Index < Item.Index) Item.Index = Item.Index;',
+    '  };',
     '});',
     '});',
-    'this.DoIt = function (i) {',
+    'this.DoIt = function (i, p) {',
     '  if (i === i) i = i;',
     '  if (i === i) i = i;',
     '  if (i === i) i = i;',
     '  if (i === i) i = i;',
     '  if (i.Index < i.Index) i.Index = i.Index;',
     '  if (i.Index < i.Index) i.Index = i.Index;',
+    '  if (p.Index === p.Index) p.Index = p.Index;',
     '};'
     '};'
     ]),
     ]),
     LinesToStr([
     LinesToStr([