Skip to content

Commit

Permalink
Improve @param parse errors #1777
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jan 5, 2025
1 parent c47cb51 commit f1ef2e8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 15 additions & 1 deletion src/compiler/parse_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/test_suite/functions/param_doc_error.c3
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion test/test_suite/lexing/expected_directive.c3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<*
@hello
@param feij > 0 // #error: Expected end of line
@param feij > 0 // #error: A string containing the description
*>

0 comments on commit f1ef2e8

Please sign in to comment.