Browse Source

* allow type = type ... ; syntax only for previously declared types, avoids also internal error for #40566

florian 1 year ago
parent
commit
bccc0b195e
6 changed files with 37 additions and 3 deletions
  1. 0 1
      compiler/pdecl.pas
  2. 7 1
      compiler/ptype.pas
  3. 1 1
      rtl/inc/systemh.inc
  4. 1 0
      tests/webtbf/tw25077.pp
  5. 13 0
      tests/webtbf/tw40566a.pp
  6. 15 0
      tests/webtbf/tw40566b.pp

+ 0 - 1
compiler/pdecl.pas

@@ -781,7 +781,6 @@ implementation
                genorgtypename:=orgtypename;
                genorgtypename:=orgtypename;
              end;
              end;
 
 
-
            consume(_EQ);
            consume(_EQ);
 
 
            { support 'ttype=type word' syntax }
            { support 'ttype=type word' syntax }

+ 7 - 1
compiler/ptype.pas

@@ -1725,10 +1725,16 @@ implementation
            name:=newsym.RealName
            name:=newsym.RealName
          else
          else
            name:='';
            name:='';
+         { type a = type ..,; syntax is allowed only with type syms and apparently helpers, see below }
+         if hadtypetoken and ((token<>_ID) or (idtoken=_REFERENCE)) and (token<>_STRING) and (token<>_FILE) then
+           consume(_ID);
          case token of
          case token of
             _STRING,_FILE:
             _STRING,_FILE:
               begin
               begin
-                single_type(def,[stoAllowTypeDef]);
+                if hadtypetoken then
+                  single_type(def,[])
+                else
+                  single_type(def,[stoAllowTypeDef]);
               end;
               end;
            _LKLAMMER:
            _LKLAMMER:
               begin
               begin

+ 1 - 1
rtl/inc/systemh.inc

@@ -570,7 +570,7 @@ Type
   UTF8Char = AnsiChar;
   UTF8Char = AnsiChar;
   PUTF8Char = PAnsiChar;
   PUTF8Char = PAnsiChar;
 
 
-  UCS4Char            = type 0..$10ffff;
+  UCS4Char            = 0..$10ffff;
   PUCS4Char           = ^UCS4Char;
   PUCS4Char           = ^UCS4Char;
 {$ifdef CPU16}
 {$ifdef CPU16}
   TUCS4CharArray      = array[0..32767 div sizeof(UCS4Char)-1] of UCS4Char;
   TUCS4CharArray      = array[0..32767 div sizeof(UCS4Char)-1] of UCS4Char;

+ 1 - 0
tests/webtbs/tw25077.pp → tests/webtbf/tw25077.pp

@@ -1,4 +1,5 @@
 { %NORUN}
 { %NORUN}
+{ %fail }
 program tw25077;
 program tw25077;
 
 
 TYPE AnyName = TYPE PROCEDURE (A : INTEGER);
 TYPE AnyName = TYPE PROCEDURE (A : INTEGER);

+ 13 - 0
tests/webtbf/tw40566a.pp

@@ -0,0 +1,13 @@
+{ %fail }
+{$mode objfpc}
+
+program Project1;
+type
+  Tbar = type class
+    f:integer;
+  end;
+
+  // tabc = specialize TBar<integer>; // Internal error 2012101001
+
+begin
+end.

+ 15 - 0
tests/webtbf/tw40566b.pp

@@ -0,0 +1,15 @@
+{ %fail }
+{$mode objfpc}
+{$modeswitch FUNCTIONREFERENCES}
+program Project1;
+type
+{  generic Tbar<_A> = type class
+    f:_A;
+  end;}
+
+  a = type reference to procedure;
+
+  tabc = specialize TBar<integer>; // Internal error 2012101001
+
+begin
+end.