From 124efb26848ecd6f3eb7f7e39cd389a682680fe6 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 6 Feb 2026 02:00:26 +0100 Subject: [PATCH] Improve error message on `const int*` --- src/compiler/parse_global.c | 6 ++++++ test/test_suite/functions/const_param.c3 | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 test/test_suite/functions/const_param.c3 diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 6c5e0daca..c141d6edd 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -1832,6 +1832,12 @@ CHECK_ELLIPSIS: span = c->prev_span; param_kind = VARDECL_PARAM; break; + case TOKEN_CONST: + if (token_is_any_type(peek(c))) + { + RETURN_PRINT_ERROR_HERE("'const' is not allowed here, did you try to make a C style const parameter? In that case, consider using contracts with '@param [in]' for the parameter."); + } + FALLTHROUGH; default: if (token_is_keyword(c->tok)) { diff --git a/test/test_suite/functions/const_param.c3 b/test/test_suite/functions/const_param.c3 new file mode 100644 index 000000000..52d5fefd5 --- /dev/null +++ b/test/test_suite/functions/const_param.c3 @@ -0,0 +1,3 @@ +import std; +fn int bar(const int* baz) // #error: 'const' is not allowed here, did you try to make a C style const parameter? +{} \ No newline at end of file