Bug 11812 – Associative array .keys needs 'this' at compile time
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-24T11:49:03Z
Last change time
2018-11-05T11:36:21Z
Assigned to
No Owner
Creator
Dylan Knutson
Comments
Comment #0 by tcdknutson — 2013-12-24T11:49:03Z
DMD compiler 2.064, Windows 7 64 bit
```
enum myaa = ["foo": "bar"];
template MyTemplate(alias Arr)
{
enum MyTemplate = Arr.length;
}
void main()
{
// Fails
auto a = MyTemplate!(myaa.keys);
}
version(none):
void main()
{
// Works
enum keys = myaa.keys;
auto a = MyTemplate!keys;
}
```
Passing an AA's .keys to a template directly fails, but making `keys` a separate enum allows them to be passed.
Error:
aabug.d(5): Error: need 'this' for 'keys' of type 'pure nothrow @property @system string[]()'
aabug.d(10): Error: template instance aabug.MyTemplate!(keys) error instantiating
Comment #1 by razvan.nitu1305 — 2018-11-05T11:36:21Z
This code compiles successfully in git HEAD (2.081). Closing as fixed.