Skip to content

Commit 7d855d0

Browse files
committed
- Improve error message when a keyword is used a block parameter. #3275
1 parent 8295112 commit 7d855d0

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Add json pretty print.
1010
- `$$atomic_store` and `$$atomic_load` takes an alignment parameter.
1111
- `$vaarg[^1]` is supported. #3276
12+
- Improve error message when a keyword is used a block parameter. #3275
1213

1314
### Stdlib changes
1415
- Add math::TAU / math::TWO_PI

src/compiler/parse_expr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ static Expr *parse_call_expr(ParseContext *c, Expr *left, SourceLoc *lhs_start)
10351035
{
10361036
if (!parse_next_may_be_type_or_ident(c))
10371037
{
1038+
if (token_is_keyword_ident(c->tok) && c->span.row == c->prev_span.row)
1039+
{
1040+
PRINT_ERROR_HERE("'%s' is a keyword, and can't be used as a parameter name.", symstr(c));
1041+
return poisoned_expr;
1042+
}
10381043
PRINT_ERROR_LAST("Expected an ending ')'. Did you forget a ')' before this ';'?");
10391044
return poisoned_expr;
10401045
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module test;
2+
import std;
3+
fn void main()
4+
{
5+
HashMap{String, String} my_map;
6+
my_map.@each(;module, migration) // #error: 'module' is a keyword, and can't be used
7+
{
8+
};
9+
}

0 commit comments

Comments
 (0)