Bug 8413 – function breaks compilation of property function

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-22T14:56:00Z
Last change time
2013-09-17T14:48:30Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-07-22T14:56:18Z
struct Foo { int[] arr; @property int front(string file = __FILE__, size_t line = __LINE__)() { enforce(arr.length, format("%s(%s): Cannot call back on empty array.", file, line)); return arr.front; } } void main() { Foo foo; auto x = foo.front; } test.d(28): Error: cannot resolve type for foo.front(string file = __FILE__,uint line = __LINE__) If you remove enforce it compiles with no problems.
Comment #1 by andrej.mitrovich — 2012-07-22T14:59:23Z
Actually it has nothing to do with enforce, same error: void test(bool) { } struct Foo { int[] arr; @property int front(string file = __FILE__, size_t line = __LINE__)() { test(arr.length); return arr.front; } }
Comment #2 by issues.dlang — 2012-07-22T15:04:10Z
The error is correct. The fact that you gave front's parameters default arguments has _zero_ affect on its type, and its the type that determines whether the function can be @property or not.
Comment #3 by issues.dlang — 2012-07-22T15:05:09Z
Oh wait. I read that wrong. I thought that you were passing them as function arguments.
Comment #4 by issues.dlang — 2012-07-22T15:11:47Z
For this to make sense return arr.front!("hello", 12) would have to make sense for a property, and I don't know if that makes sense or not. Probably not, since you couldn't do that if front were a public variable.
Comment #5 by andrej.mitrovich — 2013-09-17T14:48:30Z
Works in 2.063.2.