www.fgks.org   »   [go: up one dir, main page]

Issue 21680 - inconsistent error on `typeof({ return field; }())`
Summary: inconsistent error on `typeof({ return field; }())`
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2021-03-04 11:34 UTC by ag0aep6g
Modified: 2021-03-05 02:04 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2021-03-04 11:34:01 UTC
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 Dlang Bot 2021-03-04 17:06:31 UTC
@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 Dlang Bot 2021-03-05 02:04:05 UTC
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