diff --git a/doc/src/language/fn-capture.md b/doc/src/language/fn-capture.md index 58ce811a..e35de979 100644 --- a/doc/src/language/fn-capture.md +++ b/doc/src/language/fn-capture.md @@ -43,6 +43,12 @@ let f = Fn("foo"); call!(f, 41) == 42; // must use function-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 ``` diff --git a/src/parser.rs b/src/parser.rs index 4e932fe9..12f8660a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1949,7 +1949,17 @@ fn parse_primary( settings.pos = token_pos; 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"))] (Expr::Variable(x), Token::Bang) => { if !match_token(input, Token::LeftParen)? {