Implicit cast to immutable

bearophile bearophileHUGS at lycos.com
Wed Oct 5 16:19:37 PDT 2011


Do you know why this program doesn't compile (with DMD 2.056head)?


immutable(int[]) foo(in int[] x) pure {
    return new int[1];
}
void main() {}


It gives:
test.d(2): Error: cannot implicitly convert expression (new int[](1u)) of type int[] to immutable(int[])

This program instead compiles (now x is int[2] instead of int[]):

immutable(int[]) foo(in int[2] x) pure {
    return new int[1];
}
void main() {}


Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list