Bug 21680 – inconsistent error on `typeof({ return field; }())`

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-03-04T11:34:01Z
Last change time
2021-03-05T02:04:05Z
Keywords
accepts-invalid, pull, rejects-valid
Assigned to
No Owner
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2021-03-04T11:34:01Z
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
Comment #1 by dlang-bot — 2021-03-04T17:06:31Z
@BorisCarvajal created dlang/dmd pull request #12251 "Fix Issue 21680 - inconsistent error on `typeof({ return field; }())`" fixing this issue: - Fix Issue 21680 - inconsistent error on `typeof({ return field; }())` https://github.com/dlang/dmd/pull/12251
Comment #2 by dlang-bot — 2021-03-05T02:04:05Z
dlang/dmd pull request #12251 "Fix Issue 21680 - inconsistent error on `typeof({ return field; }())`" was merged into master: - 4cb7a61d2f687114602be92a154f652ab64454f8 by Boris Carvajal: Fix Issue 21680 - inconsistent error on `typeof({ return field; }())` https://github.com/dlang/dmd/pull/12251