www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15867] New: Compiler reports wrong error location for

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 puremagic.com
          Reporter: andy.pj.hanson 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.

--
Apr 03 2016