Skip to content

Commit

Permalink
[NF] Check if binding type does match component type
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Mar 26, 2017
1 parent 84fadec commit 7e8436e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
17 changes: 17 additions & 0 deletions Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -121,6 +121,13 @@ public
end match;
end typedExp;

function getTypedExp
input Binding binding;
output Expression exp;
algorithm
TYPED_BINDING(bindingExp = exp) := binding;
end getTypedExp;

function setTypedExp
input Expression exp;
input output Binding binding;
Expand Down Expand Up @@ -175,6 +182,16 @@ public
end match;
end isEach;

function isTyped
input Binding binding;
output Boolean isTyped;
algorithm
isTyped := match binding
case TYPED_BINDING() then true;
else false;
end match;
end isTyped;

function toString
input Binding binding;
input String prefix = "";
Expand Down
28 changes: 18 additions & 10 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -51,19 +51,20 @@ import NFType.Type;
import Operator = NFOperator;

protected
import Inst = NFInst;
import Lookup = NFLookup;
import TypeCheck = NFTypeCheck;
import Types;
import Ceval = NFCeval;
import ClassInf;
import ComponentRef = NFComponentRef;
import ExecStat.execStat;
import Inst = NFInst;
import InstUtil = NFInstUtil;
import Lookup = NFLookup;
import MatchKind = NFTypeCheck.MatchKind;
import NFCall.Call;
import NFClass.ClassTree;
import ComponentRef = NFComponentRef;
import Ceval = NFCeval;
import SimplifyExp = NFSimplifyExp;
import Subscript = NFSubscript;
import ExecStat.execStat;
import TypeCheck = NFTypeCheck;
import Types;

public
function typeClass
Expand Down Expand Up @@ -315,24 +316,31 @@ algorithm
() := match c
local
Binding binding;
MatchKind matchKind;

case Component.TYPED_COMPONENT()
algorithm
binding := typeBinding(c.binding, scope);

if not referenceEq(binding, c.binding) then
c.binding := binding;
InstNode.updateComponent(c, component);
end if;

if Binding.isTyped(binding) then
(_, _, matchKind) := TypeCheck.matchTypes(Binding.getType(binding), c.ty, Binding.getTypedExp(binding));
if not TypeCheck.isCompatibleMatch(matchKind) then
Error.addSourceMessage(Error.VARIABLE_BINDING_TYPE_MISMATCH, {InstNode.name(component), Binding.toString(binding), Type.toString(c.ty), Type.toString(Binding.getType(binding))}, Binding.getInfo(binding));
fail();
end if;
end if;

typeBindings(c.classInst, component);
then
();

else
algorithm
assert(false, getInstanceName() + " got invalid node " +
InstNode.name(component));
assert(false, getInstanceName() + " got invalid node " + InstNode.name(component));
then
fail();

Expand Down

0 comments on commit 7e8436e

Please sign in to comment.