Browse Source

fcl-passrc: resolver: fixed scopedenums for anonymous set type

git-svn-id: trunk@38706 -
Mattias Gaertner 7 years ago
parent
commit
c5b82873d2
2 changed files with 30 additions and 25 deletions
  1. 25 23
      packages/fcl-passrc/src/pasresolver.pp
  2. 5 2
      packages/fcl-passrc/tests/tcresolver.pas

+ 25 - 23
packages/fcl-passrc/src/pasresolver.pp

@@ -8173,32 +8173,34 @@ begin
     RaiseInvalidScopeForElement(20160929205736,El);
   AddIdentifier(TPasIdentifierScope(TopScope),El.Name,El,pikSimple);
 
-  if not (bsScopedEnums in CurrentParser.Scanner.CurrentBoolSwitches) then
+  // propagate enum to parent scopes
+  //  TEnum = (red, green); -> dot not propagate
+  //  TFlags = set of (red,blue); -> propagate
+  if (bsScopedEnums in CurrentParser.Scanner.CurrentBoolSwitches)
+      and not (El.Parent.Parent is TPasSetType) then
+    exit;
+  for i:=ScopeCount-2 downto 0 do
     begin
-    // propagate enum to parent scopes
-    for i:=ScopeCount-2 downto 0 do
+    Scope:=Scopes[i];
+    if (Scope is TPasClassScope) or (Scope is TPasRecordScope) then
       begin
-      Scope:=Scopes[i];
-      if (Scope is TPasClassScope) or (Scope is TPasRecordScope) then
-        begin
-        // class or record: add if not duplicate
-        Old:=TPasIdentifierScope(Scope).FindIdentifier(El.Name);
-        if Old=nil then
-          TPasIdentifierScope(Scope).AddIdentifier(El.Name,El,pikSimple);
-        end
-      else if (Scope is TPasProcedureScope) or (Scope is TPasSectionScope) then
-        begin
-        // procedure or section: check for duplicate and add
-        Old:=TPasIdentifierScope(Scope).FindLocalIdentifier(El.Name);
-        if Old<>nil then
-          RaiseMsg(20170216152224,nDuplicateIdentifier,sDuplicateIdentifier,
-                   [El.Name,GetElementSourcePosStr(Old.Element)],El);
+      // class or record: add if not duplicate
+      Old:=TPasIdentifierScope(Scope).FindIdentifier(El.Name);
+      if Old=nil then
         TPasIdentifierScope(Scope).AddIdentifier(El.Name,El,pikSimple);
-        break;
-        end
-      else
-        break;
-      end;
+      end
+    else if (Scope is TPasProcedureScope) or (Scope is TPasSectionScope) then
+      begin
+      // procedure or section: check for duplicate and add
+      Old:=TPasIdentifierScope(Scope).FindLocalIdentifier(El.Name);
+      if Old<>nil then
+        RaiseMsg(20170216152224,nDuplicateIdentifier,sDuplicateIdentifier,
+                 [El.Name,GetElementSourcePosStr(Old.Element)],El);
+      TPasIdentifierScope(Scope).AddIdentifier(El.Name,El,pikSimple);
+      break;
+      end
+    else
+      break;
     end;
 end;
 

+ 5 - 2
packages/fcl-passrc/tests/tcresolver.pas

@@ -3657,10 +3657,13 @@ begin
   'type',
   '  {$scopedenums on}',
   '  TEnum = (red, green);',
+  '  TFlags = set of (red,blue);',
   'var e: TEnum;',
+  '  f: TFlags;',
   'begin',
-  '  e:=TEnum.red;'
-  ]);
+  '  e:=TEnum.red;',
+  '  if red in f then ;',
+  '']);
   ParseProgram;
 end;