diff --git a/Compiler/NFFrontEnd/NFCall.mo b/Compiler/NFFrontEnd/NFCall.mo index 0b4aa271341..bc1a51ca210 100644 --- a/Compiler/NFFrontEnd/NFCall.mo +++ b/Compiler/NFFrontEnd/NFCall.mo @@ -1674,8 +1674,8 @@ protected if dim_size == -1 then dim_size := Dimension.size(dim); else - Error.addSourceMessageAndFail(Error.INVALID_ARRAY_DIM_IN_CONVERSION_OP, - {String(i), "vector", "1", Dimension.toString(dim)}, info); + Error.addSourceMessageAndFail(Error.NF_VECTOR_INVALID_DIMENSIONS, + {Type.toString(ty), toString(call)}, info); end if; end if; end if; diff --git a/Compiler/NFFrontEnd/NFTyping.mo b/Compiler/NFFrontEnd/NFTyping.mo index 04362abb1d0..2588f50a85c 100644 --- a/Compiler/NFFrontEnd/NFTyping.mo +++ b/Compiler/NFFrontEnd/NFTyping.mo @@ -1465,19 +1465,44 @@ function typeArray output Variability variability = Variability.CONSTANT; protected Expression exp; - list expl = {}; + list expl = {}, expl2 = {}; Variability var; - Type ty; + Type ty1 = Type.UNKNOWN(), ty2, ty3; + list tys = {}; + MatchKind mk; + Integer n=1; algorithm for e in elements loop - // TODO: Type checking. - (exp, ty, var) := typeExp(e, origin, info); + (exp, ty2, var) := typeExp(e, origin, info); variability := Prefixes.variabilityMax(var, variability); + (, ty3, mk) := TypeCheck.matchTypes(ty2, ty1, exp, allowUnknown = true); + if TypeCheck.isIncompatibleMatch(mk) then + // Try the other way around to get the super-type of the array + (, ty3, mk) := TypeCheck.matchTypes(ty1, ty2, exp, allowUnknown = false); + if TypeCheck.isCompatibleMatch(mk) then + ty1 := ty3; + end if; + else + ty1 := ty3; + end if; expl := exp :: expl; + tys := ty2 :: tys; + n := n+1; + end for; + // Give the actual error-messages here after we got the super-type of the array + for e in expl loop + ty2::tys := tys; + (exp, , mk) := TypeCheck.matchTypes(ty2, ty1, e); + expl2 := exp::expl2; + n := n-1; + if TypeCheck.isIncompatibleMatch(mk) then + Error.addSourceMessage(Error.NF_ARRAY_TYPE_MISMATCH, {String(n), Expression.toString(exp), Type.toString(ty2), Type.toString(ty1)}, info); + fail(); + end if; end for; - arrayType := Type.liftArrayLeft(ty, Dimension.fromExpList(expl)); - arrayExp := Expression.ARRAY(arrayType, listReverse(expl)); + arrayType := Type.liftArrayLeft(ty1, Dimension.fromExpList(expl2)); + arrayExp := Expression.ARRAY(arrayType, expl2); end typeArray; function typeRange diff --git a/Compiler/Util/Error.mo b/Compiler/Util/Error.mo index c479f7dbc98..dd0e2974d4f 100644 --- a/Compiler/Util/Error.mo +++ b/Compiler/Util/Error.mo @@ -935,6 +935,10 @@ public constant Message MIXED_DETERMINED = MESSAGE(583, SYMBOLIC(), ERROR(), Util.gettext("The given system is mixed-determined. [index > %s]\nPlease checkout the option \"--maxMixedDeterminedIndex\".")); public constant Message STACK_OVERFLOW_DETAILED = MESSAGE(584, SCRIPTING(), ERROR(), Util.gettext("Stack overflow occurred while evaluating %s:\n%s")); +public constant Message NF_VECTOR_INVALID_DIMENSIONS = MESSAGE(585, TRANSLATION(), ERROR(), + Util.gettext("Invalid dimensions %s in %s, no more than one dimension may have size > 1.")); +public constant Message NF_ARRAY_TYPE_MISMATCH = MESSAGE(586, TRANSLATION(), ERROR(), + Util.gettext("Array types mismatch. Argument %s (%s) has type %s whereas previous arguments have type %s.")); public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(), Util.gettext("Local variable '%s' shadows another variable."));