mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
Don't parse lambda as UDA without parentheses (#21009)
This brings the compiler's behavior in line with the language spec. Fixes dlang/dlang.org#4137
This commit is contained in:
parent
726c50e5bd
commit
7c95446800
3 changed files with 25 additions and 1 deletions
|
@ -1319,7 +1319,21 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
|
||||||
|
|
||||||
// Allow identifier, template instantiation, or function call
|
// Allow identifier, template instantiation, or function call
|
||||||
// for `@Argument` (single UDA) form.
|
// for `@Argument` (single UDA) form.
|
||||||
AST.Expression exp = parsePrimaryExp();
|
AST.Expression exp;
|
||||||
|
|
||||||
|
{
|
||||||
|
const loc = token.loc;
|
||||||
|
Identifier id = token.ident;
|
||||||
|
nextToken();
|
||||||
|
if (token.value == TOK.not)
|
||||||
|
{
|
||||||
|
auto tempinst = new AST.TemplateInstance(loc, id, parseTemplateArguments());
|
||||||
|
exp = new AST.ScopeExp(loc, tempinst);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
exp = new AST.IdentifierExp(loc, id);
|
||||||
|
}
|
||||||
|
|
||||||
if (token.value == TOK.leftParenthesis)
|
if (token.value == TOK.leftParenthesis)
|
||||||
{
|
{
|
||||||
const loc = token.loc;
|
const loc = token.loc;
|
||||||
|
|
3
compiler/test/compilable/uda_lambda.d
Normal file
3
compiler/test/compilable/uda_lambda.d
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
enum UDA;
|
||||||
|
int fun() @UDA => 7;
|
||||||
|
static assert(fun() == 7);
|
7
compiler/test/fail_compilation/uda_lambda.d
Normal file
7
compiler/test/fail_compilation/uda_lambda.d
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/+
|
||||||
|
TEST_OUTPUT:
|
||||||
|
---
|
||||||
|
fail_compilation/uda_lambda.d(7): Error: declaration expected, not `=>`
|
||||||
|
---
|
||||||
|
+/
|
||||||
|
@a => 7 int b;
|
Loading…
Add table
Add a link
Reference in a new issue