mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
Improve error message for 'out' on foreach
This hopefully will provide a slightly better user experience, as many other storage classes are accepted. Before, the following error message was printed by DMD: ``` test/fail_compilation/foreach.d(12): Error: basic type expected, not `out` test/fail_compilation/foreach.d(12): Error: no identifier for declarator `_error_` test/fail_compilation/foreach.d(12): Error: found `out` when expecting `;` test/fail_compilation/foreach.d(12): Error: found `;` when expecting `)` test/fail_compilation/foreach.d(12): Error: found `)` when expecting `;` following statement test/fail_compilation/foreach.d(13): Error: basic type expected, not `out` test/fail_compilation/foreach.d(13): Error: no identifier for declarator `_error_` test/fail_compilation/foreach.d(13): Error: found `out` when expecting `;` test/fail_compilation/foreach.d(13): Error: expression expected, not `out` test/fail_compilation/foreach.d(13): Error: found `val` when expecting `)` test/fail_compilation/foreach.d(13): Error: use `{ }` for an empty statement, not `;` test/fail_compilation/foreach.d(13): Error: found `)` when expecting `;` following statement ```
This commit is contained in:
parent
96569c9a95
commit
0befa1bc6a
2 changed files with 19 additions and 0 deletions
|
@ -5411,6 +5411,11 @@ class Parser(AST) : Lexer
|
||||||
stc = STC.scope_;
|
stc = STC.scope_;
|
||||||
goto Lagain;
|
goto Lagain;
|
||||||
|
|
||||||
|
case TOK.out_:
|
||||||
|
error("cannot declare `out` loop variable, use `ref` instead");
|
||||||
|
stc = STC.out_;
|
||||||
|
goto Lagain;
|
||||||
|
|
||||||
case TOK.enum_:
|
case TOK.enum_:
|
||||||
stc = STC.manifest;
|
stc = STC.manifest;
|
||||||
goto Lagain;
|
goto Lagain;
|
||||||
|
|
14
test/fail_compilation/foreach.d
Normal file
14
test/fail_compilation/foreach.d
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
TEST_OUTPUT:
|
||||||
|
---
|
||||||
|
fail_compilation/foreach.d(12): Error: cannot declare `out` loop variable, use `ref` instead
|
||||||
|
fail_compilation/foreach.d(13): Error: cannot declare `out` loop variable, use `ref` instead
|
||||||
|
fail_compilation/foreach.d(13): Error: cannot declare `out` loop variable, use `ref` instead
|
||||||
|
---
|
||||||
|
*/
|
||||||
|
void main ()
|
||||||
|
{
|
||||||
|
int[] array;
|
||||||
|
foreach (out val; array) {}
|
||||||
|
foreach (out idx, out val; array) {}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue