Issue 22609 - [REG2.097] std.format.format fails for opEquals overloads without int
Summary: [REG2.097] std.format.format fails for opEquals overloads without int
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: industry
Depends on:
Blocks:
 
Reported: 2021-12-19 16:03 UTC by johanengelen
Modified: 2022-01-08 12:12 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description johanengelen 2021-12-19 16:03:42 UTC
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 Dlang Bot 2021-12-19 22:49:54 UTC
@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 Dlang Bot 2021-12-20 00:36:44 UTC
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 Ate Eskola 2022-01-08 12:12:47 UTC
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.