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