[Issue 20670] immutable template specialization pattern matches immutable struct, strips immutable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 14 16:09:22 UTC 2022


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

--- Comment #10 from Paul Backus <snarwin+bugzilla at gmail.com> ---
> But `immutable struct` is not actually a qualifier, it's an
> "immutable declaration." This is currently, apparently, implemented as
> an implicit qualifier, which is what this bug is about, and at any rate
> is not what the spec says.

Here's the relevant part of the spec:

https://dlang.org/spec/attribute.html#immutable

It says immutable works "the same was as const does", so let's look at the
section on const:

> The const attribute changes the type of the declared symbol from T to
> const(T), where T is the type specified (or inferred) for the introduced
> symbol in the absence of const.

https://dlang.org/spec/attribute.html#const

This paragraph implicitly assumes that the declared symbol has a type. But in
the case of `immutable struct S`, S does not *have* a type, it *is* a type. So
the spec does not give us a clear answer one way or the other to the question
of what `immutable struct S` ought to mean.

--


More information about the Digitalmars-d-bugs mailing list