Bug 14735 – [REG2.068-b1] std.string.indexOf cannot deduce function for char argument

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-25T19:13:00Z
Last change time
2017-07-22T12:35:45Z
Keywords
pull
Assigned to
nobody
Creator
pro.mathias.lang

Comments

Comment #0 by pro.mathias.lang — 2015-06-25T19:13:34Z
The following code compiled fine in 2.067: ``` void main() { import std.string; enum Test = "Hello\0World"; char[64] foo; foo[0 .. Test.length] = Test[]; auto greetings = foo[0 .. foo[].indexOf('\0')]; } ``` But now it outputs: Error: template std.string.indexOf cannot deduce function from argument types !()(char[], char), candidates are: /home/travis/dmd2/linux/bin64/../../src/phobos/std/string.d(346): std.string.indexOf(Range)(Range s, in dchar c, in CaseSensitive cs = CaseSensitive.yes) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) /home/travis/dmd2/linux/bin64/../../src/phobos/std/string.d(471): std.string.indexOf(T, ulong n)(ref T[n] s, in dchar c, in CaseSensitive cs = CaseSensitive.yes) if (isSomeChar!T) /home/travis/dmd2/linux/bin64/../../src/phobos/std/string.d(544): std.string.indexOf(Range)(Range s, in dchar c, in size_t startIdx, in CaseSensitive cs = CaseSensitive.yes) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) /home/travis/dmd2/linux/bin64/../../src/phobos/std/string.d(640): std.string.indexOf(Range, Char)(Range s, const(Char)[] sub, in CaseSensitive cs = CaseSensitive.yes) if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char) /home/travis/dmd2/linux/bin64/../../src/phobos/std/string.d(793): std.string.indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, in size_t startIdx, in CaseSensitive cs = CaseSensitive.yes) if (isSomeChar!Char1 && isSomeChar!Char2) This affects Vibe.d
Comment #1 by slavo5150 — 2015-06-26T05:36:32Z
A simpler test case: void main() { import std.string; char[64] foo; int i = foo[].indexOf('\0'); }
Comment #2 by k.hara.pg — 2015-06-26T06:12:14Z
It's a phobos regression introduced in: https://github.com/D-Programming-Language/phobos/pull/3191
Comment #3 by dlang-bugzilla — 2015-06-26T10:33:42Z
Comment #4 by slavo5150 — 2015-06-27T09:57:32Z
The problem has something to do with the CaseSensitive argument. This (cut-and-paste code compiles): //********************************* import std.stdio; import std.traits; import std.range.primitives; import std.typecons : Flag; alias CaseSensitive = Flag!"caseSensitive"; ptrdiff_t indexOf(Range)(Range s, in dchar c) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) { return 0; } ptrdiff_t indexOf(Range)(Range s, in dchar c, in size_t startIdx) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) { return 0; } ptrdiff_t indexOf(Range, Char)(Range s, const(Char)[] sub) if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char) { return 0; } ptrdiff_t indexOf(T, size_t n)(ref T[n] s, in dchar c) if (isSomeChar!T) { return indexOf(s[], c); } ptrdiff_t indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, in size_t startIdx) if (isSomeChar!Char1 && isSomeChar!Char2) { return 0; } void main() { char[10] fixedSizeArray = "0123456789"; assert(indexOf(fixedSizeArray, '2') == 2); assert(indexOf(fixedSizeArray[], '2') == 2); // Issue 14735 } This code does not compile. The only difference is the addition of the CaseSensitive argument. //*********************************** import std.stdio; import std.traits; import std.range.primitives; import std.typecons : Flag; alias CaseSensitive = Flag!"caseSensitive"; ptrdiff_t indexOf(Range)(Range s, in dchar c, in CaseSensitive cs = CaseSensitive.yes) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) { return 0; } ptrdiff_t indexOf(Range)(Range s, in dchar c, in size_t startIdx, in CaseSensitive cs = CaseSensitive.yes) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) { return 0; } ptrdiff_t indexOf(Range, Char)(Range s, const(Char)[] sub, in CaseSensitive cs = CaseSensitive.yes) if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char) { return 0; } ptrdiff_t indexOf(T, size_t n)(ref T[n] s, in dchar c, in CaseSensitive cs = CaseSensitive.yes) if (isSomeChar!T) { return indexOf(s[], c); } ptrdiff_t indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, in size_t startIdx, in CaseSensitive cs = CaseSensitive.yes) if (isSomeChar!Char1 && isSomeChar!Char2) { return 0; } void main() { char[10] fixedSizeArray = "0123456789"; assert(indexOf(fixedSizeArray, '2') == 2); assert(indexOf(fixedSizeArray[], '2') == 2); // Issue 14735 } I'm still not sure how to fix this, but I hope this information is helpful.
Comment #5 by schuetzm — 2015-06-27T12:06:46Z
Comment #6 by schuetzm — 2015-06-27T12:21:56Z
@Mike: Thank you. I experimented with your reduce code, and I'm now sure it's a compiler bug: https://issues.dlang.org/show_bug.cgi?id=14741
Comment #7 by k.hara.pg — 2015-06-27T12:34:19Z
Sorry, this is a compiler bug, because of the incomplete implementation for the language enhancement from 2.063. Code to illustrate issue. int foo(Range )(Range s, in dchar c) { return 1; } // A int foo(T, size_t n)(ref T[n] s, in dchar c) { return 2; } // B void main() { char[64] buf; // Supported from 2.063: (http://dlang.org/changelog#implicitarraycast) assert(foo(buf[0..32], '\0') == 2); // Not yet supported case (it's a compiler bug) assert(foo(buf[], '\0') == 2); } In both cases (buf[0..23] and buf[]), the foo calls should match to B, because it's specialized version to the static array argument than A.
Comment #8 by k.hara.pg — 2015-06-27T12:46:19Z
(In reply to Kenji Hara from comment #7) > Sorry, this is a compiler bug, because of the incomplete implementation for > the language enhancement from 2.063. PR to fix dmd: https://github.com/D-Programming-Language/dmd/pull/4779
Comment #9 by k.hara.pg — 2015-06-27T13:23:24Z
(In reply to Kenji Hara from comment #8) > (In reply to Kenji Hara from comment #7) > > Sorry, this is a compiler bug, because of the incomplete implementation for > > the language enhancement from 2.063. > > PR to fix dmd: > https://github.com/D-Programming-Language/dmd/pull/4779 My compiler fix needs Phobos tweak. https://github.com/D-Programming-Language/phobos/pull/3446
Comment #10 by github-bugzilla — 2015-06-29T22:26:00Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/cd77a9cdcb8483618bde3512386e6899692c04af Supplemental fix for issue 14735 - Prevent self-recursive match The slice expression `s[]` will match to T[n] by using compile-time length deduction. https://github.com/D-Programming-Language/phobos/commit/f6ce5692ef12c136229844f21afe184dfb885f3e Merge pull request #3446 from 9rnsr/fix14735 Supplemental fix for issue 14735 - Prevent self-recursive match
Comment #11 by github-bugzilla — 2015-06-29T23:05:12Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/13a16e8e0344e90c3a03b87167d9a82b3cb7e24c fix Issue 14735 - std.string.indexOf cannot deduce function for char argument https://github.com/D-Programming-Language/dmd/commit/fdfb5882ef701ebfda49a3cc3392b5fe4e0e95b8 Merge pull request #4779 from 9rnsr/fix14735 [REG2.068-b1] Issue 14735 - std.string.indexOf cannot deduce function for char argument
Comment #12 by k.hara.pg — 2015-06-30T02:09:56Z
*** Issue 14741 has been marked as a duplicate of this issue. ***
Comment #13 by github-bugzilla — 2015-06-30T17:08:31Z
Commit pushed to stable at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/709fb22e8ad984d5a77181a2669afaefed5c6a1d Merge pull request #3446 from 9rnsr/fix14735 Supplemental fix for issue 14735 - Prevent self-recursive match
Comment #14 by github-bugzilla — 2015-07-01T01:25:13Z
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/c2b84a0b24f680bfa3cd336af6c84b0ded2c4594 Merge pull request #4779 from 9rnsr/fix14735 [REG2.068-b1] Issue 14735 - std.string.indexOf cannot deduce function for char argument
Comment #15 by github-bugzilla — 2015-07-24T03:20:17Z
Comment #16 by github-bugzilla — 2015-07-25T00:03:28Z
Comment #17 by github-bugzilla — 2015-10-04T18:18:47Z
Comment #18 by github-bugzilla — 2015-10-04T18:19:45Z
Comment #19 by github-bugzilla — 2017-07-19T17:43:36Z
Commit pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/709fb22e8ad984d5a77181a2669afaefed5c6a1d Merge pull request #3446 from 9rnsr/fix14735
Comment #20 by github-bugzilla — 2017-07-22T12:35:45Z
Commits pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/13a16e8e0344e90c3a03b87167d9a82b3cb7e24c fix Issue 14735 - std.string.indexOf cannot deduce function for char argument https://github.com/dlang/dmd/commit/fdfb5882ef701ebfda49a3cc3392b5fe4e0e95b8 Merge pull request #4779 from 9rnsr/fix14735