pastojs: fixed attributes of indirectly used class

git-svn-id: trunk@48896 -
(cherry picked from commit 9fbaa28df7)
This commit is contained in:
Mattias Gaertner 2021-03-07 12:48:14 +00:00 committed by Florian Klämpfl
parent 01439291c2
commit 494263cf7c
3 changed files with 14 additions and 4 deletions

View File

@ -262,7 +262,7 @@ type
procedure UseElement(El: TPasElement; Access: TResolvedRefAccess; procedure UseElement(El: TPasElement; Access: TResolvedRefAccess;
UseFull: boolean); virtual; UseFull: boolean); virtual;
procedure UseTypeInfo(El: TPasElement); 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; function UseModule(aModule: TPasModule; Mode: TPAUseMode): boolean; virtual;
procedure UseSection(Section: TPasSection; Mode: TPAUseMode); virtual; procedure UseSection(Section: TPasSection; Mode: TPAUseMode); virtual;
procedure UseImplBlock(Block: TPasImplBlock; Mark: boolean); virtual; procedure UseImplBlock(Block: TPasImplBlock; Mark: boolean); virtual;
@ -1322,12 +1322,13 @@ begin
UseTypeInfo(El.Parent); UseTypeInfo(El.Parent);
end; end;
procedure TPasAnalyzer.UseAttributes(El: TPasElement); function TPasAnalyzer.UseAttributes(El: TPasElement): boolean;
var var
Calls: TPasExprArray; Calls: TPasExprArray;
i: Integer; i: Integer;
begin begin
Calls:=Resolver.GetAttributeCallsEl(El); Calls:=Resolver.GetAttributeCallsEl(El);
Result:=Calls<>nil;
for i:=0 to length(Calls)-1 do for i:=0 to length(Calls)-1 do
UseExpr(Calls[i]); UseExpr(Calls[i]);
end; end;
@ -2412,7 +2413,9 @@ begin
end; end;
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; end;
procedure TPasAnalyzer.UseClassConstructor(El: TPasMembersType); procedure TPasAnalyzer.UseClassConstructor(El: TPasMembersType);

View File

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

View File

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