[Issue 14457] New: Algebraic does not allow assignment from subset type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 17 11:44:51 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14457

          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 at puremagic.com
          Reporter: justin at 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))

--


More information about the Digitalmars-d-bugs mailing list