Bug 21975 – is expression ignores implicit conversion of struct via alias this when pattern matching
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-25T17:47:13Z
Last change time
2022-03-01T15:09:37Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Comments
Comment #0 by snarwin+bugzilla — 2021-05-25T17:47:13Z
The following program fails to compile as of DMD 2.096.1:
---
struct Outer(T) {
Inner!T inner;
alias inner this;
}
struct Inner(T) {
T t;
}
static assert(is(Outer!int : Inner!int)); // ok
static assert(is(Outer!int : Inner!T, T)); // error
---
The error message is:
--
bug.d(11): Error: static assert: `is(Outer!int : Inner!T, __isexp_id2, T)` is false
---
The expected behavior is for both static assert statements to pass.
Surprisingly, changing Inner and Outer from structs to classes causes the second static assert statement to pass:
---
class Outer(T) {
Inner!T inner;
alias inner this;
}
class Inner(T) {
T t;
}
static assert(is(Outer!int : Inner!int)); // ok
static assert(is(Outer!int : Inner!T, T)); // ok
---
Comment #1 by dlang-bot — 2022-02-27T20:56:52Z
@pbackus created dlang/phobos pull request #8394 "sumtype: work around issue 21975 in isSumType" mentioning this issue:
- sumtype: work around issue 21975 in isSumType
isSumType!T now evaluates to true instead of false when T is a templated
struct type that implicitly converts to a SumType via alias this.
https://github.com/dlang/phobos/pull/8394
Comment #2 by dlang-bot — 2022-02-27T23:15:35Z
dlang/phobos pull request #8394 "sumtype: work around issue 21975 in isSumType" was merged into master:
- c47c861646ddbb8bd30be849aee37a6167ab41f3 by Paul Backus:
sumtype: work around issue 21975 in isSumType
isSumType!T now evaluates to true instead of false when T is a templated
struct type that implicitly converts to a SumType via alias this.
https://github.com/dlang/phobos/pull/8394
Comment #3 by dlang-bot — 2022-03-01T11:30:44Z
@RazvanN7 created dlang/dmd pull request #13738 "Fix Issue 21975 - is expression ignores implicit conversion of struct via alias this when pattern matching" fixing this issue:
- Fix Issue 21975 - is expression ignores implicit conversion of struct via alias this when pattern matching
https://github.com/dlang/dmd/pull/13738
Comment #4 by dlang-bot — 2022-03-01T12:55:48Z
dlang/dmd pull request #13738 "Fix Issue 21975 - is expression ignores implicit conversion of struct via alias this when pattern matching" was merged into master:
- 7e62db470b9e73bb6d9813e25295d9277f313131 by RazvanN7:
Fix Issue 21975 - is expression ignores implicit conversion of struct via alias this when pattern matching
https://github.com/dlang/dmd/pull/13738
Comment #5 by dlang-bot — 2022-03-01T15:09:37Z
dlang/phobos pull request #8397 "Revert "sumtype: work around issue 21975 in isSumType"" was merged into master:
- 7806947d9447f12062ac0976f9918bec79398449 by Paul Backus:
Revert "sumtype: work around issue 21975 in isSumType"
This reverts commit 2de68340ae2a057fd993af7bc2388325e68a9186.
https://github.com/dlang/phobos/pull/8397