浏览代码

* Attributes for methods. Fixes issue 41001

Michaël Van Canneyt 8 月之前
父节点
当前提交
22d7033d18
共有 2 个文件被更改,包括 17 次插入17 次删除
  1. 13 14
      compiler/pdecobj.pas
  2. 4 3
      compiler/pmodules.pas

+ 13 - 14
compiler/pdecobj.pas

@@ -1087,6 +1087,15 @@ implementation
         attr_element_count,fldCount : Integer;
         attr_element_count,fldCount : Integer;
         method_def : tprocdef;
         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;
       procedure parse_const;
         begin
         begin
           if not(current_objectdef.objecttype in [odt_class,odt_object,odt_helper,odt_javaclass,odt_interfacejava]) then
           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
           if not((token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_DESTRUCTOR,_THREADVAR]) or (token=_CONSTRUCTOR)) then
             Message(parser_e_procedure_or_function_expected);
             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 }
           { Java interfaces can contain final class vars }
           if is_interface(current_structdef) or
           if is_interface(current_structdef) or
              (is_javainterface(current_structdef) and
              (is_javainterface(current_structdef) and
@@ -1166,15 +1179,6 @@ implementation
         end;
         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
       begin
         { empty class declaration ? }
         { empty class declaration ? }
         if (current_objectdef.objecttype in [odt_class,odt_objcclass,odt_javaclass]) and
         if (current_objectdef.objecttype in [odt_class,odt_objcclass,odt_javaclass]) and
@@ -1439,12 +1443,7 @@ implementation
                 is_classdef:=false;
                 is_classdef:=false;
               end;
               end;
             _CLASS:
             _CLASS:
-              begin
-                { class properties currently can't have attributes, so it's safe
-                  to check for unbound attributes here }
-                check_unbound_attributes;
                 parse_class;
                 parse_class;
-              end;
             _PROCEDURE,
             _PROCEDURE,
             _FUNCTION,
             _FUNCTION,
             _CONSTRUCTOR,
             _CONSTRUCTOR,

+ 4 - 3
compiler/pmodules.pas

@@ -2630,6 +2630,10 @@ type
         if (target_cpu=tsystemcpu.cpu_wasm32) then
         if (target_cpu=tsystemcpu.cpu_wasm32) then
           add_synthetic_interface_classes_for_st(curr.localsymtable,true,true);
           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 }
         { Generate VMTs }
         if Errorcount=0 then
         if Errorcount=0 then
           write_vmts(curr.localsymtable,false);
           write_vmts(curr.localsymtable,false);
@@ -2638,9 +2642,6 @@ type
           the compiler }
           the compiler }
         add_synthetic_method_implementations(curr.localsymtable);
         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? }
         { should we force unit initialization? }
         force_init_final:=tstaticsymtable(curr.localsymtable).needs_init_final;
         force_init_final:=tstaticsymtable(curr.localsymtable).needs_init_final;
         if force_init_final or cnodeutils.force_init then
         if force_init_final or cnodeutils.force_init then