- Index
- » Programming
- » Modelica Language
- » 1.) No matching function; 2.)...
1.) No matching function; 2.) Function scope
1.) No matching function; 2.) Function scope
Hello!
Two questions:
First:
Error: No matching function found for find(in_x.value) of type function(index:Integer) => Real, candidates are function(index:Integer) => Real
How to interpret that? ...Looks like the candidate's pattern exactly matches the reqired one.
Second:
In the case of a class which contains a type declaration and a function - Shouldn't the type be available in the scope of the function then?
Kind Regards,
Hannes
- edes
- 38 Posts
Re: 1.) No matching function; 2.) Function scope
Code:
class A
type T = Integer;
function find
input T t1;
output T t2 = t1;
end find;
T t1 = find(1);
end A;
Seems to work fine. The types do exist.
However, that error messages can sometimes be bad:
* Either it failed to create a record constructor. Then it will say this type exists, etc...
* Or it fails to instantiate the function.
Run omc with +d=failtrace to see what weird things fails.
- sjoelund.se
- 1700 Posts
Re: 1.) No matching function; 2.) Function scope
Thanks for your response.
As for the failtrace to omc: We start our simulation using a .mos OMShell script, because the simulation environment needs much more than one command to be set up correctly. Is there any way to pass omc-switches from OMShell?
As for the scoping problem: Our situation looks a little different - This is from an OMShell session, which describes the actual problem better:
Code:
>> model C
function find
input Integer index;
output Real value;
algorithm
for j in labels loop
if index == Integer(j) then value := werte[i]; end if;
end for;
end find;
type labels = enumeration (one "1st", two "2nd");
constant Real[labels] values := {1.1, 2.2};
Real valueTwo = find(Integer(labels.two));
end C;
{C}
>> simulate(C)
record SimulationResult
resultFile = "Simulation failed.
Error: Wrong type or wrong number of arguments to Integer(j)'.
Error: Variable labels not found in scope C.find
Error: No matching function found for find(2) of type function(index:Integer) => Real, candidates are function(index:Integer) => Real
Error: Error occured while flattening model C
"
end SimulationResult;
...Maybe the type exists in the function's scope, but the for-statement doesn't work as described in 11.2.2 of the Modelica 3.0 language specification?
Cheers,
Hannes
- edes
- 38 Posts
Re: 1.) No matching function; 2.) Function scope
Ah... The first error message is:
Error: Variable labels not found in scope C.find
And enumerations are weird in OpenModelica. It really should work, and I know Per has been poking around with enumerations the last week.
- sjoelund.se
- 1700 Posts
Re: 1.) No matching function; 2.) Function scope
Huh...?
Well - We already noticed, that the enum implementation im OM is kind of rudimentary yet, but we need enums here, cause they are ideal for the definition of table headers (combination of a String and the corresponding Integer, which is the Array-Index).
But I didn't really get your answer: Do you suggest to implement a workaround?
- edes
- 38 Posts
Re: 1.) No matching function; 2.) Function scope
I've seen the following used before:
package myAlmostEnum
constant Integer a = 1;
constant Integer b = 2;
constant Integer c = 3;
constant Integer d = 4;
constant Integer e = 5;
constant Integer f = 6;
constant Integer numberOfElements = 6;
end myAlmostEnum;
Actually, it seems like the index becomes an integer. It works if you remove the call to Integer()... Really weird. For-loops don't work properly with enumerations. Or something like that.
- sjoelund.se
- 1700 Posts
Re: 1.) No matching function; 2.) Function scope
Oh - Thanks! ...Actually I did not mean to ask for a workaround solution - I just wasn't sure wether the problem was a fault in our programming or not.
Just one more thing: Is there a chance to pass the failtrace switch to omc, if a simulation is run from OMShell?
- edes
- 38 Posts
Re: 1.) No matching function; 2.) Function scope
Sort of. You can start the interactive session before you start OMShell, and then OMShell will use that session instead.
$ omc +d=interactiveCorba,failtrace +showErrorMessages
Then start OMShell and type something silly like a+b into the prompt and see some error messages in your console.
- sjoelund.se
- 1700 Posts
Re: 1.) No matching function; 2.) Function scope
edes wrote:
Code:
model C
function find
input Integer index;
output Real value;
algorithm
for j in labels loop
if index == Integer(j) then value := werte[i]; end if;
end for;
end find;
type labels = enumeration (one "1st", two "2nd");
constant Real[labels] values := {1.1, 2.2};
Real valueTwo = find(Integer(labels.two));
end C;
The problem in this case is that enumerations as you have seen are not completely implemented yet. When the enumeration is used as the range in the for loop it is unfortunately converted into an integer range, which causes the Integer call to fail since Integer only works on enumerations. A workaround in this case would therefore be to remove the Integer call in the for loop, and just use the iterator as it is. The best solution would of course be to keep the iterator as an enumeration instead of converting it to an integer, but at the moment I can't say when that will fixed. I'll add it to our bug tracker though, so hopefully it will be fixed sometime in the near future.
Cheers,
Per
- perost
- 114 Posts
Re: 1.) No matching function; 2.) Function scope
Clear now. Thank you!
- edes
- 38 Posts
Re: 1.) No matching function; 2.) Function scope
I am Very new to OpenModelica and need help..
I geeting the following Notifications every time while using any function.
" [:0:0-0:0] Notification: Instantiation of C failed.; "
Please any one can help me out ...
- Index
- » Programming
- » Modelica Language
- » 1.) No matching function; 2.)...