[Issue 4286] New: Wrong error line number and more with schwartzSort
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 6 07:40:56 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4286
Summary: Wrong error line number and more with schwartzSort
Product: D
Version: future
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-06-06 07:40:55 PDT ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list