diff --git a/compiler/ncnv.pas b/compiler/ncnv.pas index fef219df66..ee52207f1a 100644 --- a/compiler/ncnv.pas +++ b/compiler/ncnv.pas @@ -2494,6 +2494,7 @@ implementation aprocdef : tprocdef; eq : tequaltype; cdoptions : tcompare_defs_options; + selfnode : tnode; newblock: tblocknode; newstatement: tstatementnode; tempnode: ttempcreatenode; @@ -2657,8 +2658,14 @@ implementation tprocdef(currprocdef),tcallnode(left).symtableproc); if (tcallnode(left).symtableprocentry.owner.symtabletype=ObjectSymtable) then begin - if assigned(tcallnode(left).methodpointer) then - tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy) + selfnode:=tcallnode(left).methodpointer; + if assigned(selfnode) then + begin + { in case the nodetype is a typen, avoid the internal error + in set_mp and instead let the code error out normally } + if selfnode.nodetype<>typen then + tloadnode(hp).set_mp(selfnode.getcopy) + end else tloadnode(hp).set_mp(load_self_node); end; diff --git a/tests/test/tprocvar11.pp b/tests/test/tprocvar11.pp new file mode 100644 index 0000000000..03d5d7b87a --- /dev/null +++ b/tests/test/tprocvar11.pp @@ -0,0 +1,17 @@ +{ %FAIL } + +program tprocvar11; + +{$mode delphi} + +type C = class + class procedure NonStatic; +end; +class procedure C.NonStatic; begin end; + +type CC = class of C; + +var IncompatWNonStatic: procedure; +begin + IncompatWNonStatic := CC.NonStatic; +end. diff --git a/tests/test/tprocvar12.pp b/tests/test/tprocvar12.pp new file mode 100644 index 0000000000..4a855d6c1c --- /dev/null +++ b/tests/test/tprocvar12.pp @@ -0,0 +1,17 @@ +{ %FAIL } + +program tprocvar12; + +{$mode delphi} + +type C = class + class procedure Static; static; +end; +class procedure C.Static; begin end; + +type CC = class of C; + +var IncompatWStatic: procedure of object; +begin + IncompatWStatic := CC.Static; +end. diff --git a/tests/test/tprocvar13.pp b/tests/test/tprocvar13.pp new file mode 100644 index 0000000000..35d31858c9 --- /dev/null +++ b/tests/test/tprocvar13.pp @@ -0,0 +1,15 @@ +{ %FAIL } + +program tprocvar13; + +{$mode delphi} + +type O = object + class procedure Static; static; +end; +class procedure O.Static; begin end; + +var IncompatWStatic: procedure of object; +begin + IncompatWStatic := O.Static; +end. diff --git a/tests/test/tprocvar14.pp b/tests/test/tprocvar14.pp new file mode 100644 index 0000000000..6d7299082b --- /dev/null +++ b/tests/test/tprocvar14.pp @@ -0,0 +1,16 @@ +{ %FAIL } + +program tprocvar14; + +{$mode delphi} + +type C = class end; +type H = class helper for C + class procedure NonStatic; +end; +class procedure H.NonStatic; begin end; + +var IncompatWNonStatic: procedure; +begin + IncompatWNonStatic := H.NonStatic; +end. diff --git a/tests/test/tprocvar15.pp b/tests/test/tprocvar15.pp new file mode 100644 index 0000000000..3deda0ecf2 --- /dev/null +++ b/tests/test/tprocvar15.pp @@ -0,0 +1,16 @@ +{ %FAIL } + +program tprocvar15; + +{$mode delphi} + +type C = class end; +type H = class helper for C + class procedure Static; static; +end; +class procedure H.Static; begin end; + +var IncompatWStatic: procedure of object; +begin + IncompatWStatic := H.Static; +end.