Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit c97c5bb

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Various fixes.
- Better type checking for smooth. - Fix typing of if expressions. - Fix printing of if expressions. Belonging to [master]: - #2157
1 parent 91ae007 commit c97c5bb

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,9 +1423,10 @@ protected
14231423
list<Expression> args;
14241424
list<NamedArg> named_args;
14251425
Expression arg1, arg2;
1426-
Type ty1;
1426+
Type ty1, ty2;
14271427
Variability var;
14281428
Function fn;
1429+
TypeCheck.MatchKind mk;
14291430
algorithm
14301431
UNTYPED_CALL(ref = fn_ref, arguments = args, named_args = named_args) := call;
14311432

@@ -1442,7 +1443,7 @@ protected
14421443

14431444
{arg1, arg2} := args;
14441445
(arg1, ty1, var) := Typing.typeExp(arg1, origin, info);
1445-
(arg2, ty, variability) := Typing.typeExp(arg2, origin, info);
1446+
(arg2, ty2, variability) := Typing.typeExp(arg2, origin, info);
14461447

14471448
// First argument must be Integer.
14481449
if not Type.isInteger(ty1) then
@@ -1461,10 +1462,12 @@ protected
14611462
// Second argument must be Real, array of allowed expressions or record
14621463
// containing only components of allowed expressions.
14631464
// TODO: Also handle records here.
1464-
if not Type.isReal(Type.arrayElementType(ty)) then
1465+
(arg2, ty, mk) := TypeCheck.matchTypes(ty2, Type.setArrayElementType(ty2, Type.REAL()), arg2, true);
1466+
1467+
if not TypeCheck.isCompatibleMatch(mk) then
14651468
Error.addSourceMessageAndFail(Error.ARG_TYPE_MISMATCH,
14661469
{"2", ComponentRef.toString(fn_ref), "", Expression.toString(arg2),
1467-
Type.toString(ty), "Real\n Real[:, ...]\n Real record\n Real record[:, ...]"}, info);
1470+
Type.toString(ty2), "Real\n Real[:, ...]\n Real record\n Real record[:, ...]"}, info);
14681471
end if;
14691472

14701473
{fn} := typeCachedFunctions(fn_ref);

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public
752752
Operator.symbol(exp.operator) +
753753
operandString(exp.exp2, exp, false);
754754

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

757757
case UNBOX() then "UNBOX(" + toString(exp.exp) + ")";
758758
case CAST() then "CAST(" + Type.toString(exp.ty) + ", " + toString(exp.exp) + ")";

Compiler/NFFrontEnd/NFTypeCheck.mo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,6 @@ algorithm
16461646
end if;
16471647

16481648
outExp := Expression.IF(ec, e1, e2);
1649-
outType := thenType;
16501649
outVar := Prefixes.variabilityMax(thenVar, elseVar);
16511650
end checkIfExpression;
16521651

0 commit comments

Comments
 (0)