Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4780 closed defect (fixed)

Issue with Complex constructor in NF

Reported by: Francesco Casella Owned by: Mahder Alemseged Gebremedhin
Priority: critical Milestone: 2.0.0
Component: New Instantiation Version:
Keywords: Cc:

Description

After f570c07f3, Complex numbers should be supported in the NF. However, the test cases in the ScalableTestSuite e.g., DistributionSystemLinear_N_10_M_10, still fail with this error:

[Complex 3.2.2.mo:163:5-163:48:writable]
Error: Ambiguous matching functions found for
Complex(/*Real*/ c1.re + c2.re, /*Real*/ c1.im + c2.im).
Candidates are:
  Complex(Real re, Real im) => Complex
  Complex(Real re, Real im = 0.0) => Complex

Line 163 of Complex.mo reads:

c3 := Complex(c1.re + c2.re, c1.im + c2.im)

I'm not sure why the two candidates for the constructor should be in conflict, since in this case there is obviously no need for a default value of the im part, but anyway I guess this bug should be fixed easily. If so, can you do it right away?

Change History (2)

comment:1 by Francesco Casella, 7 years ago

Resolution: fixed
Status: newclosed

Fixed in PR 2241

comment:2 by Mahder Alemseged Gebremedhin, 7 years ago

This might be late but just for clarification:
The two functions are indeed ambiguous. It should be printed like this:

Candidates are:
  Complex(Real re, Real im) => Complex
  Complex.'constrcutor'.fromReal(Real re, Real im = 0.0) => Complex

We used to print the overloaded function name thinking it will be less confusing. This has changed since so it will be printed like above now.

The real problem here is that Complex.'constrcutor'.fromReal is defined as

function fromReal
  input Real re;
  input Real im = 0;
...
end fromReal;

which makes it ambiguous with the default.

function $default
  input Real re;
  input Real im;
...
end $default;

constructor for calls with two arguments, .e.g., Complex(i,j)

but the rule for constructor overloads is that the default constructor is used only if there is no other match. That is what is done PR 2241.

The default constructor for Complex will never be used the way Complex is written now :). It will always use fromReal because it has two inputs. I don't know why it has two inputs.

Last edited 7 years ago by Mahder Alemseged Gebremedhin (previous) (diff)
Note: See TracTickets for help on using tickets.