diff --git a/releasenotes.md b/releasenotes.md index f5977e273..fe6cbd767 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -19,6 +19,7 @@ - Allow compile time `$foreach` iteration over constant Strings and bytes. - Improved error message when accessing `@private` from other modules #1769. - Include `@name` when searching for possible matches to `name` in the error message. #1779 +- Improve `@param` parse errors #1777 ### Fixes - Fix case trying to initialize a `char[*]*` from a String. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 3aa139bbd..5f29f9dcd 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -2621,7 +2621,21 @@ static inline bool parse_contract_param(ParseContext *c, AstId *docs, AstId **do } else { - try_consume(c, TOKEN_STRING); + if (!try_consume(c, TOKEN_STRING)) + { + if (!tok_is(c, TOKEN_DOCS_EOL) && !tok_is(c, TOKEN_DOCS_END)) + { + if (tok_is(c, TOKEN_IDENT) || tok_is(c, TOKEN_TYPE_IDENT)) + { + PRINT_ERROR_HERE("A string containing the parameter description was expected, did you forget enclosing the description in \"\" or ``?"); + } + else + { + PRINT_ERROR_HERE("A string containing the description was expected after the parameter name."); + } + return false; + } + } } append_docs(docs_next, docs, ast); return true; diff --git a/test/test_suite/functions/param_doc_error.c3 b/test/test_suite/functions/param_doc_error.c3 new file mode 100644 index 000000000..3dd09dbb5 --- /dev/null +++ b/test/test_suite/functions/param_doc_error.c3 @@ -0,0 +1,13 @@ +<* +@param some 1 *> // #error: parameter name + +fn int foo(int some){ + return some + 1; +} + +<* +@param some stuff *> // #error: did you forget enclosing the description in + +fn int foo(int some){ + return some + 1; +} diff --git a/test/test_suite/lexing/expected_directive.c3 b/test/test_suite/lexing/expected_directive.c3 index 7a9d65515..46ef6465d 100644 --- a/test/test_suite/lexing/expected_directive.c3 +++ b/test/test_suite/lexing/expected_directive.c3 @@ -1,4 +1,4 @@ <* @hello -@param feij > 0 // #error: Expected end of line +@param feij > 0 // #error: A string containing the description *>