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

Improve error locations when lexing number literals #17500

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
14 changes: 7 additions & 7 deletions compiler/src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -2571,19 +2571,19 @@ class Lexer
Ldone:
if (errorDigit)
{
error(token.loc, "%s digit expected, not `%c`", base == 2 ? "binary".ptr :
error(scanloc, "%s digit expected, not `%c`", base == 2 ? "binary".ptr :
base == 8 ? "octal".ptr :
"decimal".ptr, errorDigit);
err = true;
}
if (overflow && !err)
{
error("integer overflow");
error(scanloc, "integer overflow");
err = true;
}
if ((base == 2 && !anyBinaryDigitsNoSingleUS) ||
(base == 16 && !anyHexDigitsNoSingleUS))
error(token.loc, "`%.*s` isn't a valid integer literal, use `%.*s0` instead", cast(int)(p - start), start, 2, start);
error(scanloc, "`%.*s` isn't a valid integer literal, use `%.*s0` instead", cast(int)(p - start), start, 2, start);

t.unsvalue = n;

Expand Down Expand Up @@ -2612,15 +2612,15 @@ class Lexer
goto L1;
case 'l':
f = FLAGS.long_;
error("lower case integer suffix 'l' is not allowed. Please use 'L' instead");
error(scanloc, "lower case integer suffix 'l' is not allowed. Please use 'L' instead");
goto L1;
case 'L':
f = FLAGS.long_;
L1:
p++;
if ((flags & f) && !err)
{
error("repeated integer suffix `%c`", p[-1]);
error(scanloc, "repeated integer suffix `%c`", p[-1]);
err = true;
}
flags = cast(FLAGS)(flags | f);
Expand All @@ -2634,9 +2634,9 @@ class Lexer
{
if (err)
// can't translate invalid octal value, just show a generic message
error("octal literals larger than 7 are no longer supported");
error(scanloc, "octal literals larger than 7 are no longer supported");
else
error(token.loc, "octal literals `0%llo%.*s` are no longer supported, use `std.conv.octal!\"%llo%.*s\"` instead",
error(scanloc, "octal literals `0%llo%.*s` are no longer supported, use `std.conv.octal!\"%llo%.*s\"` instead",
n, cast(int)(p - psuffix), psuffix, n, cast(int)(p - psuffix), psuffix);
}
TOK result;
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