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

allow cast of type, not only expressions #19596

Open
dlangBugzillaToGithub opened this issue Jun 29, 2019 · 1 comment
Open

allow cast of type, not only expressions #19596

dlangBugzillaToGithub opened this issue Jun 29, 2019 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

basile-z reported this on 2019-06-29T10:14:30Z

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

CC List

  • Bolpat

Description

People write stuff like : 

    mixin("alias Func = " ~ typeof(&impl).stringof ~ " pure nothrow;");

to set the attributes of a function. We could have something like

    alias Func = cast(pure nothrow) typeof(&impl);

or even using the TypeCtor style

    alias Func = pure(nothrow(typeof(&impl)));

This probably requires a DIP but I open an issue to keep track of the idea.
@dlangBugzillaToGithub
Copy link
Author

qs.il.paperinik commented on 2024-06-05T13:16:27Z

I’d be in favor of the cast.

Grammar:
```diff
    CastQual:
-       cast ( TypeCtors? ) UnaryExpression
+       cast ( MemberFunctionAttributes? ) UnaryExpression
+       cast ( ... MemberFunctionAttributes ) UnaryExpression
+       cast ( ! ...[opt] MemberFunctionAttributes ) UnaryExpression
```

Note that `MemberFunctionAttributes` includes `TypeCtors`.

Semantics of `cast()` must remain so that it only removes `TypeCtor`s. To remove other things, either use e.g. `cast(@system)` or fix https://issues.dlang.org/show_bug.cgi?id=24587.

One issue I see, however, is with delegate types: `cast(immutable)` would produce `immutable(R delegate())` and there’s no way to go from `R delegate()` to `R delegate() immutable` with a cast. This is what the second rule does: It applies the member function attribute to the function type even if it’s a type qualifier.

`cast(pure)` is unambiguous, so it doesn’t require `cast(... pure)`, but `cast(... pure)` should be legal. The `...` essentially becomes `typeof(UnaryExpression)`.

As for Issue 24587 (negated forms), that’s the last rule: `cast(! ... const)` removes `const` as a member function attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant