Bug 19829 – __traits(isSame) returns true for some non-local delegate lambdas even when they are different

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-04-26T08:34:14Z
Last change time
2020-03-21T03:56:32Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
Simen Kjaeraas
See also
https://issues.dlang.org/show_bug.cgi?id=19828

Comments

Comment #0 by simen.kjaras — 2019-04-26T08:34:14Z
From issue 19828: import std.stdio : writeln; unittest { int[] arr = [0, 1]; // Different writeln(__traits(isSame, i => arr[i], a => a) ? "Same" : "Different"); // Same test!(i => arr[i], a => a); // Different test!(i => arr[i], a => a * 4); } auto test(alias map1, alias map2)() { writeln(__traits(isSame, map1, map2) ? "Same" : "Different"); }
Comment #1 by ag0aep6g — 2019-04-26T09:43:38Z
Two observations: 1) This prints "true" even though the two lambdas are clearly not the same: pragma(msg, __traits(isSame, i => x[i], a => a)); This is a bug in itself. 2) In the original code, when I move `arr` to global scope, then all writelns correctly print "Different". This suggests that, in the context of `test` and __traits(isSame, ...), map1 might be considered to not have access to arr.
Comment #2 by b2.temp — 2019-04-26T14:51:35Z
looks like a 2.079.z regression : https://run.dlang.io/is/LCV9pX
Comment #3 by simen.kjaras — 2019-04-26T21:02:11Z
Not really - lambda comparison was implemented in 2.079. Before that any comparison of lambdas with isSame would return false. Anyways, the core issue is `x` doesn't impact the serialization of lambdas, while it should render the lambda incomparable. Fixed here: https://github.com/dlang/dmd/pull/9710
Comment #4 by dlang-bot — 2019-04-26T21:03:11Z
@Biotronic created dlang/dmd pull request #9710 "Fix issue 19829 - __traits(isSame) returns true for some non-local de…" fixing this issue: - Fix issue 19829 - __traits(isSame) returns true for some non-local delegate lambdas even when they are different https://github.com/dlang/dmd/pull/9710
Comment #5 by dlang-bot — 2019-05-30T06:43:52Z
dlang/dmd pull request #9710 "Fix issue 19829 - __traits(isSame) returns true for some non-local de…" was merged into master: - c4782963597ce3e719a10d218a7933b69d2dafac by Biotronic: Fix issue 19829 - __traits(isSame) returns true for some non-local delegate lambdas even when they are different https://github.com/dlang/dmd/pull/9710