[Issue 21680] New: inconsistent error on `typeof({ return field; }())`
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 4 11:34:01 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21680
Issue ID: 21680
Summary: inconsistent error on `typeof({ return field; }())`
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: accepts-invalid, rejects-valid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
Encountered while working on issue 20655.
Works:
----
struct Unique
{
int field;
alias ValueType = typeof({ return field; }());
}
----
Doesn't work (only change is in order of declarations):
----
struct Unique
{
alias ValueType = typeof({ return field; }()); /* Error: need `this` for
`field` of type `int` */
int field;
}
----
Works again (only change is in type of `field`):
----
struct Unique
{
alias ValueType = typeof({ return field; }());
int* field;
}
----
Either all should work, or all should fail with the same error.
I'm inclined to say that the error is correct. Razvan leans towards accepting
all snippets [1]. Depending on which stance we end up with, this is either an
accepts-invalid or a rejects-valid bug.
[1] https://github.com/dlang/dmd/pull/10884#issuecomment-790466796
--
More information about the Digitalmars-d-bugs
mailing list