fcl-passrc: forbid type reference to TGeneric.Something

git-svn-id: trunk@44203 -
This commit is contained in:
Mattias Gaertner 2020-02-17 12:15:56 +00:00
parent 40a975b803
commit f05b51d7d8
2 changed files with 24 additions and 0 deletions

View File

@ -20560,6 +20560,10 @@ begin
NeedPop:=true;
if CurScopeEl is TPasType then
begin
if (CurScopeEl is TPasGenericType)
and not IsFullySpecialized(TPasGenericType(CurScopeEl)) then
RaiseMsg(20200217131215,nGenericsWithoutSpecializationAsType,
sGenericsWithoutSpecializationAsType,['reference'],ErrorEl);
CurScope:=PushDotScope(TPasType(CurScopeEl));
if CurScope=nil then
RaiseMsg(20190122122529,nIllegalQualifierAfter,sIllegalQualifierAfter,

View File

@ -88,6 +88,7 @@ type
procedure TestGen_Class_Self;
procedure TestGen_Class_MemberTypeConstructor;
procedure TestGen_Class_AliasMemberType;
procedure TestGen_Class_AccessGenericMemberTypeFail;
procedure TestGen_Class_ReferenceTo; // ToDo
procedure TestGen_Class_List;
// ToDo: different modeswitches at parse time and specialize time
@ -1416,6 +1417,25 @@ begin
ParseProgram;
end;
procedure TTestResolveGenerics.TestGen_Class_AccessGenericMemberTypeFail;
begin
StartProgram(false);
Add([
'{$mode objfpc}',
'type',
' TObject = class end;',
'',
' generic TBird<T> = class',
' public type',
' TRun = reference to function (aValue : T) : T;',
' end;',
' TBirdRun = TBird.TRun;',
'begin',
'']);
CheckResolverException('Generics without specialization cannot be used as a type for a reference',
nGenericsWithoutSpecializationAsType);
end;
procedure TTestResolveGenerics.TestGen_Class_ReferenceTo;
begin
exit;