* ensure that an expression that involves an overloaded generic in mode Delphi isn't handled as a specialization if it shouldn't be

+ added tests
This commit is contained in:
Sven/Sarah Barth 2022-01-22 18:12:02 +01:00
parent d4e0a79d9e
commit 5ce96de0f2
6 changed files with 118 additions and 0 deletions

View File

@ -4431,6 +4431,9 @@ implementation
filepos : tfileposinfo;
gendef,parseddef : tdef;
gensym : tsym;
genlist : tfpobjectlist;
dummyagain : boolean;
dummyspezctxt : tspecializationcontext;
begin
SubExprStart:
if pred_level=highest_precedence then
@ -4520,6 +4523,39 @@ implementation
{ potential generic types that are followed by a "<": }
if p1.nodetype=specializen then
begin
genlist:=tfpobjectlist(current_module.genericdummysyms.find(tspecializenode(p1).sym.name));
if assigned(genlist) and (genlist.count>0) then
begin
gensym:=tgenericdummyentry(genlist.last).resolvedsym;
check_hints(gensym,gensym.symoptions,gensym.deprecatedmsg,p1.fileinfo);
dummyagain:=false;
dummyspezctxt:=nil;
ptmp:=factor_handle_sym(gensym,
gensym.owner,
dummyagain,
tspecializenode(p1).getaddr,
false,
flags,
dummyspezctxt);
if dummyagain then
internalerror(2022012201);
p1.free;
p1:=ptmp;
end
else
begin
identifier_not_found(tspecializenode(p1).sym.realname);
p1.free;
p1:=cerrornode.create;
end;
end;
{ a) might not have their resultdef set }
if not assigned(p1.resultdef) then
do_typecheckpass(p1);

14
tests/test/tgenconst31.pp Normal file
View File

@ -0,0 +1,14 @@
program tgenconst31;
{$mode delphi}
uses
ugenconst31a, ugenconst31b;
const
N = 42;
begin
if Test<N then
Writeln('Foo');
end.

19
tests/test/tgenconst32.pp Normal file
View File

@ -0,0 +1,19 @@
program tgenconst32;
{$mode delphi}
var
Test: LongInt = 42;
type
Test<const N: LongInt> = class
end;
const
N = 42;
begin
if Test<N then
Writeln('Foo');
end.

21
tests/test/tgenconst33.pp Normal file
View File

@ -0,0 +1,21 @@
{ %FAIL }
program tgenconst33;
{$mode delphi}
{var
Test: LongInt = 42;}
type
Test<const N: LongInt> = class
end;
const
N = 42;
begin
if Test<N then
Writeln('Foo');
end.

View File

@ -0,0 +1,13 @@
unit ugenconst31a;
{$mode objfpc}{$H+}
interface
var
Test: LongInt = 42;
implementation
end.

View File

@ -0,0 +1,15 @@
unit ugenconst31b;
{$mode delphi}{$H+}
interface
type
Test<const N: LongInt> = class
end;
implementation
end.