Opened 4 years ago

Closed 4 years ago

#6217 closed defect (fixed)

Allow checking models containing partial classes

Reported by: Francesco Casella Owned by: Per Östlund
Priority: blocker Milestone: 1.17.0
Component: New Instantiation Version:
Keywords: Cc: Adrian Pop, Michael Wetter

Description

If you check any model of the Modelica.Fluid library, which contains a partial medium package declaration, it fails with

[1] 11:55:14 Translation Error
[Modelica.Fluid.Interfaces: 571:7-572:53]: Medium is partial, name lookup is not allowed in partial classes.

This issue is reproduced by this MWE

package C
  model A
    B myB(redeclare package Medium = Modelica.Media.Air.MoistAir);
  end A;
  
  model B
    replaceable package Medium = Modelica.Media.Interfaces.PartialMedium;
    
    // The statement below is not valid, and leads to an error in checking the model B in OMEdit.
    parameter Modelica.SIunits.SpecificEnthalpy h_default = Medium.specificEnthalpy_pTX(
      p=Medium.p_default,
      T=Medium.T_default,
      X=Medium.X_default) "Default enthalpy for the selected medium";
  end B;
end C;

where B is checked successfully, but A fails check. Of course there is nothing wrong with A, it simply cannot be used unless the medium model is redeclared, but that doesn't make it invalid.

@perost, I'm not sure if you can fix this, or if @adrpo should take care of that, please report. Maybe we should introduce a separate API call that does (partial) instantiation for checking purposes and does not consider the constraint for simulation models.

Change History (5)

comment:1 by Per Östlund, 4 years ago

Currently we check for the nfAPI flag in some cases and both the nfAPI and checkModel in others when checking for partial classes, so just making sure to check for both nfAPI and checkModel everywhere should fix it.

I think I want to solve it a bit differently and introduce an "instantiation context" that can be propagated throughout the instantiation though, since I think there are both more things than partial that we might want to handle differently during checkModel and also more contexts we want to track.

in reply to:  1 comment:2 by Francesco Casella, 4 years ago

Replying to perost:

I think I want to solve it a bit differently and introduce an "instantiation context" that can be propagated throughout the instantiation though, since I think there are both more things than partial that we might want to handle differently during checkModel and also more contexts we want to track.

Sure. For example checking functions or entire packages, see #5045.

comment:3 by Per Östlund, 4 years ago

Fixed in b2811ee. We already had a kind of instantiation context that was used in the instantiation and typing, but I've now expanded on it and also use it to turn off some errors checks when needed (like when using nfAPI or checkModel).

comment:4 by Francesco Casella, 4 years ago

Cc: Michael Wetter added

@mwetter, this should fix one of your concerns in [Buildings #2229].

Version 0, edited 4 years ago by Francesco Casella (next)

comment:5 by Francesco Casella, 4 years ago

Resolution: fixed
Status: newclosed

I just checked it with the latest nightly, all seems fine.

Note: See TracTickets for help on using tickets.