Bug 20539 – std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?)

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-01-27T18:25:43Z
Last change time
2021-01-19T15:00:49Z
Keywords
pull
Assigned to
No Owner
Creator
asumface

Comments

Comment #0 by asumface — 2020-01-27T18:25:43Z
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: /dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(1894): std.conv.toImpl!(css_colors, const(char)[]).toImpl(const(char)[] value) and: /dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2011): 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.
Comment #1 by bugzilla — 2020-01-27T20:41:28Z
(In reply to asumface from comment #0) > I believe both functions would handle this case correctly, not sure what > constraints opEquals touches to create this pathological case. opEquals is called by "is(typeof(value == OriginalType!T.init))" in the second overload.
Comment #2 by dlang-bot — 2020-01-28T09:05:11Z
@berni44 created dlang/phobos pull request #7378 "Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload" fixing this issue: - Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?) https://github.com/dlang/phobos/pull/7378
Comment #3 by dlang-bot — 2021-01-17T18:14:54Z
@berni44 created dlang/phobos pull request #7749 "Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?)" fixing this issue: - Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?) https://github.com/dlang/phobos/pull/7749
Comment #4 by dlang-bot — 2021-01-19T15:00:49Z
dlang/phobos pull request #7749 "Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?)" was merged into master: - ad72a3f7cd7970b6b98bbc56a929cfae0af7a68c by Bernhard Seckinger: Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?) https://github.com/dlang/phobos/pull/7749