Bug 22865 – __traits(compiles) affects inferrence of attributes
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-09T18:45:21Z
Last change time
2022-05-20T08:24:29Z
Keywords
pull, safe
Assigned to
No Owner
Creator
elpenguino+D
Comments
Comment #0 by elpenguino+D — 2022-03-09T18:45:21Z
```
@safe unittest {
foo();
}
auto foo() {
immutable(ubyte)[] data;
enum bar = __traits(compiles, cast(ubyte[])data);
}
```
Whether bar evaluates to true or false in this context I do not know. In either case, it shouldn't directly affect whether or not @safe is inferred.
The basic problem is that the function scope is used to evaluate the enum value while we are more in a static scope that can see static things in parent scopes.
There is no system for this in the D frontend now. We can only known if something static is evaluated (SCOPE.ctfe) or also if we are in a traits compile (SCOPE.compile).
That fix is consequently not good but it does not break the test suite.
There is something very conceptual about semantics on if the cast should be allowed or not in "particular contexts".
Comment #3 by dlang-bot — 2022-05-19T14:34:49Z
@dkorpel created dlang/dmd pull request #14144 "Fix issue 22865 - __traits(compiles) affects inferrence of attributes" fixing this issue:
- Fix issue 22865 - __traits(compiles) affects inferrence of attributes
https://github.com/dlang/dmd/pull/14144
Comment #4 by dlang-bot — 2022-05-20T08:24:29Z
dlang/dmd pull request #14144 "Fix issue 22865 - __traits(compiles) affects inferrence of attributes" was merged into master:
- 5314bf7194aff2dd4c08234472bfd0829db05e8c by Dennis Korpel:
Fix issue 22865 - __traits(compiles) affects inferrence of attributes
https://github.com/dlang/dmd/pull/14144