Comment #0 by andy.pj.hanson — 2016-04-03T20:44:02Z
Trying to compile this code:
class ThisIsWhereTheErrorIs {
Foo foo = Foo.instance;
}
immutable class Foo {
private this() {}
// This line of code is correct, but the compiler complains at this location!
static immutable Foo instance = new immutable Foo();
}
results in this error message:
src/app.d(8,34): Error: cannot implicitly convert expression (Foo()) of type immutable(Foo) to app.Foo
The error happens on line 2, not line 8. (Changing line 2 to `immutable Foo ...` fixes it.)
The error location is reported correctly if `Foo foo` is declared inside a function instead of in a class.
Comment #1 by lasssafin — 2016-04-03T20:49:20Z
Why should it show it on line 8 in stead of line 2? The assignment happens on line 2.
Comment #2 by andy.pj.hanson — 2016-04-03T22:25:29Z
The compiler reports line 8, but the error is actually on line 2.