D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7279 - Inconsistent overloading between arrays and scalars
Summary: Inconsistent overloading between arrays and scalars
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-01-12 08:34 UTC by Denis Shelomovskii
Modified: 2012-01-23 04:48 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2012-01-12 08:34:40 UTC
---
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 Kenji Hara 2012-01-23 04:48:55 UTC
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.