digitalmars.D.learn - About implicit array cast
- bearophile (21/21) Jan 12 2012 This code compiles, because the [0,0] dynamic array literal casts implic...
- Timon Gehr (2/23) Jan 12 2012 This is a bug.
- bearophile (5/6) Jan 12 2012 OK:
This code compiles, because the [0,0] dynamic array literal casts implicitly to
int[2]:
int[2] foo() {
    return [0, 0]; // OK
}
void main() {}
And of course this too compiles:
int[2] bar() {
    int[2] ab;
    return (true) ? ab : ab; // OK
}
void main() {}
But currently this code doesn't compile:
int[2] spam() {
    int[2] ab;
    return (true) ? ab : [0, 0]; // Error
}
void main() {}
test.d(3): Error: cannot implicitly convert expression (cast(int[])ab) of type
int[] to int[2u]
Is this good?
Bye,
bearophile
 Jan 12 2012
On 01/13/2012 02:19 AM, bearophile wrote:
 This code compiles, because the [0,0] dynamic array literal casts implicitly
to int[2]:
 int[2] foo() {
      return [0, 0]; // OK
 }
 void main() {}
 And of course this too compiles:
 int[2] bar() {
      int[2] ab;
      return (true) ? ab : ab; // OK
 }
 void main() {}
 But currently this code doesn't compile:
 int[2] spam() {
      int[2] ab;
      return (true) ? ab : [0, 0]; // Error
 }
 void main() {}
 test.d(3): Error: cannot implicitly convert expression (cast(int[])ab) of type
int[] to int[2u]
 Is this good?
 Bye,
 bearophile
This is a bug.
 Jan 12 2012
Timon Gehr:This is a bug.OK: http://d.puremagic.com/issues/show_bug.cgi?id=7285 Bye, bearophile
 Jan 12 2012








 
  
  
  bearophile <bearophileHUGS lycos.com>
 bearophile <bearophileHUGS lycos.com>