Skip to content

Commit fde1bba

Browse files
authored
[spec/const3] Add example for immutable overriding other qualifiers (#3749)
1 parent ff3d6a9 commit fde1bba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spec/const3.dd

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,20 @@ $(P Applying a qualifier to a type that already has that qualifier is legal but
662662
has no effect, e.g. given an unqualified type `T`, $(D shared(const shared T))
663663
yields the type $(D const shared T).)
664664

665-
$(P Applying the `immutable` qualifier to any type (qualified or not) results in
665+
$(PANEL Applying the `immutable` qualifier to any type (qualified or not) results in
666666
$(D immutable T). Applying any qualifier to $(D immutable T) results in
667667
`immutable T`. This makes `immutable` a fixed point of qualifier combinations and
668-
makes types such as $(D const(immutable(shared T))) impossible to create.)
668+
makes types such as $(D const(immutable(shared T))) impossible to create.
669+
670+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
671+
---
672+
alias SInt = shared int;
673+
alias IInt = immutable int;
674+
static assert(is(immutable(SInt) == IInt));
675+
static assert(is(shared(IInt) == IInt));
676+
---
677+
)
678+
)
669679

670680
$(P Assuming `T` is an unqualified type, the graph below illustrates how
671681
qualifiers combine (combinations with `immutable` are omitted). For each node,

0 commit comments

Comments
 (0)