D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21975 - is expression ignores implicit conversion of struct via alias this when pattern matching
Summary: is expression ignores implicit conversion of struct via alias this when patte...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-05-25 17:47 UTC by Paul Backus
Modified: 2022-03-01 15:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2021-05-25 17:47:13 UTC
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 Dlang Bot 2022-02-27 20:56:52 UTC
@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 Dlang Bot 2022-02-27 23:15:35 UTC
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 Dlang Bot 2022-03-01 11:30:44 UTC
@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 Dlang Bot 2022-03-01 12:55:48 UTC
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 Dlang Bot 2022-03-01 15:09:37 UTC
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