Bug 4501 – Can't call templated properties as properties from within class

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-07-24T09:48:00Z
Last change time
2012-05-30T19:08:57Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2010-07-24T09:48:24Z
class Foo { int _num; int num()() { return _num; } void doStuff() { int i = num; // Broken } } void main() { auto foo = new Foo; auto n = foo.num; // Works } Errors: test9.d(8): Error: template num() has no value test9.d(8): Error: cannot implicitly convert expression (num()) of type void to int If I comment out Foo.doStuff(), the line `auto n = bar.num;` works, apparently becuase it's not inside the class.
Comment #1 by stanislav.blinov — 2010-12-02T16:27:16Z
This seems related, though error manifests outside of class body: class Bar { @property T num(T = int)() const // Note default type { T result; //... return result; } } void main() { auto bar = new Bar; auto n1 = bar.num!int; // Ok auto n2 = bar.num; // Error: Bar.num(T = int) has no value auto n3 = bar.num!float; // Ok } I don't know if it's worth separate issue report.
Comment #2 by k.hara.pg — 2012-05-30T19:08:57Z
Works in 2.060head.