From 16774350d77a6942bdf47b39ddeb1c60da0a3b5d Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sun, 21 Sep 2014 19:15:37 +0000 Subject: [PATCH] Fix for Mantis #26749 . pgenutil.pas, generate_specialization: * first check whether we can reuse the current specialization or another specialization and only /then/ retrieve the symtable to specialize to + added test git-svn-id: trunk@28705 - --- .gitattributes | 1 + compiler/pgenutil.pas | 66 ++++++++++++++++++++--------------------- tests/webtbs/tw26749.pp | 27 +++++++++++++++++ 3 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 tests/webtbs/tw26749.pp diff --git a/.gitattributes b/.gitattributes index 8b11721dbc..08df1343de 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14088,6 +14088,7 @@ tests/webtbs/tw26627.pp -text svneol=native#text/plain tests/webtbs/tw2666.pp svneol=native#text/plain tests/webtbs/tw2668.pp svneol=native#text/plain tests/webtbs/tw2669.pp svneol=native#text/plain +tests/webtbs/tw26749.pp svneol=native#text/pascal tests/webtbs/tw2676.pp svneol=native#text/plain tests/webtbs/tw2678.pp svneol=native#text/plain tests/webtbs/tw2690.pp svneol=native#text/plain diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index 6187e16a35..63a13ee15c 100644 --- a/compiler/pgenutil.pas +++ b/compiler/pgenutil.pas @@ -689,39 +689,6 @@ uses (current_structdef.objname^=ufinalspecializename) then tt:=current_structdef; - { decide in which symtable to put the specialization } - if parse_generic 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, - 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 - else - if current_module.is_unit and current_module.in_interface then - specializest:=current_module.globalsymtable - else - specializest:=current_module.localsymtable; - if not assigned(specializest) then - internalerror(2014050910); - { Can we reuse an already specialized type? } { for this first check whether we are currently specializing a nested @@ -759,6 +726,39 @@ uses end; end; + { decide in which symtable to put the specialization } + if parse_generic and not assigned(tt) 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, + 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 + else + if current_module.is_unit and current_module.in_interface then + specializest:=current_module.globalsymtable + else + specializest:=current_module.localsymtable; + if not assigned(specializest) then + internalerror(2014050910); + { now check whether there is a specialization somewhere else } if not assigned(tt) then begin diff --git a/tests/webtbs/tw26749.pp b/tests/webtbs/tw26749.pp new file mode 100644 index 0000000000..600f9204c8 --- /dev/null +++ b/tests/webtbs/tw26749.pp @@ -0,0 +1,27 @@ +{ %NORUN } + +program tw26749; + +{$mode delphi} +{$modeswitch advancedrecords} + +type + + { TVector3 } + + TVector3 = record + class function null : TVector3; static; + end; + + TLine = array[0..1] of TVector3; + +{ TVector3 } + +class function TVector3.null : TVector3; +begin + +end; + +begin +end. +