Skip to content

Commit 724a9b1

Browse files
committed
Make 'return' a term taking an optional argument.
This way, 'return;' won't be silently ignored in a function. Closes #127.
1 parent e13e2f4 commit 724a9b1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/NQP/Actions.nqp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,9 @@ class NQP::Actions is HLL::Actions {
15591559

15601560
method postfix:sym<.>($/) { make $<dotty>.ast; }
15611561

1562-
method prefix:sym<return>($/) {
1563-
make QAST::Op.new( :op('call'), :name('RETURN') );
1562+
method term:sym<return>($/) {
1563+
make QAST::Op.new( :op('call'), :name('RETURN'),
1564+
$<EXPR> ?? $<EXPR>.ast !! QAST::WVal.new( :value($*W.find_sym(['NQPMu'])) ));
15641565
}
15651566

15661567
method prefix:sym<make>($/) {

src/NQP/Grammar.nqp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ grammar NQP::Grammar is HLL::Grammar {
629629
}
630630

631631
token term:sym<name> {
632-
<name> <args>**0..1
632+
<name> <?{ ~$<name> ne 'return' }> <args>**0..1
633633
}
634634

635635
token args {
@@ -796,8 +796,8 @@ grammar NQP::Grammar is HLL::Grammar {
796796

797797
token infix:sym<,> { <sym> <O('%comma, :op<list>')> }
798798

799-
token prefix:sym<return> { <sym> \s <O('%list_prefix')> { $*RETURN_USED := 1 } }
800799
token prefix:sym<make> { <sym> \s <O('%list_prefix')> }
800+
token term:sym<return> { <sym> [\s <EXPR>]? { $*RETURN_USED := 1 } }
801801

802802
method smartmatch($/) {
803803
# swap rhs into invocant position

0 commit comments

Comments
 (0)