Bug 14457 – Algebraic does not allow assignment from subset type

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-17T18:44:00Z
Last change time
2017-07-19T17:43:06Z
Keywords
pull
Assigned to
nobody
Creator
justin

Comments

Comment #0 by justin — 2015-04-17T18:44:51Z
The following code produces a compilation error, despite the type B allowing a strict subset of A's type. I would expect this assignment to copy over the type and storage from `b`, leaving `a` as a `double` equal to `6.0`. ----- import std.variant; void main(string[] args) { alias A = Algebraic!(int, float, double); A a = 1; alias B = Algebraic!(int, double); B b = 6.0; a = b; } ----- src/phobos/std/variant.d(605): Error: static assert "Cannot store a VariantN!(8LU, int, double) in a VariantN!(8LU, int, float, double). Valid types are (int, float, double)" test_algebraic.d(11): instantiated from here: opAssign!(VariantN!(8LU, int, double))
Comment #1 by github-bugzilla — 2015-04-26T05:21:43Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/5a9c0bcd6bb60b32eca098fbbaf46746a0cbcfb4 Fixes 14457 (VariantN opAssign subset variant) Allows a VariantN to be assigned from another VariantN that is a strict subset. Implements an opAssign overload that specializes on VariantN instantations that are not the current VariantN but whose AllowedTypes are a subset of the current variant's. Added accompanying unittest. Fix Issue 14457
Comment #2 by github-bugzilla — 2017-07-19T17:43:06Z
Commit pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/5a9c0bcd6bb60b32eca098fbbaf46746a0cbcfb4 Fixes 14457 (VariantN opAssign subset variant)