Opened 14 years ago

Closed 9 years ago

#1203 closed defect (fixed)

Replaceable package behaves different when encapsulated in a package

Reported by: perob88 Owned by: perob88
Priority: high Milestone:
Component: Frontend Version: 1.5.0RC2
Keywords: Cc:

Description (last modified by perost)

Consider the following set of definitions. It is somewhat similar to the media library building blocks.

partial package partialStuff
  constant Integer nz = 1;
end partialStuff;
 
package simpleStuff
  extends testPackage.partialStuff(nz = 2);
end simpleStuff;
 
class modelComponent
  replaceable package theStuff = testPackage.partialStuff;
  Real compVar;
equation
  compVar = theStuff.nz;
end modelComponent;

Now let's instatiate the following model

model myModel
  package theStuff = simpleStuff;
  modelComponent comp(redeclare package theStuff = theStuff);
end myModel;

This yields: OMC-ERROR: "Error: Class myModel.theStuff not found in scope modelComponent.theStuff.

Encapsulating everything inside another package:

package testPackage
...
...
...
...
end testPackage

followed by instantiateModel(testPackage.myModel) gives correct results.

A third variant where the only difference is another level of instantiation gives the wrong results but no compiler complaints...:

class myModel
  replaceable package theStuff = partialStuff;
  modelComponent comp(redeclare package theStuff = theStuff);
end myModel;

model myModel2
  myModel modelInst(redeclare package theStuff = simpleStuff);
end myModel2;

instantiateModel(myModel2)
.. 
..
equation
  modelInst.comp.compVar = 1.0;

Here the problem is that compVar should be 2.0 instead of 1.0

Change History (1)

comment:1 Changed 9 years ago by perost

  • Cc perob88 removed
  • Component set to Frontend
  • Description modified (diff)
  • Resolution set to fixed
  • Status changed from new to closed

The example models contain some errors, but allowing for that this works now.

Note: See TracTickets for help on using tickets.