﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2387	Operator overloading fails for matrices	Per Östlund	Per Östlund	"There seems to be some issues when trying to use overloaded operators with matrices. For example this model:
{{{
operator record Complex
  Real re;
  Real im;

  encapsulated operator 'constructor'
    function fromReal
      import Complex;
      input Real re;
      input Real im = 0;
      output Complex result(re = re, im = im);
    end fromReal;
  end 'constructor';

  encapsulated operator '*'
    function multiply
      import Complex;
      input Complex c1;
      input Complex c2;
      output Complex c3;
    algorithm
      c3 := Complex(c1.re*c2.re - c1.im*c2.im, c1.re*c2.im + c1.im*c2.re);
    end multiply;

    function scalarProduct
      import Complex;
      input Complex c1[:];
      input Complex c2[size(c1, 1)];
      output Complex c3;
    algorithm
      c3 := Complex(0);
      for i in 1:size(c1, 1) loop
        c3 := c3 + c1[i] * c2[i];
      end for;
    end scalarProduct;
  end '*';

  encapsulated operator function '+'
    import Complex;
    input Complex c1;
    input Complex c2;
    output Complex c3;
  algorithm
    c3 := Complex(c1.re + c2.re, c1.im + c2.im);
  end '+';
end Complex;

model ComplexTest
  Complex c1 = Complex(1.0, 0.0);
  Complex c2[3, 3] = {{c1, c1, c1}, {c1, c1, c1}, {c1, c1, c1}};
  Complex c3[3, 1] = {{c1}, {c1}, {c1}};
  Complex c4[3, 1] = c2 * c3;
end ComplexTest;
}}}
In the binding of c4 we have c2 * c3, which is currently evaluated to a Complex[3] array instead of Complex[3, 1] as it should. This is because we don't check the restrictions on the function arguments for scalarProduct, and mistakenly use it even though the dimensions don't match.

If the scalarProduct function is removed the compiler still fails with:
{{{
Could not vectorize function because dimensions 3 and 1mismatch.
}}}"	defect	assigned	high	2.0.0	New Instantiation	trunk			
