D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21870 - Property/method not invoked and requires () when used in static array length
Summary: Property/method not invoked and requires () when used in static array length
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: diagnostic, pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2021-04-28 01:08 UTC by Vladimir Panteleev
Modified: 2021-04-29 00:46 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 Vladimir Panteleev 2021-04-28 01:08:37 UTC
////////////////////////////// test.d /////////////////////////////
struct S
{
    @property size_t count() const
    {
        return 1;
    }
}

int[S.init.count()] x; // OK
int[S.init.count  ] y; // error
// Error: need `this` for `count` of type `const @property ulong()`
///////////////////////////////////////////////////////////////////

Additionally, the error message is misleading. Older versions of compilers produced a better error:

2.079.0 to 2.087.1: Failure with output: test.d(9): Error: integer constant expression expected instead of `S().count`
Comment 1 Dlang Bot 2021-04-28 08:31:54 UTC
@TungstenHeart created dlang/dmd pull request #12481 "fix 21870 - Property/method not invoked and requires () when used in static array length" fixing this issue:

- fix 21870 - Property/method not invoked and requires () when used in static array length

https://github.com/dlang/dmd/pull/12481
Comment 2 Dlang Bot 2021-04-29 00:46:40 UTC
dlang/dmd pull request #12481 "fix 21870 - Property/method not invoked and requires () when used in static array length" was merged into master:

- 700a75c7179c1bc5fbbc89183961c3d8fd8e63a9 by Basile Burg:
  fix 21870, 15478 - Property/method not invoked and requires () when used in static array length

https://github.com/dlang/dmd/pull/12481