Skip to content

Conversation

@jkeenan
Copy link
Contributor

@jkeenan jkeenan commented Aug 26, 2025

This is an excerpt from t/op/goto.t in blead:

 60 my $ok = 0;
 61 sub foo {
 62     goto bar;
 63     return;
 64 bar:
 65     $ok = 1;
 66 }
 67 
 68 &foo;
 69 ok($ok, 'goto in sub');
 70     
 71 sub bar {
 72     my $x = 'bypass';
 73     eval "goto $x";
 74 }
 75 
 76 &bar;
 77 exit;   # <== What is this doing here?
 78 
 79 FINALE:
 80 is(curr_test(), 20, 'FINALE');

Note the exit; statement in line 77. I can't figure out what effect this is having there. The program certainly continues past this point in the code. This statement was added by Larry 35 years ago!

commit 79072805bf63abe5b5978b5928ab00d360ea3e7f (tag: perl-5a2)
Author:     Larry Wall <larry@wall.org>
AuthorDate: Thu Oct 7 23:00:00 1993 +0000
Commit:     Larry Wall <larry@wall.org>
CommitDate: Thu Oct 7 23:00:00 1993 +0000

    perl 5.0 alpha 2
    
    [editor's note: from history.perl.org.  The sparc executables
    originally included in the distribution are not in this commit.]

...
diff --git a/t/op/goto.t b/t/op/goto.t
old mode 100644
new mode 100755
index 29bf797a58..0b89921b94
--- a/t/op/goto.t
+++ b/t/op/goto.t
...
+
+sub foo {
+    goto bar;
+    print "not ok 4\n";
+    return;
+bar:
+    print "ok 4\n";
+}
+
+&foo;
+
+sub bar {
+    $x = 'exitcode';
+    eval "goto $x";    # Do not take this as exemplary code!!!
+}
+
+&bar;
+exit;
+exitcode:
+print "ok 5\n";

Although I'm very reluctant to remove Larry code, we should consider doing so if it has no demonstrable effect. Submitting p.r.

  • This set of changes does not require a perldelta entry.

@jkeenan
Copy link
Contributor Author

jkeenan commented Aug 27, 2025

@tonycoz @iabyn Any thoughts on this? Thanks.

}

&bar;
exit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is here to ensure that bar does not return normally. (If it did, the exit would be executed, making the test fail because the rest of the planned tests wouldn't have run.)

It is important that the exit (or equivalent) remain there. For clarity, I would recommend adding an explicit fail:

&bar;
fail('goto bypass');
exit;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating p.r. per your comments; additional eyeballs welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; squashed and rebased on blead. Will leave open for 1 day for any other comments, then commit.

The 'exit;' statement is here to ensure that bar does not return
normally. (If it did, the exit would be executed, making the test fail
because the rest of the planned tests wouldn't have run.)

For clarity, I would recommend adding an explicit fail.
@jkeenan jkeenan added the squash-before-merge Author must squash the commits down before merging to blead label Aug 27, 2025
jkeenan added a commit that referenced this pull request Aug 29, 2025
The 'exit;' statement is here to ensure that bar does not return
normally. (If it did, the exit would be executed, making the test fail
because the rest of the planned tests wouldn't have run.)  For clarity,
adding an explicit fail.

For GH #23649.
@jkeenan jkeenan removed the squash-before-merge Author must squash the commits down before merging to blead label Aug 29, 2025
@jkeenan jkeenan merged commit f5de570 into Perl:blead Aug 29, 2025
33 checks passed
@jkeenan jkeenan self-assigned this Aug 29, 2025
@jkeenan jkeenan deleted the t-op-goto-exit-20250826 branch August 29, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants