﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3750	Compilation Problem for model modifier with constrainedby and inheritance	dongping	somebody	"Suppose we have model `M1` which has a replaceable component `C1`, and `M1` uses modifiers and constrainedby to specified the value of all the parameters. 

`M2` inherits from `M1` and replaced `C1` with `C2`. `C2` has less parameters than `C1`. It shouldn't be a problem that the model `M2` works, since `M1` used constrainedby. 

And OM-nightly works as it should. 

However, a certain model `M3` which uses `C3` doesn't compile.

Problem details:

We have three different models:
* `ModelicaByExample.Architectures.ThermalControl.Examples.ExpandableModel` (short `1_ExpandableModel`)
* A model which extends `1_ExpandableModel` `ModelicaByExample.Architectures.ThermalControl.Examples.OnOffVariant` (short `2_OnOffVariant`)
* and then a model which extends `2_OnOffVariant` `ModelicaByExample.Architectures.ThermalControl.Examples.HysteresisVariant` (short `3_HysteresisVariant`)

The `1_ExpandableModel` uses a replaceable component variant `V1_ExpandablePIControl` which has the most parameters, and `1_ExpandableModel` specified them as following:
{{{
    redeclare replaceable Implementations.ExpandablePIControl
      controller(setpoint=300, k=20, T=1)
      constrainedby Interfaces.ControlSystem_WithExpandableBus);
}}}

Then `2_OnOffVariant` uses a component `V2_OnOffControl` which has less parameters, and so far so good:
{{{
    redeclare replaceable
      Implementations.OnOffControl controller(setpoint=300));
}}}

Then `3_HysteresisVariant` uses a component `V3_OnOffControl_WithHysteresis`, and somehow it doesn't work
{{{
  extends OnOffVariant(redeclare Implementations.OnOffControl_WithHysteresis
      controller(setpoint=300, bandwidth=1));
}}}

Here is the discussion with Mike Tiller and @perost for reference:
https://github.com/xogeny/ModelicaBook/pull/295


Bug Reproduction:

I failed to make a simplified version, so the I tried to make the reproduction step easier:
{{{
mkdir test_constrainedby && cd test_constrainedby
git clone https://github.com/xie-dongping/ModelicaBook && cd ModelicaBook 
git checkout modifier 
echo ""loadFile(\""ModelicaByExample/package.mo\"");simulate(ModelicaByExample.Architectures.ThermalControl.Examples.HysteresisVariant);"" > test.mos
omc test.mos
}}}
and you can see the model doesn't work and the flattening failed.

If we remove the modifier, the incompatibility surely isn't a problem:
{{{
git checkout no_error
git diff modifier..no_error
omc test.mos
}}}

Surely, there are workarounds to make the model works, and I'm not sure if we had any misunderstanding about the specification. So I really would like to hear what you think. Thanks in advance!
"	defect	closed	high	1.12.0	*unknown*	v1.9.4-dev-nightly	worksforme		
