Opened 14 years ago
Last modified 14 years ago
#1402 closed defect (fixed)
Checking types in if expressions (the non-evaluated branch)
Reported by: | dhedberg | Owned by: | dhedberg |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Version: | ||
Keywords: | Cc: | dhedberg, |
Description
In the MSL combitable models you find code such as:
for i in 1:n loop y[i]=if not tableOnFile and size(table, 1) == 1 then table[1,columns[i]] else tableTimeIpo(tableID, columns[i], u[i]); end for;
where the condition of the if expression is a parameter. If it is set to false (interpolation data is read from file) we get an error when building the model as the true branch is still type checked and hence an illegal subscript is found. This needs to be addressed as the table classes of MSL generates an error message when they are used in models and the data is located in an external file (you set the fileName and tableOnFile parameters of the class).
However, worth noting is that it seems like the type checking is more relaxed when checking the model as this error message is not produced during a checkModel call. The relaxed type checking is due to the "checkModel" being set and as a consequence the elabSubscriptsDims2() function in Static.mo will not fail in this case.
Change History (7)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
The example code is rather incomplete...
Is the problem that this code will produce an error message, but work anyway?
{{{class A
parameter Boolean b = false;
Real r = if not b then 1.0 else q();
end A;}}}
=>
{{{class A
parameter Boolean b = false;
Real r = 1.0;
end A;
[e.mo:3:3-3:38:writable] Error: Class q not found in scope A (looking for a function or record).}}}
comment:3 by , 14 years ago
I am sorry if the description was confusing. Yes, the compiler will report an error, but the generated code is correct. What makes this worse is that code like this is used in MSL and it may confuse users in thinking they have done something wrong.
comment:4 by , 14 years ago
I'll fix this in the trunk by doing checkpoint/delete/rollback of error messages. Do you need me to also fix it in the branch?
comment:5 by , 14 years ago
If possible, fixing it on the branch as well would be most appreciated! Thank you!
comment:6 by , 14 years ago
This is now working in trunk (see SCM commits). It should soon be ported to the branch (Note: the testsuite is not 100% on the branch, some problems could appear, although this is unlikely).
comment:7 by , 14 years ago
And now the backport has been commited. The testcases added in the trunk work as expected and no new testcases started failing (using make fast).
http://intranet/trac/mathmodelica/ticket/1410