diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2023-03-04 17:13:54 +0000 |
---|---|---|
committer | Paul Evans <leonerd@leonerd.org.uk> | 2023-03-07 11:32:21 +0000 |
commit | 2da014bc9fd80ae0453878c6cca2e22309637641 (patch) | |
tree | ba06ef24f0f67e23673c00e034854c3fda3922ee /t | |
parent | 3740cf6d26acbeaa48675e7ec51b6c92f5749e8b (diff) | |
download | perl-2da014bc9fd80ae0453878c6cca2e22309637641.tar.gz |
Permit internal OP_GOTO when forbidding out-of-block ops
Diffstat (limited to 't')
-rw-r--r-- | t/class/field.t | 15 | ||||
-rw-r--r-- | t/op/defer.t | 13 |
2 files changed, 27 insertions, 1 deletions
diff --git a/t/class/field.t b/t/class/field.t index ba4e64baca..a12fb65413 100644 --- a/t/class/field.t +++ b/t/class/field.t @@ -282,4 +282,19 @@ no warnings 'experimental::class'; 'Values for missing'); } +# field initialiser expressions permit `goto` in do {} blocks +{ + class Test13 { + field $forwards = do { goto HERE; HERE: 1 }; + field $backwards = do { my $x; HERE: ; goto HERE if !$x++; 2 }; + + method values { return ($forwards, $backwards) } + } + + ok(eq_array( + [Test13->new->values], + [1, 2], + 'Values for goto inside do {} blocks in field initialisers')); +} + done_testing; diff --git a/t/op/defer.t b/t/op/defer.t index c651312cb5..fd712d9c66 100644 --- a/t/op/defer.t +++ b/t/op/defer.t @@ -6,7 +6,7 @@ BEGIN { set_up_inc('../lib'); } -plan 26; +plan 28; use feature 'defer'; no warnings 'experimental::defer'; @@ -251,6 +251,17 @@ no warnings 'experimental::defer'; like($e, qr/^Oopsie \d\n/, 'defer block can throw exception during exception unwind'); } +# goto +{ + ok(defined eval 'sub { defer { goto HERE; HERE: 1; } }', + 'goto forwards within defer {} is permitted') or + diag("Failure was $@"); + + ok(defined eval 'sub { defer { HERE: 1; goto HERE; } }', + 'goto backwards within defer {} is permitted') or + diag("Failure was $@"); +} + { my $sub = sub { while(1) { |