The following code produce
51
3 0 4
2 0 4
.
.
.
0 0 4
[5, 5, 5, 5, 5]
[2, 1, 1, 0, 1]
by commenting out the return statement in BW_count
and commenting in the other code we get the expected output.
51
3 0 50
2 0 50
.
.
.
0 0 50
[51, 51, 51, 51, 51]
[2, 1, 1, 0, 1]
//**** BW_count ****//
// string,string[] => int[]
// Count the number of suffix matches in Burrows Wheeler Transform
unittest
{
writeln(BW_count("TCCTCTATGAGATCCTATTCTATGAAACCTTCA$GACCAAAATTCTCCGGC",["CCT","CAC","GAG","CAG","ATC"]));
writeln([2,1,1,0,1]);
}
int[] BW_count(string str,string[] pat)
{
int BW_count_pat(string sstr,uint start=0,uint end=str.length-1)
{
writeln(sstr.length," ",start," ",end);
if (!sstr.length) return end-start+1;
return BW_count_pat(sstr[1..$],start,end);
}
writeln(str.length);
/* if (!pat.length)
return (int[]).init;
return BW_count_pat(pat[0])~BW_count(str,pat[1..$]);
*/
return pat.map!(BW_count_pat).array;
}
Comment #1 by k.hara.pg — 2014-01-25T10:52:21Z
Reduced test case.
void main()
{
test("abcdefg");
}
void test(string str)
{
void bar(string sstr, size_t end = str.length-1)
{
import std.stdio;
writeln(sstr.length, " ", end);
}
foo!(bar)(str[0..4]);
}
void foo(alias fun)(string s)
{
fun(s);
}
Prints:
4 4294967295
The second parameter 'end' is assigned garbage because 'str' parameter of test function is not directly accessible from 'foo' function.
Raised importance to 'critical' because it's wrong-code generation bug.
Comment #2 by robert.schadek — 2024-12-13T18:16:18Z