Bug 23400 – [REG 2.099] Can't format enum value whose base type has non-const opEquals
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-10-09T03:25:09Z
Last change time
2022-10-17T09:20:57Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Comments
Comment #0 by snarwin+bugzilla — 2022-10-09T03:25:09Z
As of DMD 2.100.2, the following program fails to compile:
---
struct flagenum {
auto opEquals(typeof(this) a) {
return false;
}
}
enum foo { a = flagenum() }
void main() {
import std.format: formatValue, singleSpec;
import std.range: nullSink;
foo bar;
auto spec = singleSpec("%s");
auto sink = nullSink;
formatValue(sink, bar, spec);
}
---
The error message is:
---
/usr/include/dmd/phobos/std/format/internal/write.d(3024): Error: mutable method `bug.flagenum.opEquals` is not callable using a `const` object
bug.d(2): Consider adding `const` or `inout` here
/usr/include/dmd/phobos/std/format/write.d(1239): Error: template instance `std.format.internal.write.formatValueImpl!(NullSink, foo, char)` error instantiating
bug.d(16): instantiated from here: `formatValue!(NullSink, foo, char)`
---
According to run.dlang.io, this is a regression introduced in Phobos 2.099:
2.079.1 to 2.098.1: Success and no output
2.099.1: Failure with output:
-----
/path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/format/internal/write.d(2899): Error: mutable method `onlineapp.flagenum.opEquals` is not callable using a `const` object
onlineapp.d(2): Consider adding `const` or `inout` here
/path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/format/write.d(1239): Error: template instance `std.format.internal.write.formatValueImpl!(NullSink, foo, char)` error instantiating
onlineapp.d(16): instantiated from here: `formatValue!(NullSink, foo, char)`
-----
Comment #1 by snarwin+bugzilla — 2022-10-09T03:56:40Z
@pbackus updated dlang/phobos pull request #8591 "Fix issue 23400 - Can't format enum value whose base type has non-con…" fixing this issue:
- Fix issue 23400 - Can't format enum value whose base type has non-const opEquals
https://github.com/dlang/phobos/pull/8591
Comment #4 by dlang-bot — 2022-10-17T09:20:57Z
dlang/phobos pull request #8591 "Fix issue 23400 - Can't format enum value whose base type has non-con…" was merged into stable:
- 94fa37f2bf5aea48f83518ff58310a3b68c0a89a by Paul Backus:
Fix issue 23400 - Can't format enum value whose base type has non-const opEquals
https://github.com/dlang/phobos/pull/8591