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

--- Comment #0 from 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];

    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);

DMD v2.046 prints at compile-time:

test.d(4061): Error: function!(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:
------- You are receiving this mail because: -------

Reply via email to