From 8fe91b3bf2db68ac9738a710bf2bddb08137f32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Mon, 13 Nov 2017 17:16:01 +0100 Subject: [PATCH] Improve detection of invalid each in NFInst. - Take the dimensions of a component's type into account when checking whether each is used on an array or not. - Don't fail when an invalid use of each is found, since the MSL uses each incorrectly. Belonging to [master]: - OpenModelica/OMCompiler#2010 - OpenModelica/OpenModelica-testsuite#776 --- Compiler/FrontEnd/MetaModelicaBuiltin.mo | 2 +- Compiler/NFFrontEnd/NFClass.mo | 11 +++++++++++ Compiler/NFFrontEnd/NFInst.mo | 4 +++- Compiler/NFFrontEnd/NFMod.mo | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Compiler/FrontEnd/MetaModelicaBuiltin.mo b/Compiler/FrontEnd/MetaModelicaBuiltin.mo index 15c8fcd3ad..4c285dc1bd 100644 --- a/Compiler/FrontEnd/MetaModelicaBuiltin.mo +++ b/Compiler/FrontEnd/MetaModelicaBuiltin.mo @@ -664,7 +664,7 @@ function arrayEmpty "O(1)" input array arr; output Boolean isEmpty; algorithm - isEmpty := arrayLength(str) == 0; + isEmpty := arrayLength(arr) == 0; annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true); end arrayEmpty; diff --git a/Compiler/NFFrontEnd/NFClass.mo b/Compiler/NFFrontEnd/NFClass.mo index f37b391990..e9107f2548 100644 --- a/Compiler/NFFrontEnd/NFClass.mo +++ b/Compiler/NFFrontEnd/NFClass.mo @@ -313,6 +313,17 @@ uniontype Class end match; end getDimensions; + function hasDimensions + input Class cls; + output Boolean hasDims; + algorithm + hasDims := match cls + case DERIVED_CLASS() + then not listEmpty(cls.dims) or hasDimensions(InstNode.getClass(cls.baseClass)); + else false; + end match; + end hasDimensions; + function getAttributes input Class cls; output Component.Attributes attr; diff --git a/Compiler/NFFrontEnd/NFInst.mo b/Compiler/NFFrontEnd/NFInst.mo index 7aa5e8e0f7..515ffde8ff 100644 --- a/Compiler/NFFrontEnd/NFInst.mo +++ b/Compiler/NFFrontEnd/NFInst.mo @@ -971,7 +971,6 @@ algorithm checkOuterComponentMod(comp_mod, comp, comp_node); dims := list(Dimension.RAW_DIM(d) for d in def.attributes.arrayDims); - Modifier.checkEach(comp_mod, listEmpty(dims), InstNode.name(comp_node)); binding := Modifier.binding(comp_mod); comp_mod := Modifier.propagate(comp_mod); condition := Binding.fromAbsyn(def.condition, SCode.Each.NOT_EACH(), parent, info); @@ -985,6 +984,9 @@ algorithm // Instantiate the type of the component. (cls, cls_attr) := instTypeSpec(def.typeSpec, comp_mod, attr, scope, comp_node, def.info); + Modifier.checkEach(comp_mod, listEmpty(dims) and + not Class.hasDimensions(InstNode.getClass(cls)), InstNode.name(comp_node)); + if not referenceEq(attr, cls_attr) then comp_node := InstNode.componentApply(comp_node, Component.setAttributes, cls_attr); end if; diff --git a/Compiler/NFFrontEnd/NFMod.mo b/Compiler/NFFrontEnd/NFMod.mo index 0a01753bc9..2ce87c4e28 100644 --- a/Compiler/NFFrontEnd/NFMod.mo +++ b/Compiler/NFFrontEnd/NFMod.mo @@ -435,7 +435,7 @@ public Error.addSourceMessage(Error.EACH_ON_NON_ARRAY, {elementName}, mod.info); then - fail(); + (); else (); end match;