[Issue 15168] New: std.variant.Algebraic interacts badly with string alias this sub-types

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Oct 6 00:00:27 PDT 2015


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

          Issue ID: 15168
           Summary: std.variant.Algebraic interacts badly with string
                    alias this sub-types
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: radu.racariu at gmail.com

When sub-typing a string via alias this, the Algebraic construct fails to
distinguish the sub-type from the string type.

Using the following:
--------------------------------------------
import std.variant    : Algebraic;

struct N { double val; alias val this; }
struct S { string val; alias val this; }
alias T = Algebraic!(S, N);

pragma(msg, T.AllowedTypes); 
--------------------------------------------
prints (N, string)

This happens in v2.068.2 win32

The expected behavior is to have S as a allowed type instead of string.

A workaround is to use std.typecons.Proxy in the S type. Like:

struct S
{
    /// the value
    string val;

    this(string s)
    {
        this.val = s;
    }

    import std.typecons : Proxy;
    mixin Proxy!val;
}

--


More information about the Digitalmars-d-bugs mailing list