Răsfoiți Sursa

* fix #41075: don't allow @<anonfunc>
+ added tests

Sven/Sarah Barth 7 luni în urmă
părinte
comite
310afcd783

+ 8 - 0
compiler/pexpr.pas

@@ -4347,6 +4347,7 @@ implementation
                  if (block_type=bt_body) and
                      (m_anonymous_functions in current_settings.modeswitches) then
                    begin
+                     filepos:=current_filepos;
                      oldprocvardef:=getprocvardef;
                      oldfuncrefdef:=getfuncrefdef;
                      getprocvardef:=nil;
@@ -4358,6 +4359,13 @@ implementation
                        tokens follow that indicate a call }
                      do_proc_call(pd.procsym,pd.owner,nil,not (token in [_POINT,_CARET,_LECKKLAMMER]),
                                   again,p1,[],nil);
+                     { don't allow @<anon func>, but keep the parsing for recovery }
+                     if (p1.nodetype<>errorn) and getaddr then
+                       begin
+                         p1.free;
+                         p1:=cerrornode.create;
+                         MessagePos(filepos,parser_e_illegal_expression);
+                       end;
                    end
                  else
                    begin

+ 21 - 0
tests/webtbf/tw41075a.pp

@@ -0,0 +1,21 @@
+{ %FAIL }
+
+program tw41075a;
+
+{$modeswitch ANONYMOUSFUNCTIONS}
+
+//{$modeswitch CLASSICPROCVARS} // with this its a regular error: expected procedure, got pointer
+//{$modeswitch POINTERTOPROCVAR} // with this (and CLASSICPROCVARS) the code works fine
+
+procedure test(p: TProcedure);
+begin
+  p;
+end;
+
+begin
+  test(@(procedure // Error: Internal error 2021052602
+  begin
+    writeln('Hello');
+  end));
+end.
+

+ 21 - 0
tests/webtbf/tw41075b.pp

@@ -0,0 +1,21 @@
+{ %FAIL }
+
+program tw41075b;
+
+{$modeswitch ANONYMOUSFUNCTIONS}
+
+{$modeswitch CLASSICPROCVARS} // with this its a regular error: expected procedure, got pointer
+//{$modeswitch POINTERTOPROCVAR} // with this (and CLASSICPROCVARS) the code works fine
+
+procedure test(p: TProcedure);
+begin
+  p;
+end;
+
+begin
+  test(@(procedure // Error: Internal error 2021052602
+  begin
+    writeln('Hello');
+  end));
+end.
+

+ 21 - 0
tests/webtbf/tw41075c.pp

@@ -0,0 +1,21 @@
+{ %FAIL }
+
+program tw41075c;
+
+{$modeswitch ANONYMOUSFUNCTIONS}
+
+//{$modeswitch CLASSICPROCVARS} // with this its a regular error: expected procedure, got pointer
+{$modeswitch POINTERTOPROCVAR} // with this (and CLASSICPROCVARS) the code works fine
+
+procedure test(p: TProcedure);
+begin
+  p;
+end;
+
+begin
+  test(@(procedure // Error: Internal error 2021052602
+  begin
+    writeln('Hello');
+  end));
+end.
+

+ 21 - 0
tests/webtbf/tw41075d.pp

@@ -0,0 +1,21 @@
+{ %FAIL }
+
+program tw41075d;
+
+{$modeswitch ANONYMOUSFUNCTIONS}
+
+{$modeswitch CLASSICPROCVARS} // with this its a regular error: expected procedure, got pointer
+{$modeswitch POINTERTOPROCVAR} // with this (and CLASSICPROCVARS) the code works fine
+
+procedure test(p: TProcedure);
+begin
+  p;
+end;
+
+begin
+  test(@(procedure // Error: Internal error 2021052602
+  begin
+    writeln('Hello');
+  end));
+end.
+