mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
fix Bugzilla 24745 - improve associative array syntax error message
Signed-off-by: royalpinto007 <royalpinto007@gmail.com>
This commit is contained in:
parent
f5f7baeb19
commit
36c58b7368
2 changed files with 27 additions and 1 deletions
|
@ -6812,7 +6812,6 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
|
|||
{
|
||||
case TOK.identifier:
|
||||
{
|
||||
|
||||
if (commaExpected)
|
||||
error("comma expected separating field initializers");
|
||||
const t = peek(&token);
|
||||
|
@ -6846,6 +6845,20 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
|
|||
default:
|
||||
if (commaExpected)
|
||||
error("comma expected separating field initializers");
|
||||
const t = peek(&token);
|
||||
if (t.value == TOK.colon)
|
||||
{
|
||||
error("incorrect syntax for associative array, expected `[]`, found `{}`");
|
||||
while (token.value != TOK.rightCurly && token.value != TOK.endOfFile)
|
||||
{
|
||||
nextToken();
|
||||
}
|
||||
if (token.value == TOK.rightCurly)
|
||||
{
|
||||
nextToken();
|
||||
}
|
||||
break;
|
||||
}
|
||||
auto value = parseInitializer();
|
||||
_is.addInit(null, value);
|
||||
commaExpected = true;
|
||||
|
|
13
compiler/test/fail_compilation/test24745.d
Normal file
13
compiler/test/fail_compilation/test24745.d
Normal file
|
@ -0,0 +1,13 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=24745
|
||||
|
||||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/test24745.d(12): Error: incorrect syntax for associative array, expected `[]`, found `{}`
|
||||
---
|
||||
*/
|
||||
|
||||
void main()
|
||||
{
|
||||
int[int] f = {1: 1, 2: 2};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue