Bug 22609 – [REG2.097] std.format.format fails for opEquals overloads without int

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-19T16:03:42Z
Last change time
2022-01-08T12:12:47Z
Keywords
industry
Assigned to
No Owner
Creator
johanengelen

Comments

Comment #0 by johanengelen — 2021-12-19T16:03:42Z
Testcase: ``` enum State: ubyte { INACTIVE, } static struct S { State state = State.INACTIVE; int generation = 1; alias state this; // DMDBUG: https://issues.dlang.org/show_bug.cgi?id=16657 auto opEquals(S other) const { return state == other.state && generation == other.generation; } auto opEquals(State other) const { return state == other; } } void main() { S a; import std.format; auto str = format("%s", a); } ``` Since 2.097, compilation errors with: ``` std/format/internal/write.d(248): Error: none of the overloads of `opEquals` are callable using argument types `(int)`, candidates are: <source>(9): `example.S.opEquals(S other)` <source>(10): `example.S.opEquals(State other)` std/format/internal/write.d(253): Error: none of the overloads of `opEquals` are callable using argument types `(int)`, candidates are: <source>(9): `example.S.opEquals(S other)` <source>(10): `example.S.opEquals(State other)` std/format/write.d(1239): Error: template instance `std.format.internal.write.formatValueImpl!(Appender!string, S, char)` error instantiating std/format/write.d(632): instantiated from here: `formatValue!(Appender!string, S, char)` std/format/package.d(779): instantiated from here: `formattedWrite!(Appender!string, char, S)` <source>(17): instantiated from here: `format!(char, S)` ASM generation compiler returned: 1 std/format/internal/write.d(248): Error: none of the overloads of `opEquals` are callable using argument types `(int)`, candidates are: <source>(9): `example.S.opEquals(S other)` <source>(10): `example.S.opEquals(State other)` std/format/internal/write.d(253): Error: none of the overloads of `opEquals` are callable using argument types `(int)`, candidates are: <source>(9): `example.S.opEquals(S other)` <source>(10): `example.S.opEquals(State other)` std/format/write.d(1239): Error: template instance `std.format.internal.write.formatValueImpl!(Appender!string, S, char)` error instantiating /opt/compiler-explorer/ldc1.27.1/ldc2-1.27.1-linux-x86_64/bin/../import/std/format/write.d(632): instantiated from here: `formatValue!(Appender!string, S, char)` /opt/compiler-explorer/ldc1.27.1/ldc2-1.27.1-linux-x86_64/bin/../import/std/format/package.d(779): instantiated from here: `formattedWrite!(Appender!string, char, S)` <source>(17): instantiated from here: `format!(char, S)` ``` This appears to be fixed by https://github.com/dlang/phobos/pull/8278, which replaces the `obj != 0` comparison with a zero comparison after casting to `ulong` first.
Comment #1 by dlang-bot — 2021-12-19T22:49:54Z
@nordlow created dlang/phobos pull request #8339 "Add unittest for issue 22609" mentioning this issue: - Add unittest for issue 22609 https://github.com/dlang/phobos/pull/8339
Comment #2 by dlang-bot — 2021-12-20T00:36:44Z
dlang/phobos pull request #8339 "Add unittest for issue 22609" was merged into master: - fa882c0e039eb3972aef46e19cbde8cb5fc7a702 by Per Nordlöw: Add unittest for issue 22609 https://github.com/dlang/phobos/pull/8339
Comment #3 by Ajieskola — 2022-01-08T12:12:47Z
Confirmed to work on latest master. @RazvanN credit for fixing this goes to Per Norlöw. If the scores for the first round of the bugfix campaing are still around somewhere, Per should receive +100 posthumously.