* allow nil to be assigned to generic types, resolves #34037

* niln is also a constant node

git-svn-id: trunk@39934 -
This commit is contained in:
florian 2018-10-14 07:38:13 +00:00
parent 5499533ddc
commit eea088c5f5
5 changed files with 30 additions and 5 deletions

1
.gitattributes vendored
View File

@ -16378,6 +16378,7 @@ tests/webtbs/tw33840.pp -text svneol=native#text/pascal
tests/webtbs/tw33898.pp -text svneol=native#text/pascal
tests/webtbs/tw3402.pp svneol=native#text/plain
tests/webtbs/tw34021.pp -text svneol=native#text/pascal
tests/webtbs/tw34037.pp svneol=native#text/pascal
tests/webtbs/tw3411.pp svneol=native#text/plain
tests/webtbs/tw34124.pp svneol=native#text/pascal
tests/webtbs/tw3418.pp svneol=native#text/plain

View File

@ -289,7 +289,8 @@ implementation
if assigned(tstoreddef(def_from).genconstraintdata) or
assigned(tstoreddef(def_to).genconstraintdata) then
begin
if def_from.typ<>def_to.typ then
{ constants could get another deftype (e.g. niln) }
if (def_from.typ<>def_to.typ) and not(fromtreetype in nodetype_const) then
begin
{ not compatible anyway }
doconv:=tc_not_possible;

View File

@ -197,11 +197,13 @@ interface
'specializen');
{ a set containing all const nodes }
nodetype_const = [ordconstn,
nodetype_const = [niln,
ordconstn,
pointerconstn,
stringconstn,
guidconstn,
realconstn];
realconstn,
setconstn];
type
{ all boolean field of ttree are now collected in flags }
@ -657,7 +659,7 @@ implementation
function is_constnode(p : tnode) : boolean;
begin
is_constnode:=(p.nodetype in [niln,ordconstn,realconstn,stringconstn,setconstn,pointerconstn,guidconstn]);
is_constnode:=(p.nodetype in nodetype_const);
end;

View File

@ -1939,7 +1939,7 @@ implementation
not is_objectpascal_helper(tdef(srsymtable.defowner)) then
internalerror(2013011401);
{ convert const node to temp node of the extended type }
if node.nodetype in (nodetype_const+[niln,addrn]) then
if node.nodetype in (nodetype_const+[addrn]) then
begin
extdef:=tobjectdef(srsymtable.defowner).extendeddef;
newstatement:=nil;

21
tests/webtbs/tw34037.pp Normal file
View File

@ -0,0 +1,21 @@
program project1;
{$mode objfpc}{$H+}
uses
Classes, FGL;
type
TBaseClass = class (TObject)
end;
generic TFPGObjectListEx<T: TBaseClass> = class (specialize TFPGObjectList<T>)
function GetItemByID(AID: Integer): T;
end;
function TFPGObjectListEx.GetItemByID(AID: Integer): T;
begin
Result:=nil; //T(nil);
end;
begin
end.