Opened 15 years ago

Closed 10 years ago

#1144 closed defect (worksforme)

Fails to validate correct class (from MathCore)

Reported by: Jan Brugård Owned by: Jan Brugård
Priority: high Milestone:
Component: Frontend Version:
Keywords: Cc: Jan Brugård, Per Östlund

Description

Validate the following class (the total model is attached):

model FacultyCall
  parameter Integer n=15;
  Integer fac=faculty(n);
  Integer fac_rec=faculty_rec(n);
end FacultyCall;

This returns the following error:

--- [13] 17:22:28 Validation of class M1_solutions.E03.Faculty.FacultyCall ---
Check of M1_solutions.E03.Faculty.FacultyCall failed
Error: Type mismatch in modifier, expected type Integer, got modifier =M1_solutions.E03.Faculty.faculty(n) of type Real
Error: Error occured while flattening model M1_solutions.E03.Faculty.FacultyCall

For some reason n is interpreted as a Real even though it is declared as an integer. If the value 15 is used instead of n in the function call it works to validate the model. this model is part of the exercises of our course (I cab avoid that problem this time). However, I believe that it is a quite worrying error that could possible affect a lot of other models. Therefore setting highest priority. If the error is judged not to influence too much the priority should be decreased.

Attachments (1)

FacultyCallTotal.mo (9.0 KB ) - added by Jan Brugård 15 years ago.

Download all attachments as: .zip

Change History (7)

by Jan Brugård, 15 years ago

Attachment: FacultyCallTotal.mo added

comment:2 by Per Östlund, 15 years ago

checkModel(M1_solutions_E03_Faculty_FactultyCall) in OMShell runs successfully, so validation of the model works with OMC at least. I fixed some bugs a while ago related to type mismatches with Integer and Real, so this bug might have been fixed then.

comment:3 by bjozac, 15 years ago

This is still not working, this is the output of OpenModelica. I reopen this ticket.

./omc.exe FacultyCallTotal.mo
Error processing file: FacultyCallTotal.mo
Error: Type mismatch in modifier, expected type Integer, got modifier =M1_solutions.E03.Faculty.faculty(n) of type Real
Error: Type mismatch in modifier, expected type Integer, got modifier =M1_solutions.E03.Faculty.faculty_rec(n) of type Real
Error: Type mismatch in modifier, expected type Integer, got modifier =M1_solutions.E03.Faculty.faculty(n) of type Real

# Error encountered! Exiting...
# Please check the error message and the flags.

comment:4 by Per Östlund, 15 years ago

I'm still unable to confirm this bug. This is the output when I run it (using revision 4909):

$ omc FacultyCallTotal.mo 
function M1_solutions.E03.Faculty.faculty_rec
input Integer n;
output Integer k = 1;
algorithm
  assert( n >= 0, "n must be larger than 0");
  k := if n == 0 then 1 else n * M1_solutions.E03.Faculty.faculty_rec(n - 1);
end M1_solutions.E03.Faculty.faculty_rec;

function M1_solutions.E03.Faculty.faculty
input Integer n;
output Integer k = 1;
algorithm
  assert( n >= 0, "n must be larger than 0");
  if n <> 0 then
    for i in 1:n loop
      k := k * i;
    end for;
  end if;
end M1_solutions.E03.Faculty.faculty;

fclass M1_solutions_E03_Faculty_FacultyCall
parameter Integer n = 15;
Integer fac = M1_solutions.E03.Faculty.faculty(n);
Integer fac_rec = M1_solutions.E03.Faculty.faculty_rec(n);
end M1_solutions_E03_Faculty_FacultyCall;

Are you sure that you're using a recent (i.e. newer than about two weeks) revision of OMC?

comment:5 by AlexeyLebedev, 15 years ago

This seems to happen because the value faculty(15)=faculty_rec(15)=15! is too big for 32-bit integer, so its type is Real. If you replace 15 by 12 or lower number, then the instantiation goes fine.

Interesting, that if you replace "parameter Integer n=15;" by "constant Integer n=15;", then the instantiaton finishes successfully, even though one gets a modification "Integer fac_rec=1307674368000.0;", i.e., a Real value for an Integer variable.

comment:6 by Martin Sjölund, 10 years ago

Component: Frontend
Resolution: worksforme
Status: reopenedclosed
Note: See TracTickets for help on using tickets.