Opened 3 years ago

Closed 3 years ago

#6217 closed defect (fixed)

Allow checking models containing partial classes

Reported by: casella Owned by: perost
Priority: blocker Milestone: 1.17.0
Component: New Instantiation Version:
Keywords: Cc: adrpo, mwetter

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 follow-up: Changed 3 years ago by perost

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.

comment:2 in reply to: ↑ 1 Changed 3 years ago by casella

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 Changed 3 years ago by perost

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 Changed 3 years ago by casella

  • Cc mwetter added

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

Last edited 3 years ago by casella (previous) (diff)

comment:5 Changed 3 years ago by casella

  • Resolution set to fixed
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.