New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BEGIN blocks don't parse as expressions in Rakudo #608
Comments
From @masakI'm toying around with precompilation in Rakudo r35404. I can print the value of a 'time' call directly. $ ./perl6 -e 'say time' # works fine But I don't seem to be able to put the 'time' call in a BEGIN block, $ ./perl6 --target=PIR --output=precompiled.pir -e 'my $a = do BEGIN { |
From @masakRakudo r35404: $ ./perl6 -e 'BEGIN { say "OH HAI" }' # works |
From @kylehaThis is tested in S04-closure-traits/rvalue.t |
From @kylehaThis is an automatically generated mail to inform you that tests are now available in t/spec/S04-phasers/rvalue.t commit 4e1049963df253c5287810a4c579541fd55f16d6 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 and RT #74836 Inline Patchdiff --git a/t/spec/S04-phasers/rvalue.t b/t/spec/S04-phasers/rvalue.t
index 877b069..55ca63a 100644
--- a/t/spec/S04-phasers/rvalue.t
+++ b/t/spec/S04-phasers/rvalue.t
@@ -5,47 +5,74 @@ use v6;
use Test;
-plan 10;
+plan 16;
# L<S04/Phasers/"marked with a *" "used within" expression>
-my $hist = '';
+{
+ my $x = BEGIN { 8 };
+ is $x, 8, 'BEGIN block as expression';
-# Test INIT {} as rval:
+ # test that built-ins are available within a BEGIN block:
+ my $y = BEGIN { ucfirst 'moin' };
+ is $y, 'Moin', 'can access built-in functions in BEGIN blocks';
-my $init_val;
-my $init = {
- $init_val = INIT { $hist ~= 'I' };
+ my $z = BEGIN { 'moin'.ucfirst };
+ is $z, 'Moin', 'can access built-in methods in BEGIN blocks';
}
-is $init(), 'BCI', 'INIT {} runs only once';
-is $init_val, 'BCI', 'INIT {} as rval is its ret val';
-is $init(), 'BCI', 'INIT {} runs only once';
+{
+ my $x = BEGIN 8;
+ is $x, 8, 'BEGIN statement prefix as expression';
-# Test CHECK {} as rval:
+ # test that built-ins are available within a BEGIN block:
+ my $y = BEGIN ucfirst 'moin';
+ is $y, 'Moin', 'can access built-in functions in BEGIN statement prefix';
-my $check_val;
-my $check = {
- $check_val = CHECK { $hist ~= 'C' };
+ my $z = BEGIN 'moin'.ucfirst;
+ is $z, 'Moin', 'can access built-in methods in BEGIN statement prefix';
}
-is $check(), 'BC', 'CHECK {} runs only once';
-is $check_val, 'BC', 'CHECK {} as rval is its ret val';
-is $check(), 'BC', 'CHECK {} runs only once';
+#?rakudo skip 'lexicals in phasers'
+{
+ my $hist = '';
-# Test BEGIN {} as rval:
+ # Test INIT {} as rval:
-my $begin_val;
-my $begin = {
- $begin_val = BEGIN { $hist ~= 'B' };
-}
+ my $init_val;
+ my $init = {
+ $init_val = INIT { $hist ~= 'I' };
+ }
+
+ is $init(), 'BCI', 'INIT {} runs only once';
+ is $init_val, 'BCI', 'INIT {} as rval is its ret val';
+ is $init(), 'BCI', 'INIT {} runs only once';
+
+ # Test CHECK {} as rval:
+
+ my $check_val;
+ my $check = {
+ $check_val = CHECK { $hist ~= 'C' };
+ }
-is $begin(), 'B', 'BEGIN {} runs only once';
-is $begin_val, 'B', 'BEGIN {} as rval is its ret val';
-is $begin(), 'B', 'BEGIN {} runs only once';
+ is $check(), 'BC', 'CHECK {} runs only once';
+ is $check_val, 'BC', 'CHECK {} as rval is its ret val';
+ is $check(), 'BC', 'CHECK {} runs only once';
-# Test END {} as rval:
+ # Test BEGIN {} as rval:
-ok !eval 'my $end_val = END { 3 }', "END {} can't be used as a rvalue";
+ my $begin_val;
+ my $begin = {
+ $begin_val = BEGIN { $hist ~= 'B' };
+ }
+
+ is $begin(), 'B', 'BEGIN {} runs only once';
+ is $begin_val, 'B', 'BEGIN {} as rval is its ret val';
+ is $begin(), 'B', 'BEGIN {} runs only once';
+
+ # Test END {} as rval:
+
+ ok !eval 'my $end_val = END { 3 }', "END {} can't be used as a rvalue";
+}
# vim: ft=perl6 |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#62188 (status was 'resolved')
Searchable as RT62188$
The text was updated successfully, but these errors were encountered: