Bug 14791 – std.string.indexOf(char[], char) no longer compiles

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-09T22:36:00Z
Last change time
2015-07-13T05:48:39Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-07-09T22:36:30Z
cat > bug.d << CODE import std.string; ptrdiff_t test() { char[64] buf; return buf[].indexOf('\0'); } CODE ---- dmd -c bug ---- bug2.d(6): Error: template std.string.indexOf cannot deduce function from argument types !()(char[], char), candidates are: /usr/include/dmd/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)) /usr/include/dmd/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) /usr/include/dmd/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)) /usr/include/dmd/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) /usr/include/dmd/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) ---- Might be related to issue 14765. Breaks vibe.d
Comment #1 by bugzilla — 2015-07-11T10:15:04Z
This is caused by a recent change to DMD that regards buf[] as being equivalent to buf[64]. (Which causes both overloads of indexOf() to match.)
Comment #2 by bugzilla — 2015-07-11T10:42:46Z
Test case: import std.range; void indexOf(Range)(Range s, bool cs = true) if (isInputRange!Range) { } void indexOf(T, size_t n)(ref T[n] s, bool cs = true) { } void test() { char[64] buf; indexOf(buf[]); } Results: Error: template foo.indexOf cannot deduce function from argument types !() (char[]), candidates are: foo.indexOf(Range)(Range s, bool cs = true) if (isInputRange!Range) foo.indexOf(T, uint n)(ref T[n] s, bool cs = true) Now, the peculiar thing is, if we remove the "bool cs = true" from both templates, it compiles without error. This is definitely a dmd bug, not a Phobos bug.
Comment #3 by k.hara.pg — 2015-07-13T00:26:34Z
(In reply to Walter Bright from comment #1) > This is caused by a recent change to DMD that regards buf[] as being > equivalent to buf[64]. (Which causes both overloads of indexOf() to match.) Martin and Walter, do you really test the snippet with git-head dmd? In my local environment, git-head dmd does not reproduce the reported error. And, if I use the modified dmd which is reverting issue 14735 fix, the errors happen. I doubt this is for 2.068-beta1 issue (and it's a dup of 14735), or your local environment problem (that's not synchronized with current latest git-head repo).
Comment #4 by bugzilla — 2015-07-13T05:48:39Z
Updating to the latest HEAD does resolve the issue. Thank you, Kenji! Glad the fix was so easy!