Răsfoiți Sursa

* fix finally block getting unconditionally removed if try-block is empty
(hasnocode(nil) always returns true). Regression from r48174

git-svn-id: trunk@49305 -

Jonas Maebe 4 ani în urmă
părinte
comite
9977889f4a
3 a modificat fișierele cu 21 adăugiri și 2 ștergeri
  1. 1 0
      .gitattributes
  2. 2 2
      compiler/nflw.pas
  3. 18 0
      tests/webtbs/tw38833.pp

+ 1 - 0
.gitattributes

@@ -18839,6 +18839,7 @@ tests/webtbs/tw38718.pp svneol=native#text/pascal
 tests/webtbs/tw38733.pp svneol=native#text/pascal
 tests/webtbs/tw38766.pp svneol=native#text/plain
 tests/webtbs/tw38802.pp svneol=native#text/pascal
+tests/webtbs/tw38833.pp svneol=native#text/plain
 tests/webtbs/tw3893.pp svneol=native#text/plain
 tests/webtbs/tw3898.pp svneol=native#text/plain
 tests/webtbs/tw3899.pp svneol=native#text/plain

+ 2 - 2
compiler/nflw.pas

@@ -2734,10 +2734,10 @@ implementation
          begin
            result:=right;
            right:=nil;
-         end;
+         end
        { if the finally block contains no code, we can kill
          it and just return the try part }
-       if has_no_code(right) and not(assigned(third)) and not(implicitframe) then
+       else if has_no_code(right) and not(assigned(third)) and not(implicitframe) then
          begin
            result:=left;
            left:=nil;

+ 18 - 0
tests/webtbs/tw38833.pp

@@ -0,0 +1,18 @@
+program EmptyTryFinally1;
+
+{$mode delphi}
+{$apptype console}
+
+var
+  finallyrun: boolean;
+begin
+  finallyrun:=false;
+  try
+   // Empty try statement block
+  finally
+    WriteLn('I should actually visible . . .'); // but I'm not
+    finallyrun:=true;
+  end;
+  if not finallyrun then
+    halt(1);
+end.