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.