www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20539] New: std.conv.to: internal overload conflict for enums


          Issue ID: 20539
           Summary: std.conv.to: internal overload conflict for enums with
                    base types that have a catch-all opEquals overload (?)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: asumface gmail.com

I've got my code reduced down to this with the help of dustmite:

import std.conv : to;

struct Vector()
    bool opEquals(U)(U)
        return true;

Vector!() read_color_string(const(char)[] input)
    enum css_colors
        red = Vector!()()

    return input.to!css_colors;

The error given is:

/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(222): Error: std.conv.toImpl
called with argument types (const(char)[]) matches both:
std.conv.toImpl!(css_colors, const(char)[]).toImpl(const(char)[] value)
std.conv.toImpl!(css_colors, const(char)[]).toImpl(const(char)[] value)
onlineapp.d(18): Error: template instance
std.conv.to!(css_colors).to!(const(char)[]) error instantiating

The message omits the constraints, the first overload's full signature is:

private T toImpl(T, S)(S value)
if (isInputRange!S && isSomeChar!(ElementEncodingType!S) &&
    !isExactSomeString!T && is(typeof(parse!T(value)))) 

and the second's:

private T toImpl(T, S)(S value)
if (is(T == enum) && !is(S == enum)
    && is(typeof(value == OriginalType!T.init))
    && !isFloatingPoint!(OriginalType!T) && !isSomeString!(OriginalType!T))

I believe both functions would handle this case correctly, not sure what
constraints opEquals touches to create this pathological case.

Jan 27