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
@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
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