Explorar o código

pastojs: fixed attributes of indirectly used class

git-svn-id: trunk@48896 -
Mattias Gaertner %!s(int64=4) %!d(string=hai) anos
pai
achega
9fbaa28df7

+ 6 - 3
packages/fcl-passrc/src/pasuseanalyzer.pas

@@ -262,7 +262,7 @@ type
     procedure UseElement(El: TPasElement; Access: TResolvedRefAccess;
       UseFull: boolean); virtual;
     procedure UseTypeInfo(El: TPasElement); virtual;
-    procedure UseAttributes(El: TPasElement); virtual;
+    function UseAttributes(El: TPasElement): boolean; virtual;
     function UseModule(aModule: TPasModule; Mode: TPAUseMode): boolean; virtual;
     procedure UseSection(Section: TPasSection; Mode: TPAUseMode); virtual;
     procedure UseImplBlock(Block: TPasImplBlock; Mark: boolean); virtual;
@@ -1322,12 +1322,13 @@ begin
     UseTypeInfo(El.Parent);
 end;
 
-procedure TPasAnalyzer.UseAttributes(El: TPasElement);
+function TPasAnalyzer.UseAttributes(El: TPasElement): boolean;
 var
   Calls: TPasExprArray;
   i: Integer;
 begin
   Calls:=Resolver.GetAttributeCallsEl(El);
+  Result:=Calls<>nil;
   for i:=0 to length(Calls)-1 do
     UseExpr(Calls[i]);
 end;
@@ -2412,7 +2413,9 @@ begin
         end;
     end;
 
-  UseAttributes(El);
+  if UseAttributes(El) and (El.ClassType=TPasClassType) then
+    UseTypeInfo(El); // class with attributes,
+        // typeinfo can be used at runtime via typeinfo(aClass) -> always mark
 end;
 
 procedure TPasAnalyzer.UseClassConstructor(El: TPasMembersType);

+ 1 - 1
packages/pastojs/src/fppas2js.pp

@@ -15579,11 +15579,11 @@ begin
     RaiseNotSupported(El,AContext,20170927183645);
   if El.Parent is TProcedureBody then
     RaiseNotSupported(El,AContext,20181231004355);
+  if not aResolver.IsFullySpecialized(El) then exit;
   if El.IsForward then
     exit(ConvertClassForwardType(El,AContext))
   else if El.IsExternal then
     exit(ConvertExtClassType(El,AContext));
-  if not aResolver.IsFullySpecialized(El) then exit;
 
   if El.CustomData is TPas2JSClassScope then
     begin

+ 7 - 0
packages/pastojs/tests/tcmodules.pas

@@ -31794,6 +31794,9 @@ begin
   '  [TCustom(1)]',
   '  TMyClass = class',
   '  end;',
+  '  [TCustom(11)]',
+  '  TMyDescendant = class(TMyClass)',
+  '  end;',
   '  [TCustom(2)]',
   '  TRec = record',
   '  end;',
@@ -31826,6 +31829,10 @@ begin
     '  var $r = this.$rtti;',
     '  $r.attr = [$mod.TCustomAttribute, "Create", [1]];',
     '});',
+    'rtl.createClass(this, "TMyDescendant", this.TMyClass, function () {',
+    '  var $r = this.$rtti;',
+    '  $r.attr = [$mod.TCustomAttribute, "Create", [11]];',
+    '});',
     'rtl.recNewT(this, "TRec", function () {',
     '  this.$eq = function (b) {',
     '    return true;',