Browse Source

fcl-passrc: useanalyzer: mark enumvalue parent types

git-svn-id: trunk@35865 -
Mattias Gaertner 8 years ago
parent
commit
88600b71ef

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

@@ -610,7 +610,12 @@ begin
   else if C.InheritsFrom(TPasExpr) then
     UseExpr(TPasExpr(El))
   else if C=TPasEnumValue then
-    MarkElementAsUsed(El)
+    begin
+    repeat
+      MarkElementAsUsed(El);
+      El:=El.Parent;
+    until not (El is TPasType);
+    end
   else if C.InheritsFrom(TPasModule) then
     // e.g. unitname.identifier -> the module is used by the identifier
   else

+ 13 - 0
packages/fcl-passrc/tests/tcuseanalyzer.pas

@@ -117,6 +117,7 @@ type
     procedure TestWP_PublishedRecordType;
     procedure TestWP_PublishedProcType;
     procedure TestWP_PublishedProperty;
+    procedure TestWP_BuiltInFunctions;
   end;
 
 implementation
@@ -1634,6 +1635,18 @@ begin
   AnalyzeWholeProgram;
 end;
 
+procedure TTestUseAnalyzer.TestWP_BuiltInFunctions;
+begin
+  StartProgram(false);
+  Add([
+  'type',
+  '  {#tordenum_used}TOrdEnum = (ordenum1,ordenum2);',
+  'begin',
+  '  if ord(ordenum1)=1 then ;',
+  '']);
+  AnalyzeWholeProgram;
+end;
+
 initialization
   RegisterTests([TTestUseAnalyzer]);