Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lexer error locations more accurate #17500

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@
Ldone:
if (errorDigit)
{
error(token.loc, "%s digit expected, not `%c`", base == 2 ? "binary".ptr :
error("%s digit expected, not `%c`", base == 2 ? "binary".ptr :

Check warning on line 2574 in compiler/src/dmd/lexer.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/lexer.d#L2574

Added line #L2574 was not covered by tests
base == 8 ? "octal".ptr :
"decimal".ptr, errorDigit);
err = true;
Expand Down Expand Up @@ -3162,7 +3162,7 @@

void error(T...)(const(char)* format, T args)
{
eSink.error(token.loc, format, args);
eSink.error(scanloc, format, args);
}

void error(T...)(const ref Loc loc, const(char)* format, T args)
Expand All @@ -3172,7 +3172,7 @@

void errorSupplemental(T...)(const(char)* format, T args)
{
eSink.errorSupplemental(token.loc, format, args);
eSink.errorSupplemental(scanloc, format, args);
}

void deprecation(T...)(const ref Loc loc, const(char)* format, T args)
Expand All @@ -3187,12 +3187,12 @@

void deprecation(T...)(const(char)* format, T args)
{
eSink.deprecation(token.loc, format, args);
eSink.deprecation(scanloc, format, args);
}

void deprecationSupplemental(T...)(const(char)* format, T args)
{
eSink.deprecationSupplemental(token.loc, format, args);
eSink.deprecationSupplemental(scanloc, format, args);
}

/***************************************
Expand Down
19 changes: 12 additions & 7 deletions compiler/test/fail_compilation/lexer23465.d
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/*
TEST_OUTPUT:
---
fail_compilation/lexer23465.d(19): Error: character 0x1f37a is not allowed as a continue character in an identifier
fail_compilation/lexer23465.d(19): Error: character 0x1f37a is not a valid token
fail_compilation/lexer23465.d(20): Error: character '\' is not a valid token
fail_compilation/lexer23465.d(21): Error: unterminated /+ +/ comment
fail_compilation/lexer23465.d(22): Error: found `End of File` instead of array initializer
fail_compilation/lexer23465.d(22): Error: semicolon needed to end declaration of `arr`, instead of `End of File`
fail_compilation/lexer23465.d(17): `arr` declared here
fail_compilation/lexer23465.d(22): Error: character 0x1f37a is not allowed as a continue character in an identifier
fail_compilation/lexer23465.d(22): Error: character 0x1f37a is not a valid token
fail_compilation/lexer23465.d(23): Error: character '\' is not a valid token
fail_compilation/lexer23465.d(24): Error: octal digit expected, not `9`
fail_compilation/lexer23465.d(24): Error: octal literals larger than 7 are no longer supported
fail_compilation/lexer23465.d(25): Error: integer overflow
fail_compilation/lexer23465.d(26): Error: unterminated /+ +/ comment
fail_compilation/lexer23465.d(27): Error: found `End of File` instead of array initializer
fail_compilation/lexer23465.d(27): Error: semicolon needed to end declaration of `arr`, instead of `End of File`
fail_compilation/lexer23465.d(20): `arr` declared here
---
*/

Expand All @@ -18,4 +21,6 @@ int[] arr = [
0,
x🍺,
3\,
09,
9999999999999999999999,
5, /+
Loading