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

Lambda as UDA is valid but spec requires brackets #4137

Closed
dlangBugzillaToGithub opened this issue Jan 20, 2024 · 3 comments · Fixed by dlang/dmd#21009
Closed

Lambda as UDA is valid but spec requires brackets #4137

dlangBugzillaToGithub opened this issue Jan 20, 2024 · 3 comments · Fixed by dlang/dmd#21009

Comments

@dlangBugzillaToGithub
Copy link

Richard (Rikki) Andrew Cattermole reported this on 2024-01-20T01:25:08Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24346

CC List

Description

From: https://forum.dlang.org/post/[email protected]

The lambda here is valid, even though it is not in a brackets.

```d
@a=>7 int b;
pragma(msg, __traits(getAttributes, b)); // AliasSeq!((a) => 7)
```

Should only be supported (according to specification):

```d
@(a=>7) int b;
pragma(msg, __traits(getAttributes, b)); // AliasSeq!((a) => 7)
```

Clarification or a compiler bug fix is needed.
@dlangBugzillaToGithub
Copy link
Author

hsteoh commented on 2024-01-20T01:34:51Z

I'm inclined to say that parentheses should be required, for consistency with the single-token requirement on unparenthesized UDAs. (Cf also binary `!` syntax, where the unparenthesized version also requires exactly 1 token, and in all other cases parentheses are required.)

@pbackus
Copy link
Contributor

pbackus commented Mar 15, 2025

Allowing this breaks shortened function bodies:

struct UDA {}

int foo() @UDA => 123;

void main()
{
    assert(foo() == 123);
    // error: undefined reference to '_D9onlineapp3fooFZi'
}

In the above code, => 123 should be parsed as the function body of foo, but it is instead parsed as part of the attribute @(UDA => 123).

@zero-vector
Copy link

From the linked forum discussion (https://forum.dlang.org/post/[email protected])

Generally we consider the implementation to win on differences between the compiler and specification for issues such as this.
Given that it does not appear to be harmful, no need to change the compiler :)

But IMHO the implementation is harmful, it prevents use of Shortened Function Declarations. And so the severity of the bug should be bumped, to get some attention.

It should be decided if it is a spec bug, or parser bug and handled accordingly.

pbackus added a commit to pbackus/dmd that referenced this issue Mar 16, 2025
This brings the compiler's behavior in line with the language spec.

Fixes dlang/dlang.org#4137
pbackus added a commit to pbackus/dmd that referenced this issue Mar 16, 2025
This brings the compiler's behavior in line with the language spec.

Fixes dlang/dlang.org#4137
thewilsonator pushed a commit to dlang/dmd that referenced this issue Mar 17, 2025
This brings the compiler's behavior in line with the language spec.

Fixes dlang/dlang.org#4137
adamdruppe pushed a commit to opendlang/opend that referenced this issue Mar 17, 2025
This brings the compiler's behavior in line with the language spec.

Fixes dlang/dlang.org#4137
kinke pushed a commit to ldc-developers/ldc that referenced this issue Mar 17, 2025
This brings the compiler's behavior in line with the language spec.

Fixes dlang/dlang.org#4137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants