Skip to content

Commit

Permalink
[NF] Fix Typing.typeCrefDim for array types.
Browse files Browse the repository at this point in the history
- Handle untyped component with array types in Typing.typeCrefDim.

Belonging to [master]:
  - #134
  - OpenModelica/OMCompiler#3047
  • Loading branch information
perost authored and OpenModelica-Hudson committed Apr 8, 2019
1 parent ee4deab commit 3006b8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -407,6 +407,18 @@ uniontype Class
end if;
end isIdentical;

function hasDimensions
input Class cls;
output Boolean hasDims;
algorithm
hasDims := match cls
case EXPANDED_DERIVED()
then arrayLength(cls.dims) > 0 or hasDimensions(InstNode.getClass(cls.baseClass));
case TYPED_DERIVED() then Type.isArray(cls.ty);
else false;
end match;
end hasDimensions;

function getDimensions
input Class cls;
output list<Dimension> dims;
Expand Down
12 changes: 9 additions & 3 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -1286,7 +1286,7 @@ function typeCrefDim
input ExpOrigin.Type origin;
input SourceInfo info;
output Dimension dim;
output TypingError error;
output TypingError error = TypingError.NO_ERROR();
protected
list<ComponentRef> crl;
list<Subscript> subs;
Expand Down Expand Up @@ -1319,13 +1319,20 @@ algorithm
node := InstNode.resolveOuter(cr.node);
c := InstNode.component(node);

// If the component is untyped it might have an array type whose dimensions
// we need to take into consideration. To avoid making this more complicated
// than it already is we make sure that the component is typed in that case.
if Class.hasDimensions(InstNode.getClass(Component.classInstance(c))) then
typeComponent(node, origin);
c := InstNode.component(node);
end if;

dim_count := match c
case Component.UNTYPED_COMPONENT()
algorithm
dim_count := arrayLength(c.dimensions);

if index <= dim_count and index > 0 then
error := TypingError.NO_ERROR();
dim := typeDimension(c.dimensions, index, node, c.binding, origin, c.info);
return;
end if;
Expand All @@ -1337,7 +1344,6 @@ algorithm
dim_count := Type.dimensionCount(c.ty);

if index <= dim_count and index > 0 then
error := TypingError.NO_ERROR();
dim := Type.nthDimension(c.ty, index);
return;
end if;
Expand Down

0 comments on commit 3006b8a

Please sign in to comment.