D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13767 - Cannot partially destructure type qualifiers with == form of IsExpression
Summary: Cannot partially destructure type qualifiers with == form of IsExpression
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2014-11-22 22:55 UTC by Meta
Modified: 2024-12-13 18:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Meta 2014-11-22 22:55:26 UTC
The following code fails to print anything, although I believe it should be valid and should print `const(int)`.

shared const int i;

static if (is(typeof(i) == shared U, U))
{
    pragma(msg, U);
}

void main()
{
}
Comment 1 Vladimir Panteleev 2017-07-02 01:52:30 UTC
No, because you use ==, which does exact matching. If you want to partially match the type (i.e. check if it's implicitly convertible to shared), use `:`, not `==`:

shared const int i;

static if (is(typeof(i) == shared U, U))
{
    pragma(msg, U); // now prints const(int)
}

void main()
{
}
Comment 2 Meta 2017-07-02 04:37:47 UTC
I'm assuming in your example you meant to use : instead of ==.

That aside, why shouldn't this work? I'm trying to destructure some type which matches the pattern `shared U`. `shared const(int)` *should* match that pattern. What I'm trying to express is `∃ U: shared U == shared const int`; it seems incorrect to me that that I should have to use the subtyping form of is.
Comment 3 Vladimir Panteleev 2017-07-02 10:14:49 UTC
(In reply to monkeyworks12 from comment #2)
> I'm assuming in your example you meant to use : instead of ==.

Oops, yes.

> That aside, why shouldn't this work? I'm trying to destructure some type
> which matches the pattern `shared U`. `shared const(int)` *should* match
> that pattern. What I'm trying to express is `∃ U: shared U == shared const
> int`; it seems incorrect to me that that I should have to use the subtyping
> form of is.

OK, I see what you mean now. It looks like partial destructuring of type qualifiers was never implemented for == variants of IsExpression. It is the same for inout:

static assert(!is(shared const int == shared U, U)); // should work
static assert( is(shared const int :  shared U, U));
static assert(!is(inout  const int == const  U, U)); // should work
static assert( is(inout  const int :  const  U, U));
Comment 4 dlangBugzillaToGithub 2024-12-13 18:36:21 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18917

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB