diff --git a/compiler/aasmcnst.pas b/compiler/aasmcnst.pas index 7904a66ec4..06b78a6230 100644 --- a/compiler/aasmcnst.pas +++ b/compiler/aasmcnst.pas @@ -1328,25 +1328,19 @@ implementation function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalignmin, maxcrecordalign: shortint): trecorddef; var anonrecorddef: trecorddef; - srsym: tsym; - srsymtable: tsymtable; - found: boolean; + typesym: ttypesym; begin { if the name is specified, we create a typesym with that name in order to ensure we can find it again later with that name -> reuse here as well if possible (and that also avoids duplicate type name issues) } if optionalname<>'' then begin - if optionalname[1]='$' then - found:=searchsym_in_module(current_module,copy(optionalname,2,length(optionalname)),srsym,srsymtable) - else - found:=searchsym_in_module(current_module,optionalname,srsym,srsymtable); - if found then + typesym:=try_search_current_module_type(optionalname); + if assigned(typesym) then begin - if (srsym.typ<>typesym) or - (ttypesym(srsym).typedef.typ<>recorddef) then - internalerror(2014091207); - result:=trecorddef(ttypesym(srsym).typedef); + if typesym.typedef.typ<>recorddef then + internalerror(2015071401); + result:=trecorddef(typesym.typedef); maybe_begin_aggregate(result); exit; end; diff --git a/compiler/symtable.pas b/compiler/symtable.pas index 671d84a315..179f017451 100644 --- a/compiler/symtable.pas +++ b/compiler/symtable.pas @@ -318,6 +318,7 @@ interface function searchsym_in_helper(classh,contextclassh:tobjectdef;const s: TIDString;out srsym:tsym;out srsymtable:TSymtable;flags:tsymbol_search_flags):boolean; function search_system_type(const s: TIDString): ttypesym; function try_search_system_type(const s: TIDString): ttypesym; + function try_search_current_module_type(const s: TIDString): ttypesym; function search_system_proc(const s: TIDString): tprocdef; function search_named_unit_globaltype(const unitname, typename: TIDString; throwerror: boolean): ttypesym; function search_struct_member(pd : tabstractrecorddef;const s : string):tsym; @@ -3599,6 +3600,27 @@ implementation end; + function try_search_current_module_type(const s: TIDString): ttypesym; + var + found: boolean; + srsymtable: tsymtable; + srsym: tsym; + begin + if s[1]='$' then + found:=searchsym_in_module(current_module,copy(s,2,length(s)),srsym,srsymtable) + else + found:=searchsym_in_module(current_module,s,srsym,srsymtable); + if found then + begin + if (srsym.typ<>typesym) then + internalerror(2014091207); + result:=ttypesym(srsym); + end + else + result:=nil; + end; + + function search_system_proc(const s: TIDString): tprocdef; var srsym: tsym;