Bug 12780 – Multiplying integer array by scalar double fails

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-21T14:08:00Z
Last change time
2015-02-18T03:41:27Z
Keywords
pull
Assigned to
nobody
Creator
sfrijters

Comments

Comment #0 by sfrijters — 2014-05-21T14:08:16Z
void main() { int ifoo = 2; int[3] ibar = 1; double dfoo = 2.0; double[3] dbar = 1.0; dfoo = ifoo * dfoo; // Scalar int * scalar double -- OK dfoo = dfoo * dfoo; // Scalar double * scalar double -- OK dbar = dfoo * dbar[]; // Scalar double * array of double -- OK ibar = ifoo * ibar[]; // Scalar int * array of int -- OK dbar = ifoo * dbar[]; // Scalar int * array of double -- OK dbar = dfoo * ibar[]; // Scalar double * array of int -- FAIL } I would have expected the last case to work as well, but I get testarr.d(13): Error: incompatible types for ((dfoo) * (ibar[])): 'double' and 'int[]' Discussion at http://forum.dlang.org/thread/[email protected] suggests that this an unnecessary restriction and could be lifted.
Comment #1 by k.hara.pg — 2014-12-19T15:11:48Z
Comment #2 by github-bugzilla — 2014-12-27T07:39:44Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5bea0130e4d3491dfcae1501f8248b478fb5e8ae fix Issue 12780 - Multiplying integer array by scalar double fails Support upcasting slice elements in array operations. 1. The tweak in the buildArrayIdent() retains backward compatibility. a) If no element upcasting exists in array operation, the generated function name is not changed. double_res[] = double_val * double_arr[]; // _arrayExpSliceMulSliceAssign_d b) If upcasting slice elements is necessary, it will be encoded by the postfix "Of" + element-type-deco double_res[] = double_val * int_arr[]; // _arrayExpSlice'Ofi'MulSliceAssign_d 2. Even if the whole array operation requires double element, the sub array operations can be processed by int. double_res[] = (int_val ^ int_arr[]) * double_val; // typeof(int_val ^ int_arr[]) == int[] https://github.com/D-Programming-Language/dmd/commit/22611aa7eda98705a5661f0df424434a73b3c837 Merge pull request #4218 from 9rnsr/fix12780 Issue 12780 - Multiplying integer array by scalar double fails
Comment #3 by bearophile_hugs — 2014-12-27T09:16:06Z
(In reply to github-bugzilla from comment #2) > Issue 12780 - Multiplying integer array by scalar double fails For me one of the most important problems with array operations is Issue 10523
Comment #4 by github-bugzilla — 2015-02-18T03:41:27Z