[Issue 15867] New: Compiler reports wrong error location for immutability error

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Apr 3 13:44:02 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15867

          Issue ID: 15867
           Summary: Compiler reports wrong error location for immutability
                    error
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andy.pj.hanson at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list