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

This commit is contained in:
florian 2024-02-20 23:13:31 +01:00
parent b61a0fab97
commit bccc0b195e
6 changed files with 37 additions and 3 deletions

View File

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

View File

@ -1725,10 +1725,16 @@ implementation
name:=newsym.RealName
else
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
_STRING,_FILE:
begin
single_type(def,[stoAllowTypeDef]);
if hadtypetoken then
single_type(def,[])
else
single_type(def,[stoAllowTypeDef]);
end;
_LKLAMMER:
begin

View File

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

View File

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

13
tests/webtbf/tw40566a.pp Normal file
View File

@ -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
tests/webtbf/tw40566b.pp Normal file
View File

@ -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.