From d34acf3bc77f68c917b46ebb7a91fa024dd5cd86 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sat, 17 Dec 2016 21:20:44 +0000 Subject: [PATCH] * fix for Mantis #31120: check current_genericdef only if the current_procinfo isn't used + added test Note: the test is added to webtbs although it's right now still failing, cause I'll remove the restriction for nested procedures since the compiler now supports them correctly. Due to the way we handle generics we don't have problems with them unlike Delphi. git-svn-id: trunk@35147 - --- .gitattributes | 1 + compiler/pgenutil.pas | 34 +++++++++++++++++---------------- tests/webtbs/tw31120.pp | 42 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 tests/webtbs/tw31120.pp diff --git a/.gitattributes b/.gitattributes index 69810ccdb3..ce1dd29433 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15316,6 +15316,7 @@ tests/webtbs/tw3104.pp svneol=native#text/plain tests/webtbs/tw31076.pp svneol=native#text/pascal tests/webtbs/tw3109.pp svneol=native#text/plain tests/webtbs/tw3111.pp svneol=native#text/plain +tests/webtbs/tw31120.pp svneol=native#text/pascal tests/webtbs/tw3113.pp svneol=native#text/plain tests/webtbs/tw3124.pp svneol=native#text/plain tests/webtbs/tw3131.pp svneol=native#text/plain diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index 2ce6188380..788fa96163 100644 --- a/compiler/pgenutil.pas +++ b/compiler/pgenutil.pas @@ -845,27 +845,29 @@ uses { decide in which symtable to put the specialization } if parse_generic and not assigned(result) then begin - if not assigned(current_genericdef) then - internalerror(2014050901); if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) then { if we are parsing the definition of a method we specialize into the local symtable of it } specializest:=current_procinfo.procdef.getsymtable(gs_local) else - { we specialize the partial specialization into the symtable of the currently parsed - generic } - case current_genericdef.typ of - procvardef: - specializest:=current_genericdef.getsymtable(gs_para); - procdef: - specializest:=current_genericdef.getsymtable(gs_local); - objectdef, - recorddef: - specializest:=current_genericdef.getsymtable(gs_record); - arraydef: - specializest:=tarraydef(current_genericdef).symtable; - else - internalerror(2014050902); + begin + if not assigned(current_genericdef) then + internalerror(2014050901); + { we specialize the partial specialization into the symtable of the currently parsed + generic } + case current_genericdef.typ of + procvardef: + specializest:=current_genericdef.getsymtable(gs_para); + procdef: + specializest:=current_genericdef.getsymtable(gs_local); + objectdef, + recorddef: + specializest:=current_genericdef.getsymtable(gs_record); + arraydef: + specializest:=tarraydef(current_genericdef).symtable; + else + internalerror(2014050902); + end; end; end else diff --git a/tests/webtbs/tw31120.pp b/tests/webtbs/tw31120.pp new file mode 100644 index 0000000000..da06cfe377 --- /dev/null +++ b/tests/webtbs/tw31120.pp @@ -0,0 +1,42 @@ +{ %NORUN } + +program tw31120; + +{$mode objfpc} + +type + TTest = class + generic class procedure PrintDefault(); + end; + +generic Function GetDefault(): T; + Begin + result := default(T); + End; + +generic Procedure PrintDefault(); + procedure print(); + begin + writeln(specialize GetDefault()) + end; + + Begin + print() + End; + +generic class procedure TTest.PrintDefault(); + procedure print(); + begin + writeln(specialize GetDefault()) + end; + +begin + print() +end; + +Begin + specialize PrintDefault(); + specialize PrintDefault(); + TTest.specialize PrintDefault(); + TTest.specialize PrintDefault(); +End.