Bug 17353 – is expression type specialization matching strips const
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-04-26T13:02:18Z
Last change time
2018-02-19T09:13:42Z
Assigned to
No Owner
Creator
David Eckardt
Comments
Comment #0 by david.eckardt — 2017-04-26T13:02:18Z
const(T[]) matches an is-expression which it shouldn't match:
---
alias const(int[]) T;
static if (is(T U == U[]))
static assert(is(T == U[])); // fails
---
The "static if" and "static assert" conditions should be equivalent so the "static assert" should never fail. Instead the "static if" behaves as if the is-expression would contain Unqual!T instead of T.
Comment #1 by uplink.coder — 2018-02-19T09:13:42Z
The static if and the static assert are indeed not equivalent
since type-system wise const(int[]) is a constant array of mutable ints.
The pattern-matching is expression set u to the element type of const(int[]) which is const(int).
If you then create the slice type of U you get const(int)[]
which is different from const (int[]).
So there is no discrepancy.
I agree it can be annoying though.