Browse Source

* fix regression introduced with r47625 for Mantis #38122: when checking for a dereferentiation of the Self parameter subscript and vec nodes need to be kept
+ added test

git-svn-id: trunk@47747 -

svenbarth 4 years ago
parent
commit
1efeb5851a
3 changed files with 40 additions and 14 deletions
  1. 1 0
      .gitattributes
  2. 20 14
      compiler/ncal.pas
  3. 19 0
      tests/webtbs/tw38122b.pp

+ 1 - 0
.gitattributes

@@ -18599,6 +18599,7 @@ tests/webtbs/tw38069.pp svneol=native#text/pascal
 tests/webtbs/tw38074.pp svneol=native#text/pascal
 tests/webtbs/tw38083.pp svneol=native#text/pascal
 tests/webtbs/tw38122.pp svneol=native#text/pascal
+tests/webtbs/tw38122b.pp svneol=native#text/pascal
 tests/webtbs/tw3814.pp svneol=native#text/plain
 tests/webtbs/tw38145a.pp svneol=native#text/pascal
 tests/webtbs/tw38145b.pp svneol=native#text/pascal

+ 20 - 14
compiler/ncal.pas

@@ -4014,8 +4014,27 @@ implementation
 
               if methodpointer.nodetype<>typen then
                begin
-                  { Remove all postfix operators }
+                 { if the value a type helper works on is a derefentiation (before
+                   removing postix operators) we need to pass the original pointer
+                   as Self as the Self value might be changed by the helper }
+                 if is_objectpascal_helper(tdef(procdefinition.owner.defowner)) and
+                    not is_implicit_pointer_object_type(tobjectdef(procdefinition.owner.defowner).extendeddef) then
+                   begin
+                     hpt:=methodpointer;
+
+                     hpt:=actualtargetnode(@hpt)^;
+                     if hpt.nodetype=derefn then
+                       begin
+                         tmp:=tderefnode(hpt).left;
+                         tderefnode(hpt).left:=nil;
+                         methodpointer.free;
+                         methodpointer:=tmp;
+                       end;
+                   end;
+
                   hpt:=methodpointer;
+
+                  { Remove all postfix operators }
                   while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
                     hpt:=tunarynode(hpt).left;
 
@@ -4038,19 +4057,6 @@ implementation
                    e.g. class reference types account }
                  hpt:=actualtargetnode(@hpt)^;
 
-                 { if the value a type helper works on is a derefentiation we need to
-                   pass the original pointer as Self as the Self value might be
-                   changed by the helper }
-                 if is_objectpascal_helper(tdef(procdefinition.owner.defowner)) and
-                    not is_implicit_pointer_object_type(tobjectdef(procdefinition.owner.defowner).extendeddef) and
-                    (hpt.nodetype=derefn) then
-                   begin
-                     tmp:=tderefnode(hpt).left;
-                     tderefnode(hpt).left:=nil;
-                     methodpointer.free;
-                     methodpointer:=tmp;
-                   end;
-
                  { R.Init then R will be initialized by the constructor,
                    Also allow it for simple loads }
                  if (procdefinition.proctypeoption=potype_constructor) or

+ 19 - 0
tests/webtbs/tw38122b.pp

@@ -0,0 +1,19 @@
+program tw38122b;
+{$mode delphi}
+uses sysutils;
+type trec=record
+  i:integer;
+ end;
+
+ var rec:trec;
+     prec:^trec;
+     s: string;
+begin
+  rec.i:=20;
+  prec:=@rec;
+  s:=prec.i.tostring;
+  //writeln(s);
+  if s<>'20' then
+    halt(1);
+end.
+