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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 14 18:46:04 UTC 2022


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

--- Comment #14 from Paul Backus <snarwin+bugzilla at gmail.com> ---
> But - wasn't the thing we actually wanted just to enforce that all fields
> were only set through the constructor?

If that's all you want, then the current behavior of `immutable struct` should
be sufficient--because, as I pointed out in comment 3, stripping immutable from
the type does not strip it from the members. In fact, even the behavior Dennis
proposes in comment 4 would be sufficient.

However, going by the original bug report, it seems like in addition to this
you *also* want to be able to distinguish between `immutable struct S` and
`struct S { immutable: }` in template specializations. And in order to do this,
you would like a new special case to be introduced to the type system.

Am I missing anything?

--


More information about the Digitalmars-d-bugs mailing list