diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 4c0a8ab941..e8ee8fff4f 100644 --- a/compiler/pdecobj.pas +++ b/compiler/pdecobj.pas @@ -1087,6 +1087,15 @@ implementation attr_element_count,fldCount : Integer; method_def : tprocdef; + procedure check_unbound_attributes; + begin + if assigned(rtti_attrs_def) and (rtti_attrs_def.get_attribute_count>0) then + Message1(parser_e_unbound_attribute,trtti_attribute(rtti_attrs_def.rtti_attributes[0]).typesym.prettyname); + rtti_attrs_def.free; + rtti_attrs_def:=nil; + end; + + procedure parse_const; begin if not(current_objectdef.objecttype in [odt_class,odt_object,odt_helper,odt_javaclass,odt_interfacejava]) then @@ -1129,6 +1138,10 @@ implementation if not((token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_DESTRUCTOR,_THREADVAR]) or (token=_CONSTRUCTOR)) then Message(parser_e_procedure_or_function_expected); + { class properties currently can't have attributes } + if not(token in [_FUNCTION,_PROCEDURE]) then + check_unbound_attributes; + { Java interfaces can contain final class vars } if is_interface(current_structdef) or (is_javainterface(current_structdef) and @@ -1166,15 +1179,6 @@ implementation end; - procedure check_unbound_attributes; - begin - if assigned(rtti_attrs_def) and (rtti_attrs_def.get_attribute_count>0) then - Message1(parser_e_unbound_attribute,trtti_attribute(rtti_attrs_def.rtti_attributes[0]).typesym.prettyname); - rtti_attrs_def.free; - rtti_attrs_def:=nil; - end; - - begin { empty class declaration ? } if (current_objectdef.objecttype in [odt_class,odt_objcclass,odt_javaclass]) and @@ -1439,12 +1443,7 @@ implementation is_classdef:=false; end; _CLASS: - begin - { class properties currently can't have attributes, so it's safe - to check for unbound attributes here } - check_unbound_attributes; parse_class; - end; _PROCEDURE, _FUNCTION, _CONSTRUCTOR, diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index 46d339a390..f5923e693e 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -2630,6 +2630,10 @@ type if (target_cpu=tsystemcpu.cpu_wasm32) then add_synthetic_interface_classes_for_st(curr.localsymtable,true,true); + { generate construction functions for all attributes in the program } + { before write_vmts that asume attributes for methods is ready } + generate_attr_constrs(curr.used_rtti_attrs); + { Generate VMTs } if Errorcount=0 then write_vmts(curr.localsymtable,false); @@ -2638,9 +2642,6 @@ type the compiler } add_synthetic_method_implementations(curr.localsymtable); - { generate construction functions for all attributes in the program } - generate_attr_constrs(curr.used_rtti_attrs); - { should we force unit initialization? } force_init_final:=tstaticsymtable(curr.localsymtable).needs_init_final; if force_init_final or cnodeutils.force_init then