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.
Why should it show it on line 8 in stead of line 2? The assignment happens on line 2.
The compiler reports line 8, but the error is actually on line 2.
@BorisCarvajal created dlang/dmd pull request #11002 "Fix Issues 20718, 15867, 12380 - Wrong location errors on const. folding / exp. optimization" fixing this issue: - Fix Issues 20718, 15867, 12380 - Wrong location errors on const. folding / exp. optimization https://github.com/dlang/dmd/pull/11002
*** This issue has been marked as a duplicate of issue 12380 ***
dlang/dmd pull request #11002 "Fix Issues 20718, 15867, 12380 - Wrong location errors on const. folding / exp. optimization" was merged into stable: - e9227fc44fdd52e7217d0f72f6fec671f98555f5 by Boris Carvajal: Fix Issues 20718, 15867, 12380 - Wrong location errors on const. folding / exp. optimization https://github.com/dlang/dmd/pull/11002
dlang/dmd pull request #11102 "Revert "Fix Issues 20718, 15867, 12380 - Wrong location errors on const. folding / exp. optimization"" was merged into stable: - 7199de9b5d0a04bc415ac52d1490c66c92d14508 by Steven Schveighoffer: Revert "Fix Issues 20718, 15867, 12380 - Wrong location errors on const. folding / exp. optimization" https://github.com/dlang/dmd/pull/11102