D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15867 - Compiler reports wrong error location for immutability error
Summary: Compiler reports wrong error location for immutability error
Status: RESOLVED DUPLICATE of issue 12380
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2016-04-03 20:44 UTC by andy-hanson
Modified: 2020-05-06 16:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description andy-hanson 2016-04-03 20:44:02 UTC
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 Lass Safin 2016-04-03 20:49:20 UTC
Why should it show it on line 8 in stead of line 2? The assignment happens on line 2.
Comment 2 andy-hanson 2016-04-03 22:25:29 UTC
The compiler reports line 8, but the error is actually on line 2.
Comment 3 Dlang Bot 2020-04-03 12:12:40 UTC
@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 Steven Schveighoffer 2020-04-08 15:21:56 UTC

*** This issue has been marked as a duplicate of issue 12380 ***
Comment 5 Dlang Bot 2020-05-06 09:48:36 UTC
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 Dlang Bot 2020-05-06 16:08:53 UTC
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 Steven Schveighoffer 2020-05-06 16:10:47 UTC

*** This issue has been marked as a duplicate of issue 12380 ***