www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14457] New: Algebraic does not allow assignment from subset


          Issue ID: 14457
           Summary: Algebraic does not allow assignment from subset type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: justin economicmodeling.com

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))

Apr 17 2015