immutable class Foo
{
void bar()
{
}
}
void main()
{
auto x = new Foo();
x.bar();
// Error: function test.Foo.bar () immutable is not callable
// using argument types ()
}
What do I have to change in the program so that x.bar() compiles? Does x have the wrong type?
Looks like a bug.
xis inferred to have the typeFoo, which although is an immutable class, it is treated as if a mutable variable, which causedx.bar()to fail becausebar()is an immutable method.A workaround is to provide an empty immutable constructor function,
which caused the
new Foo()expression to return animmutable(Foo).