Bug 11990 – map don't play nice with default values in function

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-24T21:16:42Z
Last change time
2024-12-13T18:16:18Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Knud
Moved to GitHub: dmd#18764 →

Comments

Comment #0 by knud — 2014-01-24T21:16:42Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18764 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB