[Issue 8367] New: std.range.chain's template constraint is inadequate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 10 00:18:02 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8367

           Summary: std.range.chain's template constraint is inadequate
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-07-10 00:18:01 PDT ---
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.

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


More information about the Digitalmars-d-bugs mailing list