D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12780 - Multiplying integer array by scalar double fails
Summary: Multiplying integer array by scalar double fails
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2014-05-21 14:08 UTC by Stefan Frijters
Modified: 2015-02-18 03:41 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Stefan Frijters 2014-05-21 14:08:16 UTC
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/uxuhzwkefamcnqsbwctp@forum.dlang.org suggests that this an unnecessary restriction and could be lifted.
Comment 2 github-bugzilla 2014-12-27 07:39:44 UTC
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 bearophile_hugs 2014-12-27 09:16:06 UTC
(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 github-bugzilla 2015-02-18 03:41:27 UTC
Commits pushed to 2.067 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

https://github.com/D-Programming-Language/dmd/commit/22611aa7eda98705a5661f0df424434a73b3c837
Merge pull request #4218 from 9rnsr/fix12780