diff --git a/compiler/packages/fcl-passrc/src/pasuseanalyzer.pas b/compiler/packages/fcl-passrc/src/pasuseanalyzer.pas index 870986a..d9dea0b 100644 --- a/compiler/packages/fcl-passrc/src/pasuseanalyzer.pas +++ b/compiler/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); diff --git a/compiler/packages/pastojs/src/fppas2js.pp b/compiler/packages/pastojs/src/fppas2js.pp index b2b97b8..aeb65e0 100644 --- a/compiler/packages/pastojs/src/fppas2js.pp +++ b/compiler/packages/pastojs/src/fppas2js.pp @@ -15526,11 +15526,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 diff --git a/compiler/packages/pastojs/tests/tcmodules.pas b/compiler/packages/pastojs/tests/tcmodules.pas index d6c2dc1..f6733b7 100644 --- a/compiler/packages/pastojs/tests/tcmodules.pas +++ b/compiler/packages/pastojs/tests/tcmodules.pas @@ -31747,6 +31747,9 @@ begin ' [TCustom(1)]', ' TMyClass = class', ' end;', + ' [TCustom(11)]', + ' TMyDescendant = class(TMyClass)', + ' end;', ' [TCustom(2)]', ' TRec = record', ' end;', @@ -31779,6 +31782,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;',