Browse Source

fcl-passrc: test forbidden anonymous function types

mattias 3 years ago
parent
commit
04a2b42f63
1 changed files with 41 additions and 0 deletions
  1. 41 0
      packages/fcl-passrc/tests/tcresolver.pas

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

@@ -892,6 +892,9 @@ type
 
     // anonymous procedure type
     Procedure TestProcTypeAnonymous_FunctionFunctionFail;
+    Procedure TestProcTypeAnonymous_ResultTypeFail;
+    Procedure TestProcTypeAnonymous_ArgumentFail;
+    Procedure TestProcTypeAnonymous_PropertyFail;
 
     // pointer
     Procedure TestPointer;
@@ -16535,6 +16538,44 @@ begin
     nCannotNestAnonymousX);
 end;
 
+procedure TTestResolver.TestProcTypeAnonymous_ResultTypeFail;
+begin
+  StartProgram(false);
+  Add([
+  'function Fly: procedure;',
+  'begin',
+  'end;',
+  'begin']);
+  CheckResolverException('Cannot nest anonymous procedural type',
+    nCannotNestAnonymousX);
+end;
+
+procedure TTestResolver.TestProcTypeAnonymous_ArgumentFail;
+begin
+  StartProgram(false);
+  Add([
+  'procedure Fly(p: procedure);',
+  'begin',
+  'end;',
+  'begin']);
+  CheckResolverException('Cannot nest anonymous procedural type',
+    nCannotNestAnonymousX);
+end;
+
+procedure TTestResolver.TestProcTypeAnonymous_PropertyFail;
+begin
+  StartProgram(false);
+  Add([
+  'type',
+  '  TObject = class',
+  '    FProc: procedure;',
+  '    property Proc: procedure read FProc;',
+  '  end;',
+  'begin']);
+  CheckParserException('Expected ";" at token "Identifier read" in file afile.pp at line 5 column 30',
+    nParserExpectTokenError);
+end;
+
 procedure TTestResolver.TestPointer;
 begin
   StartProgram(false);