summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-03-07 12:48:14 +0000
committermattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-03-07 12:48:14 +0000
commit58757095a3b986435c8f5b26843d93a7d7dda572 (patch)
tree354e0f82c838504b306465f13f70c818ce7ecf99
parentfc0ff88b344c5ad68b68fe891171f398c4e1b269 (diff)
downloadfpc-58757095a3b986435c8f5b26843d93a7d7dda572.tar.gz
pastojs: fixed attributes of indirectly used class
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@48896 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--packages/fcl-passrc/src/pasuseanalyzer.pas9
-rw-r--r--packages/pastojs/src/fppas2js.pp2
-rw-r--r--packages/pastojs/tests/tcmodules.pas7
3 files changed, 14 insertions, 4 deletions
diff --git a/packages/fcl-passrc/src/pasuseanalyzer.pas b/packages/fcl-passrc/src/pasuseanalyzer.pas
index 870986a344..d9dea0b85d 100644
--- a/packages/fcl-passrc/src/pasuseanalyzer.pas
+++ b/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/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp
index f931f6c38d..bb479e22f8 100644
--- a/packages/pastojs/src/fppas2js.pp
+++ b/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
diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas
index 1092da987a..8731d86b8f 100644
--- a/packages/pastojs/tests/tcmodules.pas
+++ b/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;',