www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11990] New: map don't play nice with default values in function

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11990

           Summary: map don't play nice with default values in function
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: knud all-technology.com



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;

}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11990


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
          Component|Phobos                      |DMD
           Severity|major                       |critical



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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2014