diff --git a/compiler/ncal.pas b/compiler/ncal.pas index 204077cce2..ea0ab5e33e 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -304,6 +304,7 @@ implementation symconst,defutil,defcmp, htypechk,pass_1, ncnv,nflw,nld,ninl,nadd,ncon,nmem,nset,nobjc, + pgenutil, ngenutil,objcutil, procinfo,cpuinfo, wpobase; @@ -3603,6 +3604,8 @@ implementation { if the final procedure definition is not yet owned, ensure that it is } procdefinition.register_def; + if procdefinition.is_specialization and (procdefinition.typ=procdef) then + maybe_add_pending_specialization(procdefinition); candidates.free; end; { end of procedure to call determination } diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index 89b0f4427e..a1c7efd4cb 100644 --- a/compiler/pgenutil.pas +++ b/compiler/pgenutil.pas @@ -52,6 +52,7 @@ uses function could_be_generic(const name:tidstring):boolean;inline; procedure generate_specialization_procs; + procedure maybe_add_pending_specialization(def:tdef); procedure specialization_init(genericdef:tdef;var state:tspecializationstate); procedure specialization_done(var state:tspecializationstate); @@ -1072,10 +1073,9 @@ uses specialization_done(state); - if not assigned(result.owner) then - result.ChangeOwner(specializest); - - current_module.pendingspecializations.add(result.typename,result); + { procdefs are only added once we know which overload we use } + if result.typ<>procdef then + current_module.pendingspecializations.add(result.typename,result); end; generictypelist.free; @@ -1650,4 +1650,17 @@ uses end; + procedure maybe_add_pending_specialization(def:tdef); + var + hmodule : tmodule; + st : tsymtable; + begin + st:=def.owner; + while st.symtabletype in [localsymtable] do + st:=st.defowner.owner; + hmodule:=find_module_from_symtable(st); + if tstoreddef(def).is_specialization and (hmodule=current_module) then + current_module.pendingspecializations.add(def.typename,def); + end; + end.