Bug 10963 – Wrong code with aliased function referencing closure variable
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-04T01:14:00Z
Last change time
2015-03-25T03:45:37Z
Keywords
wrong-code
Assigned to
nobody
Creator
ttanjo
Comments
Comment #0 by ttanjo — 2013-09-04T01:14:17Z
I apologize to use not descriptive summary but I don't know how to explain this behavior...
The following code should work without errors but it doesn't work in dmd v2.064-devel-6f9a34f and v2.063 on Mac OSX.
It causes AssertError at line 6 at runtime.
---
import std.algorithm;
import std.range;
auto foo(in int[] ar)
{
assert(ar.length == 1);
return true;
}
void main(string[] args)
{
immutable ar = [0];
[0].map!(_ => {
auto r = [0].filter!(_ => foo(ar));
r.save.until!"true";
return 0;
}()).front;
}
---
If changing `ar` from immutable to enum, it works.
If using `r.until!"true"` instead of `r.save.until!"true"`, it works.
If using `filter` without `map`, it works.
Comment #1 by peter.alexander.au — 2014-02-23T05:30:19Z
This is a code gen bug. I have minimized it as much as I can:
http://dpaste.dzfl.pl/e2e878490438
-------------------------------------
void test(int[] a)
{
assert(a.length == 1);
}
struct A(alias p)
{
this(int a) { p(); }
A foo() { return A(0); }
}
void main()
{
int[] a = [0];
() { A!(() => test(a))(0).foo(); }();
}
-------------------------------------
The assert still fires, despite the fact that test is only ever called with 'main.a', which never changes.
Comment #2 by k.hara.pg — 2015-03-25T03:45:37Z
It's a duplication of 9685, and properly fixed in 2.067.
*** This issue has been marked as a duplicate of issue 9685 ***