Skip to content

Commit

Permalink
Fix for #3467.
Browse files Browse the repository at this point in the history
- Merge redeclare and binding modifier when looking up a modifier for a
  redeclared record component.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Sep 17, 2015
1 parent 0ad7abb commit 0de2ae0
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions Compiler/FrontEnd/Mod.mo
Expand Up @@ -1315,14 +1315,21 @@ print error of duplicate modifications, if not, the one modification having a va
input String n;
output DAE.Mod outMod;
algorithm
outMod := matchcontinue(mod1,mod2,n)
outMod := matchcontinue(mod1, mod2)
local
String s1,s2,s,n2;

case(DAE.NOMOD(),_,_) then mod2;
case (_,DAE.NOMOD(),_) then mod1;
case (DAE.NOMOD(), _) then mod2;
case (_, DAE.NOMOD()) then mod1;

case (DAE.REDECL(), DAE.MOD())
then mergeRedeclareWithBinding(mod1, mod2);

case (DAE.MOD(), DAE.REDECL())
then mergeRedeclareWithBinding(mod2, mod1);

// if they are equal, ignoring prefix, return the second one!
case(_,_,_)
case (_, _)
equation
true = modEqual(mod1, mod2);
then
Expand All @@ -1342,6 +1349,32 @@ algorithm
end matchcontinue;
end checkDuplicateModifications;

protected function mergeRedeclareWithBinding
"Merges two modifiers where the first is a redeclare and the second a binding
modifier. This is to handle the case where an extended record redeclares a
component, and then the component gets a binding when the record type is used.

E.g. record ER = R(redeclare SomeType x);
ER er = ER(1.0);
"
input DAE.Mod inRedeclare;
input DAE.Mod inBinding;
output DAE.Mod outMod = inRedeclare;
algorithm
outMod := match(outMod, inBinding)
local
SCode.Element el;

case (DAE.REDECL(tplSCodeElementModLst = {(el, DAE.NOMOD())}),
DAE.MOD(subModLst = {}, eqModOption = SOME(_)))
algorithm
outMod.tplSCodeElementModLst := {(el, inBinding)};
then
outMod;

end match;
end mergeRedeclareWithBinding;

protected function modEqualNoPrefix
input DAE.Mod mod1;
input DAE.Mod mod2;
Expand Down

0 comments on commit 0de2ae0

Please sign in to comment.