Bladeren bron

* hack around the -intconst hack in pexpr when recording tokens, resolves #9471

git-svn-id: trunk@8734 -
florian 18 jaren geleden
bovenliggende
commit
6e5ff9b825
3 gewijzigde bestanden met toevoegingen van 34 en 0 verwijderingen
  1. 1 0
      .gitattributes
  2. 6 0
      compiler/scanner.pas
  3. 27 0
      tests/webtbs/tw9471.pp

+ 1 - 0
.gitattributes

@@ -8467,6 +8467,7 @@ tests/webtbs/tw9347a.pp svneol=native#text/plain
 tests/webtbs/tw9347b.pp svneol=native#text/plain
 tests/webtbs/tw9384.pp svneol=native#text/plain
 tests/webtbs/tw9385.pp svneol=native#text/plain
+tests/webtbs/tw9471.pp -text
 tests/webtbs/tw9667.pp svneol=native#text/plain
 tests/webtbs/tw9672.pp svneol=native#text/plain
 tests/webtbs/tw9673.pp -text

+ 6 - 0
compiler/scanner.pas

@@ -1902,6 +1902,12 @@ In case not, the value returned can be arbitrary.
           _INTCONST,
           _REALNUMBER :
             begin
+              { pexpr.pas messes with pattern in case of negative integer consts,
+                see around line 2562 the comment of JM; remove the - before recording it
+                                                     (FK)
+              }
+              if (token=_INTCONST) and (pattern[1]='-') then
+                delete(pattern,1,1);
               recordtokenbuf.write(pattern[0],1);
               recordtokenbuf.write(pattern[1],length(pattern));
             end;

+ 27 - 0
tests/webtbs/tw9471.pp

@@ -0,0 +1,27 @@
+{$mode objfpc}
+
+type
+  generic GList<_T> = class
+    var private
+      i : integer;
+    function some_func(): integer;
+  end;
+
+function GList.some_func(): integer;
+begin
+  i := -1;
+  Result := -1;
+end { some_func };
+
+
+type
+  TA = specialize GList<integer>;
+var
+  A : TA;
+
+begin
+  A:=TA.Create;
+  if A.some_func<>-1 then
+    halt(1);
+  writeln('ok');
+end.