Bug 15867 – Compiler reports wrong error location for immutability error

Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-03T20:44:02Z
Last change time
2020-05-06T16:10:47Z
Keywords
pull
Assigned to
No Owner
Creator
andy.pj.hanson

Comments

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.
Comment #3 by dlang-bot — 2020-04-03T12:12:40Z
@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
Comment #4 by schveiguy — 2020-04-08T15:21:56Z
*** This issue has been marked as a duplicate of issue 12380 ***
Comment #5 by dlang-bot — 2020-05-06T09:48:36Z
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
Comment #6 by dlang-bot — 2020-05-06T16:08:53Z
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
Comment #7 by schveiguy — 2020-05-06T16:10:47Z
*** This issue has been marked as a duplicate of issue 12380 ***