7285 – Implicit fixed-size array cast

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7285 - Implicit fixed-size array cast
Summary: Implicit fixed-size array cast
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2012年01月12日 18:27 UTC by bearophile_hugs
Modified: 2012年01月15日 01:51 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012年01月12日 18:27:03 UTC
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() {}
DMD 2.058head:
test.d(3): Error: cannot implicitly convert expression (cast(int[])ab) of type int[] to int[2u]
I think this isn't good.
Comment 1 Kenji Hara 2012年01月12日 22:29:16 UTC
https://github.com/D-Programming-Language/dmd/pull/618 


AltStyle によって変換されたページ (->オリジナル) /