diff --git a/Compiler/NFFrontEnd/NFCall.mo b/Compiler/NFFrontEnd/NFCall.mo index 0e05a78f093..18988f7a550 100644 --- a/Compiler/NFFrontEnd/NFCall.mo +++ b/Compiler/NFFrontEnd/NFCall.mo @@ -1423,9 +1423,10 @@ protected list args; list 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; @@ -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 @@ -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); diff --git a/Compiler/NFFrontEnd/NFExpression.mo b/Compiler/NFFrontEnd/NFExpression.mo index de8fbfeda58..bbd341ae01d 100644 --- a/Compiler/NFFrontEnd/NFExpression.mo +++ b/Compiler/NFFrontEnd/NFExpression.mo @@ -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) + ")"; diff --git a/Compiler/NFFrontEnd/NFTypeCheck.mo b/Compiler/NFFrontEnd/NFTypeCheck.mo index f39541304d2..9f25c44f0fe 100644 --- a/Compiler/NFFrontEnd/NFTypeCheck.mo +++ b/Compiler/NFFrontEnd/NFTypeCheck.mo @@ -1646,7 +1646,6 @@ algorithm end if; outExp := Expression.IF(ec, e1, e2); - outType := thenType; outVar := Prefixes.variabilityMax(thenVar, elseVar); end checkIfExpression;