﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5721	Redeclare extends on functions not picking up the correct redeclared package/record	Mahder Alemseged Gebremedhin	Per Östlund	"If you flatten this this model 
{{{
model ConstantEffectiveness
 package Medium1 = BuildSysPro.IBPSA.Media.Water;
 package Medium2 = BuildSysPro.IBPSA.Media.Air;

  BuildSysPro.IBPSA.Fluid.Sources.Boundary_pT sou_2(
    redeclare package Medium = Medium2);

  BuildSysPro.IBPSA.Fluid.Sources.Boundary_pT sou_1(
    redeclare package Medium = Medium1);
end ConstantEffectiveness;
}}}

You get some functions from the components. e.g.

{{{
function ConstantEffectiveness.sou_1.Medium.specificEnthalpy ""Return specific enthalpy""
  input ConstantEffectiveness.Medium.ThermodynamicState state ""Thermodynamic state record"";
  output Real h(quantity = ""SpecificEnergy"", unit = ""J/kg"", min = -10000000000.0, max = 10000000000.0, nominal = 1000000.0) ""Specific enthalpy"";
algorithm
  h := 4184.0 * (state.T - 273.15);
end ConstantEffectiveness.sou_1.Medium.specificEnthalpy;
}}}

this function is generated for {{{sou_1}}} as you can see from the name. However, it seems the record type that is the input to the function is of type {{{ConstantEffectiveness.Medium.ThermodynamicState}}}. This type does not, strictly speaking, exist in the model since the partial Medium from which this type is picked up has been redeclared. It should have been {{{ConstantEffectiveness.sou_1.Medium.specificEnthalpy}}} from {{{sou_1}}}.

I am still not entirely sure what causes this. If you use just one of the components, {{{sou_1}}} or {{{sou_2}}} **but not both** then everything works fine. This is because even though we pick the wrong name/type for the record we at least pick the one with correct elements in it. However, if you use both then the name is used for both and we have issues at codegen time.

Maybe you can find something.

I am trying to duplicate it using a non-library simple model but so far doesn't seem to pinpoint it.  

If you need the full model to test with, you can use {{{BuildSysPro.IBPSA.Fluid.HeatExchangers.Validation.ConstantEffectiveness}}} or one of the models from teh coverage where you see errors saying too many or too few arguments to function ...

"	defect	new	high	Future	New Instantiation				
