Opened 9 years ago

Closed 4 years ago

#3622 closed defect (fixed)

Bad management of public and protected variables

Reported by: francois.beaude@… Owned by: somebody
Priority: high Milestone: 1.16.0
Component: New Instantiation Version:
Keywords: protected, public, variables Cc:

Description (last modified by Lennart Ochel)

When writing the following two models

class AccessRights
  Real publ;
protected
  Real protec;
end AccessRights;

class Glob
  AccessRights A;
equation
  A.publ = 10;
  A.protec = 1;
end Glob;

The Glob model is successfully compiled and a simulation is conducted (using OpenModelica v1.9.3). Only publ can be displayed in output (not A.protec). When the A.protec = 1 equation is commented out, an error message is displayed (not enough equations).
The Modelica language specification (3.3, section 4.1) says that "Protected elements in classes cannot be accessed via dot notation. They may not be modified or redeclared in a class modification."

As a result, shouldn't the A.protec = 1 equation be deemed illegal ?

Change History (2)

comment:1 by Lennart Ochel, 9 years ago

Component: UnknownFrontend
Description: modified (diff)

Once the equation A.protec = 1 is commented out, the model should fail exactly as it does, since there is indeed one missing equation.
The second issue is the missing error message. I think we should display an error message and abort the translation if protected elements get accessed via dot notation. If needed, a flag could be introduced to continue the translation anyway.

comment:2 by Per Östlund, 4 years ago

Component: FrontendNew Instantiation
Milestone: Future1.16.0
Resolution: fixed
Status: newclosed

The new frontend gives the expected error:

[test.mo:4:3-4:14:writable] Error: Illegal access of protected element protec.
[test.mo:11:3-11:15:writable] Error: Variable A.protec not found in scope Glob.
Note: See TracTickets for help on using tickets.