Strange error when compiling with dmd, not with ldc
user1234
user1234 at 12.nl
Wed Nov 29 11:00:13 UTC 2017
On Wednesday, 29 November 2017 at 10:55:35 UTC, user1234 wrote:
> On Wednesday, 29 November 2017 at 06:18:09 UTC, Fra Mecca wrote:
>> [...]
>
> You must also use a type constructor later, when a
> Configuration is declared:
>
> ```
> immutable(Configuration) config;
> config.toString.writeln; // okay this time
> ```
>
> What happens is that all the member functions have the
> `immutable` attribute, but the instance you declared was not
> itself `immutable`.
>
> actually this:
>
> ```
> immutable struct Configuration {
> @property string toString(){return "";}
> }
> ```
>
> is like:
>
> ```
> struct Configuration {
> @property string toString() immutable {return "";}
> }
> ```
>
> I would personally prefer the second form. Why ? Because the
> variable members will be set immutable anyway when an instance
> is declared.
And about the DMD vs LDC thing, i thing that the difference can
be simply explained by the fact that LDC uses a slightly older
compiler front end version, meaning that after 1 or 2 updates,
the same error would happen.
Now i don't know which change in particular has been made
recently in the front-end. Maybe the semantic of the leading
qualifier when "immutable struct {}" is used but i would bet too
much on that.
More information about the Digitalmars-d-learn
mailing list