Browse Source

* allow exit(value) in exception blocks. Forbidding this dates back to
when this construct was still handled by custom code (mantis #16803)

git-svn-id: trunk@15492 -

Jonas Maebe 15 years ago
parent
commit
60041ebf8b
3 changed files with 47 additions and 8 deletions
  1. 1 0
      .gitattributes
  2. 1 8
      compiler/pexpr.pas
  3. 45 0
      tests/webtbs/tw16803.pp

+ 1 - 0
.gitattributes

@@ -10521,6 +10521,7 @@ tests/webtbs/tw16757.pp svneol=native#text/plain
 tests/webtbs/tw1677.pp svneol=native#text/plain
 tests/webtbs/tw1677.pp svneol=native#text/plain
 tests/webtbs/tw16770.pp svneol=native#text/plain
 tests/webtbs/tw16770.pp svneol=native#text/plain
 tests/webtbs/tw16772.pp svneol=native#text/plain
 tests/webtbs/tw16772.pp svneol=native#text/plain
+tests/webtbs/tw16803.pp svneol=native#text/plain
 tests/webtbs/tw1681.pp svneol=native#text/plain
 tests/webtbs/tw1681.pp svneol=native#text/plain
 tests/webtbs/tw1696.pp svneol=native#text/plain
 tests/webtbs/tw1696.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain

+ 1 - 8
compiler/pexpr.pas

@@ -298,14 +298,7 @@ implementation
                         begin
                         begin
                           p1:=comp_expr(true);
                           p1:=comp_expr(true);
                           consume(_RKLAMMER);
                           consume(_RKLAMMER);
-                          if (block_type=bt_except) then
-                            begin
-                              Message(parser_e_exit_with_argument_not__possible);
-                              { recovery }
-                              p1.free;
-                              p1:=nil;
-                            end
-                          else if (not assigned(current_procinfo) or
+                          if (not assigned(current_procinfo) or
                               is_void(current_procinfo.procdef.returndef)) then
                               is_void(current_procinfo.procdef.returndef)) then
                             begin
                             begin
                               Message(parser_e_void_function);
                               Message(parser_e_void_function);

+ 45 - 0
tests/webtbs/tw16803.pp

@@ -0,0 +1,45 @@
+{ %opt=-g-h }
+
+{$ifdef fpc}
+{$mode delphi}
+{$endif}
+
+uses
+  sysutils;
+
+function test1: longint; 
+begin
+   try
+     try
+       result:=1;
+       raise exception.create('1');
+     except
+        exit(2); 
+     end; 
+   except
+     exit(3);
+   end;
+end;
+
+function test2: ansistring; 
+begin
+   result:='a';
+   try
+     try
+       result:=result+'b';
+       raise exception.create('2');
+     except
+        result:=result+'c'; 
+     end; 
+   except
+     result:=result+'d';
+   end;
+end;
+
+begin
+  HaltOnNotReleased:=true;
+  if test1<>2 then
+    halt(1);
+  if test2<>'abc' then
+    halt(2)
+end.