www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22609] New: [REG2.097]

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

          Issue ID: 22609
           Summary: [REG2.097]
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: johanengelen weka.io

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.

--
Dec 19 2021