how convert the range to slice ?

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 28 15:15:29 PST 2015


Chris Williams:

> Range is not castable to array. See std.array.array to generate 
> an array from a Range.


Currently this program:

void main() {
     import std.range;
     int[] a = iota(10);
}


Gives an error like:

test.d(3,19): Error: cannot implicitly convert expression 
(iota(10)) of type Result to int[]


For the error message to be like yours, the compiler has to 
recognize a Range, this could be possible because foreach() 
already does that.

I think you can try to open a diagnostic enhancement request.

In D there are already examples of hardcoded error messages 
targeting newbies:

void main() {
     int x;
     writeln(a);
     printf("%d\n", x);
}


Gives:

test.d(3,5): Error: 'writeln' is not defined, perhaps you need to 
import std.stdio; ?
test.d(4,5): Error: 'printf' is not defined, perhaps you need to 
import core.stdc.stdio; ?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list