Bug 7279 – Inconsistent overloading between arrays and scalars

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2012-01-12T08:34:00Z
Last change time
2012-01-23T04:48:55Z
Keywords
rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2012-01-12T08:34:40Z
--- void f(int[]) { assert(0); } void f(const int[]) { } void g(int[]) { assert(0); } void g(const(int)[]) { } void h(int) { assert(0); } void h(const int) { } void main() { immutable arr = [5]; f(arr); // Compiles g(arr); // Compiles immutable n = 5; h(n); // Error: ...matches both... } --- If f(arr) and g(arr) compiles, h(n) should compiles too.
Comment #1 by k.hara.pg — 2012-01-23T04:48:55Z
int[] is a value with mutable indirection, so copy conversion from immutable int[] to int[] is invalid. Then the callings of f and g with arr are solved with no ambiguous. But, immutable int is a value without mutable indirection, so copy conversion from immutable int to int is *valid*. Then callings of h makes ambiguous with the two const-conversions, immutable int -> int and immutable int -> const int.