Disallow ! in module function calls.

This commit is contained in:
Stephen Chung 2020-10-12 16:59:59 +08:00
parent e343bcfa8f
commit c4f00afbee
2 changed files with 17 additions and 1 deletions

View File

@ -43,6 +43,12 @@ let f = Fn("foo");
call!(f, 41) == 42; // must use function-call style call!(f, 41) == 42; // must use function-call style
f.call!(41); // <- syntax error: capturing is not allowed in method-call style f.call!(41); // <- syntax error: capturing is not allowed in method-call style
// Capturing is not available for module functions
import "hello" as h;
h::greet!(); // <- syntax error: capturing is not allowed in namespace-qualified calls
``` ```

View File

@ -1949,7 +1949,17 @@ fn parse_primary(
settings.pos = token_pos; settings.pos = token_pos;
root_expr = match (root_expr, token) { root_expr = match (root_expr, token) {
// Function call // Qualified function call with !
#[cfg(not(feature = "no_closure"))]
(Expr::Variable(x), Token::Bang) if x.1.is_some() => {
return Err(if !match_token(input, Token::LeftParen)? {
LexError::UnexpectedInput(Token::Bang.syntax().to_string()).into_err(token_pos)
} else {
PERR::BadInput("'!' cannot be used to call module functions".to_string())
.into_err(token_pos)
});
}
// Function call with !
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
(Expr::Variable(x), Token::Bang) => { (Expr::Variable(x), Token::Bang) => {
if !match_token(input, Token::LeftParen)? { if !match_token(input, Token::LeftParen)? {