* correctly write an error if one tries to implement a method introduced in a generic in a specialization of the generic, resolves issue #23169

git-svn-id: trunk@31241 -
This commit is contained in:
florian 2015-07-28 21:16:47 +00:00
parent a67a35c498
commit ee89e99189
6 changed files with 580 additions and 556 deletions

1
.gitattributes vendored
View File

@ -13136,6 +13136,7 @@ tests/webtbf/tw2281.pp svneol=native#text/plain
tests/webtbf/tw2285.pp svneol=native#text/plain
tests/webtbf/tw22941.pp svneol=native#text/plain
tests/webtbf/tw23110.pp svneol=native#text/plain
tests/webtbf/tw23169.pp svneol=native#text/pascal
tests/webtbf/tw23546b.pp svneol=native#text/pascal
tests/webtbf/tw23547a.pp svneol=native#text/pascal
tests/webtbf/tw23547b.pp svneol=native#text/pascal

View File

@ -1534,7 +1534,8 @@ parser_e_global_generic_references_static=03339_E_Global Generic template refere
parser_u_already_compiled=03340_UL_Unit $1 has been already compiled meanwhile.
% This tells you that the recursive reading of the uses clauses triggered already
% a compilation of the current unit, so the current compilation can be aborted.
%
parser_e_explicit_method_implementation_for_specializations_not_allowed=03341_E_Explicit implementation of methods for specializations of generics is not allowed
% Methods introduced in a generic must be implemented for the generic. It is not possible to implement them only for specializations.
%
%
% \end{description}

View File

@ -442,6 +442,7 @@ const
parser_w_ptr_type_ignored=03338;
parser_e_global_generic_references_static=03339;
parser_u_already_compiled=03340;
parser_e_explicit_method_implementation_for_specializations_not_allowed=03341;
type_e_mismatch=04000;
type_e_incompatible_types=04001;
type_e_not_equal_types=04002;
@ -1010,9 +1011,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 75410;
MsgTxtSize = 75500;
MsgIdxMax : array[1..20] of longint=(
26,99,341,124,96,58,126,32,202,64,
26,99,342,124,96,58,126,32,202,64,
58,20,1,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -996,45 +996,50 @@ implementation
end;
if (df_specialization in pd.struct.defoptions) then
begin
include(pd.defoptions,df_specialization);
{ Find corresponding genericdef, we need it later to
replay the tokens to generate the body }
if not assigned(pd.struct.genericdef) then
internalerror(200512113);
genericst:=pd.struct.genericdef.GetSymtable(gs_record);
if not assigned(genericst) then
internalerror(200512114);
{ when searching for the correct procdef to use as genericdef we need to ignore
everything except procdefs so that we can find the correct indices }
index:=0;
found:=false;
for i:=0 to pd.owner.deflist.count-1 do
if assigned(current_specializedef) then
begin
if tdef(pd.owner.deflist[i]).typ<>procdef then
continue;
if pd.owner.deflist[i]=pd then
include(pd.defoptions,df_specialization);
{ Find corresponding genericdef, we need it later to
replay the tokens to generate the body }
if not assigned(pd.struct.genericdef) then
internalerror(200512113);
genericst:=pd.struct.genericdef.GetSymtable(gs_record);
if not assigned(genericst) then
internalerror(200512114);
{ when searching for the correct procdef to use as genericdef we need to ignore
everything except procdefs so that we can find the correct indices }
index:=0;
found:=false;
for i:=0 to pd.owner.deflist.count-1 do
begin
found:=true;
break;
if tdef(pd.owner.deflist[i]).typ<>procdef then
continue;
if pd.owner.deflist[i]=pd then
begin
found:=true;
break;
end;
inc(index);
end;
inc(index);
end;
if not found then
internalerror(2014052301);
if not found then
internalerror(2014052301);
for i:=0 to genericst.deflist.count-1 do
begin
if tdef(genericst.deflist[i]).typ<>procdef then
continue;
if index=0 then
pd.genericdef:=tstoreddef(genericst.deflist[i]);
dec(index);
end;
for i:=0 to genericst.deflist.count-1 do
begin
if tdef(genericst.deflist[i]).typ<>procdef then
continue;
if index=0 then
pd.genericdef:=tstoreddef(genericst.deflist[i]);
dec(index);
end;
if not assigned(pd.genericdef) or
(pd.genericdef.typ<>procdef) then
internalerror(200512115);
if not assigned(pd.genericdef) or
(pd.genericdef.typ<>procdef) then
internalerror(200512115);
end
else
Message(parser_e_explicit_method_implementation_for_specializations_not_allowed);
end;
end;

18
tests/webtbf/tw23169.pp Normal file
View File

@ -0,0 +1,18 @@
{ %fail }
{$mode objfpc}
uses gvector;
type
generic TObjectVector<T> = class(specialize TVector<T>)
procedure X; //Destroy; override;
end;
TMyVector = specialize TObjectVector<TObject>;
//destructor TMyVector.Destroy;
procedure TMyVector.X;
begin
end;
begin
end.