Bug 7955 – Nested function error in sort with lambda template but not with a lambda
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-04-20T17:52:00Z
Last change time
2013-10-04T00:16:19Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-04-20T17:52:05Z
import std.algorithm: sort;
int foo(int n)() {
sort!((a, b) => true)([1]);
//sort!((int a, int b) => true)([1]);
foo!1();
return 0;
}
void main() {
foo!0();
}
DMD 2.059 shows:
...\dmd2\src\phobos\std\algorithm.d(6781): Error: function test.foo!(0).foo.sort!(__lambda3,cast(SwapStrategy)0,int[]).sort is a nested function and cannot be accessed from test.foo!(1).foo
The version that uses the lambda instead of a lambda template compiles correctly (then crashes at a runtime because the sort function is stupid).
Comment #1 by verylonglogin.reg — 2012-05-03T03:16:10Z
Reduced testcase:
---
void f(alias fun)() { }
void g(T)() {
f!(a => a)();
}
void main() {
g!int();
g!long();
}
---
Error: function main.g!(int).g.f!(__lambda2).f is a nested function and cannot be accessed from main.g!(long).g
Workaround: explicitly define lambda type: `(int a) => a`.
Comment #2 by verylonglogin.reg — 2013-10-04T00:16:19Z
Like Issue 7917 it compiles fine now. Then crashes at a runtime because of infinite recursion. Please open a new issue is there is a problem with `sort`.