Bug 9359 – Can't concat ints: incompatible types for 'int' and 'int'

Status
RESOLVED
Resolution
INVALID
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-20T13:20:00Z
Last change time
2013-01-21T16:17:43Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bus_dbugzilla

Comments

Comment #0 by bus_dbugzilla — 2013-01-20T13:20:12Z
void main() { int a = 0; int[] b = a ~ a; } ======================== test.d(4): Error: incompatible types for ((a) ~ (a)): 'int' and 'int'
Comment #1 by nilsbossung — 2013-01-20T14:20:49Z
(In reply to comment #0) > void main() > { > int a = 0; > int[] b = a ~ a; > } > ======================== > test.d(4): Error: incompatible types for ((a) ~ (a)): 'int' and 'int' I can't see the bug. That's not supposed/specified to work, is it?
Comment #2 by bearophile_hugs — 2013-01-20T14:35:15Z
Normally you do it like this: void main() { int a = 0; int[] b = [a, a]; } Or even: void main() { int a = 0; int[] b = (int[]).init ~ a ~ a; }
Comment #3 by bugzilla — 2013-01-20T14:39:42Z
ints are not arrays, and can't be concatenated.
Comment #4 by bus_dbugzilla — 2013-01-21T16:17:43Z
They can be concatenated with arrays, thus producing another array. But thinking about it more, defining 'int~int' to result in 'int[]' would be inconsistent with the fact that 'int[]~int[]' results in 'int[]' instead of 'int[][]'. This does result in some annoying inconsistencies: int[] a = [1] ~ 1 ~ 1; // OK int[] a = 1 ~ [1] ~ 1; // OK int[] a = 1 ~ 1 ~ [1]; // Fail int[] a = [1] ~ [1]; // OK int[] a = 1 ~ [1]; // OK int[] a = [1] ~ 1; // OK int[] a = 1 ~ 1; // Fail But I guess I don't see a way around that without introducing the more error-prone inconsistency of: [[1]] ~ [[1]] --> int[][] [1] ~ [1] --> int[] 1 ~ 1 --> int[]