Bug 18545 – Casting away const with cast() triggers alias this, but returns the supertype anyway
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-03-01T16:52:58Z
Last change time
2019-03-29T13:41:38Z
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2018-03-01T16:52:58Z
const Nullable!string a;
Nullable!string b = a; /* This works. */
Nullable!string c = cast() a; /* This asserts in get. */
// Alright, so I guess cast() mistakenly follows the alias this?
// No!
static assert(is(typeof(cast() a) == Nullable!string));
// It follows the alias get this in Nullable, but it returns a Nullable anyway.
// Why!!
Comment #1 by default_357-line — 2018-08-21T06:10:36Z
It turns out what's happening here is that cast() constNullable is equivalent to Nullable(constNullable)... which implicitly casts to constNullable.get.
alias get this strikes again!
Nullable should maybe have a copy constructor from const?
Comment #2 by default_357-line — 2019-01-08T17:12:48Z