#2964 closed defect (fixed)
Report error when modifying final parameter
| Reported by: | Henrik Tidefelt | Owned by: | Per Östlund |
|---|---|---|---|
| Priority: | critical | Milestone: | 1.19.0 |
| Component: | New Instantiation | Version: | trunk |
| Keywords: | Cc: |
Description
Model B below modifies a final parameter in A, but validates fine:
package FinalParam
model A
final parameter Integer n = 2;
Real x[2](each start = 1.0);
equation
der(x[2]) = 0;
der(x[1]) = -x[n];
end A;
model B
A a(n = 3);
end B;
end FinalParam;
The illegal modification should be detected and reported as an error. Right now, this slips all the way through code generation and results an error during compilation of the C code.
Change History (5)
comment:1 by , 11 years ago
| Component: | New Instantiation → Frontend |
|---|---|
| Status: | new → assigned |
comment:2 by , 10 years ago
| Priority: | high → critical |
|---|
An even simpler example:
package P
model A
parameter Real p = 10;
final parameter Real q = 3*p;
end A;
model B
A a(q = 0);
end B;
end P;
Model B is compiled without any error or waring and produces a simulation code with q = 0, which is clearly against the language spec., section 7.2.6.
Failure to produce an error (or at least a warning) can cause very subtle bugs to go undetected in complex models.
Please make sure that in no cases can final elements be modified in a model.
comment:3 by , 10 years ago
Partially fixed in 415e95d. I say partially, because the check has several exceptions due to the way we handle modifiers. Most importantly I don't check extends modifiers, because that leads to all kinds of issues. The check will catch the examples given in this ticket though. I don't consider this issue properly solved though, and will leave the ticket open until we can fix it properly.
comment:4 by , 4 years ago
| Milestone: | Future → 1.18.0 |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |
The new frontend gives an error:
[test.mo:11:9-11:14:writable] Notification: From here: [test.mo:3:5-3:34:writable] Error: Trying to override final element n with modifier '= 3'.
It also does not have exceptions like mentioned in the above comment, so I think we can consider this fixed.
comment:5 by , 4 years ago
| Component: | Frontend → New Instantiation |
|---|---|
| Milestone: | 1.18.0 → 1.19.0 |

This is both a front-end and back-end error on OMC's behalf (front-end does not check the modification, uses the old one for array dimensions; back-end does not check index out of bounds).