Bug 20138 – is expression not evaluating correctly?

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-18T08:26:10Z
Last change time
2019-08-31T19:55:06Z
Keywords
pull
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2019-08-18T08:26:10Z
Check this out: alias X = shared inout int; pragma(msg, X, " ", is(X == shared U, U)); > shared(inout(int)) false I feel like that should print `true`, and U should be `inout(int)`...? This works: alias X = shared int; pragma(msg, X, " ", is(X == shared U, U)); > shared(int) true What's going on here?
Comment #1 by turkeyman — 2019-08-18T08:29:32Z
alias X = shared int; pragma(msg, X, " ", is(X == shared U, U), " ", U)); > shared(int) true int alias X = shared inout int; pragma(msg, X, " ", is(X == shared U, U), " ", U)); > shared(inout(int)) false Error: undefined identifier `U`
Comment #2 by dlang-bot — 2019-08-18T18:32:31Z
@aG0aep6G created dlang/dmd pull request #10317 "fix issue 20138 - is expression not evaluating correctly?" fixing this issue: - fix issue 20138 - is expression not evaluating correctly? When passing a `shared const T` into a `shared U` parameter, then no const conversion is needed to infer `U` as `const int`. Same with `inout int` and `inout const int`. https://github.com/dlang/dmd/pull/10317
Comment #3 by dlang-bot — 2019-08-18T21:28:51Z
@aG0aep6G created dlang/phobos pull request #7147 "prepare for fix of issue 20138 ("is expression not evaluating correct…" mentioning this issue: - prepare for fix of issue 20138 ("is expression not evaluating correctly?") With issue 20138 fixed, `const U` and `shared U` do match `const shared T`, and they leave the other qualifier intact. So `const shared U` must be attempted first if we want to strip both qualifiers. https://github.com/dlang/phobos/pull/7147
Comment #4 by turkeyman — 2019-08-18T21:32:00Z
Is this another construction of the same issue, or is it a similar but unrelated issue? T fun(T)(shared(T) a) { return a; } shared const int[] x; pragma(msg, typeof(fun(x))); > const(shared(int)[]) !!! `T` should be typeof(x) but with shared peeled away: const(int[])
Comment #5 by turkeyman — 2019-08-18T21:36:16Z
In my example above, it's weird that `shared` surrounds `int`, but `const` surrounds `int[]`... why are they applied at different levels?
Comment #6 by ag0aep6g — 2019-08-18T21:54:54Z
(In reply to Manu from comment #4) > T fun(T)(shared(T) a) > { > return a; > } > shared const int[] x; > pragma(msg, typeof(fun(x))); > > > const(shared(int)[]) !!! > > `T` should be typeof(x) but with shared peeled away: const(int[]) It is typeof(x) but with shared peeled away (from the head of the type). typeof(x) is: shared(const(E[])) where E is shared(const(int)). Peel shared away from typeof(x): const(E[]). Expand E: const(shared(const(int))[]). Simplify: const(shared(int)[]). (In reply to Manu from comment #5) > In my example above, it's weird that `shared` surrounds `int`, but `const` > surrounds `int[]`... why are they applied at different levels? `shared` is in the signature, `const` isn't. If you change fun's parameter to `shared(const(T)) a`, the return type becomes `shared(const(int))[]` as expected.
Comment #7 by turkeyman — 2019-08-18T22:05:52Z
Oh yeah; I confused myself when I didn't spot the placement of the parens initially. Ignore that post...
Comment #8 by simen.kjaras — 2019-08-18T23:40:44Z
is(shared const int : shared U, U) does evaluate to true, and U is const int. Can you elaborate on why that's not good enough?
Comment #9 by ag0aep6g — 2019-08-19T00:12:21Z
(In reply to Simen Kjaeraas from comment #8) > is(shared const int : shared U, U) does evaluate to true, and U is const > int. Can you elaborate on why that's not good enough? That seems like a viable workaround, hinging on the fact that `is(int : shared U, U)` is false even though there are possible values for `U` that would pass (e.g., `is(int : shared int)` is true). But it doesn't change that the result of `==` is wrong.
Comment #10 by turkeyman — 2019-08-19T00:33:58Z
I already have workarounds. I'm making a big report, because this seems to be a bug.
Comment #11 by turkeyman — 2019-08-19T00:34:25Z
**Bug report.
Comment #12 by dlang-bot — 2019-08-19T04:15:07Z
dlang/phobos pull request #7147 "prepare for fix of issue 20138 ("is expression not evaluating correct…" was merged into master: - dc5e22944a048fb3a81f31875bcaa3c1adbb87ef by aG0aep6G: prepare for fix of issue 20138 ("is expression not evaluating correctly?") With issue 20138 fixed, `const U` and `shared U` do match `const shared T`, and they leave the other qualifier intact. So `const shared U` must be attempted first if we want to strip both qualifiers. https://github.com/dlang/phobos/pull/7147
Comment #13 by dlang-bot — 2019-08-20T08:24:00Z
dlang/dmd pull request #10317 "fix issue 20138 - is expression not evaluating correctly?" was merged into master: - 5b5219e7c2f5c9abe17b82cb38847a84d87517ca by aG0aep6G: fix issue 20138 - is expression not evaluating correctly? When passing a `shared const T` into a `shared U` parameter, then no const conversion is needed to infer `U` as `const int`. Same with `inout int` and `inout const int`. - cc9b34c49edb1b3e012294c0fbbbcf605369c5eb by aG0aep6G: add changelog entry for issue 20138 https://github.com/dlang/dmd/pull/10317
Comment #14 by ag0aep6g — 2019-08-31T19:55:06Z
*** Issue 20185 has been marked as a duplicate of this issue. ***