Bug 4286 – Wrong error line number and more with schwartzSort

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-06-06T07:40:00Z
Last change time
2013-01-10T14:10:51Z
Keywords
diagnostic
Assigned to
andrei
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-06-06T07:40:55Z
This is D2 code, I don't understand this bug: import std.typecons: tuple, Tuple; import std.algorithm: schwartzSort; void foo(int N)(char[] txt) { int[char[N]] aa; foreach (i; 0 .. txt.length + 1 - N) { char[N] key = txt[i .. i + N]; aa[key]++; } alias Tuple!(char[N], "key", int, "value") Pair; Pair[] pairs; foreach (key, value; aa) pairs ~= Pair(key, value); schwartzSort!((p){ return tuple(p.value, p.key); })(pairs); } void main() { char[] txt = cast(char[])("this is just a test".dup); foo!(1)(txt); foo!(2)(txt); } DMD v2.046 prints at compile-time: test.d(4061): Error: function test.foo!(1).foo.schwartzSort!(__dgliteral1,"a < b",cast(SwapStrategy)0,Tuple!(char[2u],"key",int,"value")[]).schwartzSort is a nested function and cannot be accessed from foo This work-around seems to fix the program: schwartzSort!((Pair p){ return tuple(p.value, p.key); })(pairs); Also note the wrong line number, this is why I have tagged this as DMD bug instead of Phobos problem.
Comment #1 by clugdbug — 2011-12-21T23:25:10Z
The wrong line number was fixed in DMD2.054. The other issue is an instance of bug 5939, bug 6217, and various others.
Comment #2 by andrej.mitrovich — 2013-01-10T14:10:51Z
Works in 2.061+.