Browse Source

fcl-passrc: parser: error on class const

git-svn-id: trunk@38300 -
Mattias Gaertner 7 years ago
parent
commit
8812f9e020

+ 0 - 2
packages/fcl-passrc/src/pasuseanalyzer.pas

@@ -666,8 +666,6 @@ begin
   else if (C=TPasAliasType) or (C=TPasTypeAliasType) then
   else if (C=TPasAliasType) or (C=TPasTypeAliasType) then
     UsePublished(TPasAliasType(El).DestType)
     UsePublished(TPasAliasType(El).DestType)
   else if C=TPasEnumType then
   else if C=TPasEnumType then
-    for i:=0 to TPasEnumType(El).Values.Count-1 do
-      UsePublished(TPasEnumValue(TPasEnumType(El).Values[i]))
   else if C=TPasSetType then
   else if C=TPasSetType then
     UsePublished(TPasSetType(El).EnumType)
     UsePublished(TPasSetType(El).EnumType)
   else if C=TPasRangeType then
   else if C=TPasRangeType then

+ 5 - 0
packages/fcl-passrc/src/pparser.pp

@@ -6020,7 +6020,12 @@ begin
       tkType:
       tkType:
         CurSection:=stType;
         CurSection:=stType;
       tkConst:
       tkConst:
+        begin
+        if haveClass then
+          ParseExc(nParserExpectToken2Error,SParserExpectToken2Error,
+            ['Procedure','Var']);
         CurSection:=stConst;
         CurSection:=stConst;
+        end;
       tkVar:
       tkVar:
         if LastToken=tkClass then
         if LastToken=tkClass then
           CurSection:=stClassVar
           CurSection:=stClassVar

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

@@ -507,6 +507,7 @@ type
     Procedure TestClass_VarExternal;
     Procedure TestClass_VarExternal;
     Procedure TestClass_WarnOverrideLowerVisibility;
     Procedure TestClass_WarnOverrideLowerVisibility;
     Procedure TestClass_Const;
     Procedure TestClass_Const;
+    Procedure TestClass_ClassConstFail;
     Procedure TestClass_Enumerator;
     Procedure TestClass_Enumerator;
     Procedure TestClass_EnumeratorFunc;
     Procedure TestClass_EnumeratorFunc;
     // Todo: Fail to use class.method in constant or type, e.g. const p = @o.doit;
     // Todo: Fail to use class.method in constant or type, e.g. const p = @o.doit;
@@ -8434,6 +8435,18 @@ begin
   CheckResolverUnexpectedHints;
   CheckResolverUnexpectedHints;
 end;
 end;
 
 
+procedure TTestResolver.TestClass_ClassConstFail;
+begin
+  StartProgram(false);
+  Add([
+  'type',
+  '  TObject = class',
+  '    class const c = 1;',
+  '  end;',
+  'begin']);
+  CheckParserException(sParserExpectToken2Error,nParserExpectToken2Error);
+end;
+
 procedure TTestResolver.TestClass_Enumerator;
 procedure TTestResolver.TestClass_Enumerator;
 begin
 begin
   StartProgram(false);
   StartProgram(false);