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:
Paul Backus 2025-03-16 20:31:39 -04:00 committed by GitHub
parent 726c50e5bd
commit 7c95446800
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 1 deletions

View file

@ -1319,7 +1319,21 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
// Allow identifier, template instantiation, or function call
// 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)
{
const loc = token.loc;

View file

@ -0,0 +1,3 @@
enum UDA;
int fun() @UDA => 7;
static assert(fun() == 7);

View file

@ -0,0 +1,7 @@
/+
TEST_OUTPUT:
---
fail_compilation/uda_lambda.d(7): Error: declaration expected, not `=>`
---
+/
@a => 7 int b;