Bug 8367 – std.range.chain's template constraint is inadequate

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-10T00:18:00Z
Last change time
2015-06-09T01:31:17Z
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2012-07-10T00:18:01Z
This code fails to compile import std.algorithm; import std.range; struct Foo {} void main() { auto f = Foo(); auto foos = [f]; auto foo = foos.map!(x => "foo"); auto bar = foo.chain("bar"); } giving this string of errors: /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1934): Error: cannot have parameter of type void /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1934): Error: variable std.range.chain!(Result,string).chain.Result.fixRef.val variables cannot be of type void /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1936): Error: cannot return non-void from void function /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1996): Error: function std.range.chain!(Result,string).chain.Result.fixRef (void val) is not callable using argument types (string) /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1996): Error: cannot implicitly convert expression (this.source._field_field_0.front()) of type string to void /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1996): Error: function std.range.chain!(Result,string).chain.Result.fixRef (void val) is not callable using argument types (dchar) /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(1996): Error: cannot implicitly convert expression (front(this.source._field_field_1)) of type dchar to void /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2026): Error: cannot return non-void from void function /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2026): Error: cannot return non-void from void function /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2039): Error: function std.range.chain!(Result,string).chain.Result.fixRef (void val) is not callable using argument types (dchar) /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2039): Error: cannot implicitly convert expression (back(this.source._field_field_1)) of type dchar to void /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2039): Error: function std.range.chain!(Result,string).chain.Result.fixRef (void val) is not callable using argument types (string) /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2039): Error: cannot implicitly convert expression (this.source._field_field_0.back()) of type string to void /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2061): Error: cannot return non-void from void function /home/jmdavis/dmd2/linux/bin/../../src/phobos/std/range.d(2061): Error: cannot return non-void from void function q.d(11): Error: template instance std.range.chain!(Result,string) error instantiating The code shouldn't compile. It's trying to chain an array of strings and a string. The types don't match. However, the error is _horrible_. Since the given arguments won't compile with chain, they shouldn't pass chain's template constraint (either that or chain must have a series of static asserts which output informative error messages for types which won't work with chain). But obviously, chain's template constraint is passing with arguments which fail to compile with chain, and that needs to be fixed.
Comment #1 by github-bugzilla — 2013-01-08T23:07:31Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/1008da752b135e41e26bc9fedeaffe824046be4e Issue 8367 - Insufficient constraints for chain The error message from compiling the bug's sample code after this change is: ``` bug.d(11): Error: template std.range.chain does not match any function template declaration. Candidates are: std/range.d(2018): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) bug.d(11): Error: template std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) cannot deduce template function from argument types !()(MapResult!(__lambda2, Foo[]),string) ``` Fixes Issue 8367 http://d.puremagic.com/issues/show_bug.cgi?id=8367 https://github.com/D-Programming-Language/phobos/commit/ca44a116d5cad084fe1cb968f23c54059984a06e Merge pull request #1047 from Poita/bug8367 Issue 8367 - Insufficient constraints for chain