Skip to content

Commit

Permalink
[NF] Various fixes.
Browse files Browse the repository at this point in the history
- Better type checking for smooth.
- Fix typing of if expressions.
- Fix printing of if expressions.

Belonging to [master]:
  - OpenModelica/OMCompiler#2157
  • Loading branch information
perost authored and OpenModelica-Hudson committed Feb 1, 2018
1 parent 91ae007 commit c97c5bb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -1423,9 +1423,10 @@ protected
list<Expression> args;
list<NamedArg> named_args;
Expression arg1, arg2;
Type ty1;
Type ty1, ty2;
Variability var;
Function fn;
TypeCheck.MatchKind mk;
algorithm
UNTYPED_CALL(ref = fn_ref, arguments = args, named_args = named_args) := call;

Expand All @@ -1442,7 +1443,7 @@ protected

{arg1, arg2} := args;
(arg1, ty1, var) := Typing.typeExp(arg1, origin, info);
(arg2, ty, variability) := Typing.typeExp(arg2, origin, info);
(arg2, ty2, variability) := Typing.typeExp(arg2, origin, info);

// First argument must be Integer.
if not Type.isInteger(ty1) then
Expand All @@ -1461,10 +1462,12 @@ protected
// Second argument must be Real, array of allowed expressions or record
// containing only components of allowed expressions.
// TODO: Also handle records here.
if not Type.isReal(Type.arrayElementType(ty)) then
(arg2, ty, mk) := TypeCheck.matchTypes(ty2, Type.setArrayElementType(ty2, Type.REAL()), arg2, true);

if not TypeCheck.isCompatibleMatch(mk) then
Error.addSourceMessageAndFail(Error.ARG_TYPE_MISMATCH,
{"2", ComponentRef.toString(fn_ref), "", Expression.toString(arg2),
Type.toString(ty), "Real\n Real[:, ...]\n Real record\n Real record[:, ...]"}, info);
Type.toString(ty2), "Real\n Real[:, ...]\n Real record\n Real record[:, ...]"}, info);
end if;

{fn} := typeCachedFunctions(fn_ref);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -752,7 +752,7 @@ public
Operator.symbol(exp.operator) +
operandString(exp.exp2, exp, false);

case IF() then "if" + toString(exp.condition) + " then " + toString(exp.trueBranch) + " else " + toString(exp.falseBranch);
case IF() then "if " + toString(exp.condition) + " then " + toString(exp.trueBranch) + " else " + toString(exp.falseBranch);

case UNBOX() then "UNBOX(" + toString(exp.exp) + ")";
case CAST() then "CAST(" + Type.toString(exp.ty) + ", " + toString(exp.exp) + ")";
Expand Down
1 change: 0 additions & 1 deletion Compiler/NFFrontEnd/NFTypeCheck.mo
Expand Up @@ -1646,7 +1646,6 @@ algorithm
end if;

outExp := Expression.IF(ec, e1, e2);
outType := thenType;
outVar := Prefixes.variabilityMax(thenVar, elseVar);
end checkIfExpression;

Expand Down

0 comments on commit c97c5bb

Please sign in to comment.