Skip to content

Commit

Permalink
RakuAST: detect a case of double closure
Browse files Browse the repository at this point in the history
Detects {* + 1}(1) which is {{$_ + 1}}(1) which won't do what's
intended.
  • Loading branch information
niner committed May 2, 2024
1 parent 4988fb3 commit 331f019
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Raku/ast/expressions.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,7 @@ class RakuAST::MetaPostfix::Hyper
class RakuAST::ApplyPostfix
is RakuAST::Termish
is RakuAST::BeginTime
is RakuAST::CheckTime
is RakuAST::WhateverApplicable
{
has RakuAST::Postfixish $.postfix;
Expand Down Expand Up @@ -2532,6 +2533,25 @@ class RakuAST::ApplyPostfix
}
}

method PERFORM-CHECK(Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
# ApplyPostfix ⎑(...)⎀
# Block ⎑{*.{}}⎀
# Blockoid π„ž -e:1 ⎑{*.{}}⎀
# StatementList π„ž -e:1 ⎑*.{}⎀
# Statement::Expression β–ͺπ„ž -e:1 ⎑*.{}⎀
# ... [curried]
# Call::Term ⎑(...)⎀
# ArgList ⎑...⎀
if nqp::istype($!operand, RakuAST::Block) && nqp::istype($!postfix, RakuAST::Call::Term) {
my $stmts := $!operand.body.statement-list;
if $stmts.IMPL-IS-SINGLE-EXPRESSION && $stmts.code-statements[0].expression.IMPL-CURRIED {
self.add-sorry:
$resolver.build-exception: 'X::Syntax::Malformed',
:what('double closure; WhateverCode is already a closure without curlies, so either remove the curlies or use valid parameter syntax instead of *')
}
}
}

method IMPL-EXPR-QAST(RakuAST::IMPL::QASTContext $context) {
my $postfix-ast := $!postfix.IMPL-POSTFIX-QAST($context, $!operand.IMPL-TO-QAST($context));
# Method calls may be to a foreign language, and thus return
Expand Down

0 comments on commit 331f019

Please sign in to comment.