Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot partially destructure type qualifiers with == form of IsExpression #18917

Open
dlangBugzillaToGithub opened this issue Nov 22, 2014 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

Meta reported this on 2014-11-22T22:55:26Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=13767

CC List

Description

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()
{
}
@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2017-07-02T01:52:30Z

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()
{
}

@dlangBugzillaToGithub
Copy link
Author

monkeyworks12 commented on 2017-07-02T04:37:47Z

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.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2017-07-02T10:14:49Z

(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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant