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

Commit 3006b8a

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix Typing.typeCrefDim for array types.
- Handle untyped component with array types in Typing.typeCrefDim. Belonging to [master]: - OpenModelica/OpenModelica#134 - #3047
1 parent ee4deab commit 3006b8a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ uniontype Class
407407
end if;
408408
end isIdentical;
409409

410+
function hasDimensions
411+
input Class cls;
412+
output Boolean hasDims;
413+
algorithm
414+
hasDims := match cls
415+
case EXPANDED_DERIVED()
416+
then arrayLength(cls.dims) > 0 or hasDimensions(InstNode.getClass(cls.baseClass));
417+
case TYPED_DERIVED() then Type.isArray(cls.ty);
418+
else false;
419+
end match;
420+
end hasDimensions;
421+
410422
function getDimensions
411423
input Class cls;
412424
output list<Dimension> dims;

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ function typeCrefDim
12861286
input ExpOrigin.Type origin;
12871287
input SourceInfo info;
12881288
output Dimension dim;
1289-
output TypingError error;
1289+
output TypingError error = TypingError.NO_ERROR();
12901290
protected
12911291
list<ComponentRef> crl;
12921292
list<Subscript> subs;
@@ -1319,13 +1319,20 @@ algorithm
13191319
node := InstNode.resolveOuter(cr.node);
13201320
c := InstNode.component(node);
13211321

1322+
// If the component is untyped it might have an array type whose dimensions
1323+
// we need to take into consideration. To avoid making this more complicated
1324+
// than it already is we make sure that the component is typed in that case.
1325+
if Class.hasDimensions(InstNode.getClass(Component.classInstance(c))) then
1326+
typeComponent(node, origin);
1327+
c := InstNode.component(node);
1328+
end if;
1329+
13221330
dim_count := match c
13231331
case Component.UNTYPED_COMPONENT()
13241332
algorithm
13251333
dim_count := arrayLength(c.dimensions);
13261334

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

13391346
if index <= dim_count and index > 0 then
1340-
error := TypingError.NO_ERROR();
13411347
dim := Type.nthDimension(c.ty, index);
13421348
return;
13431349
end if;

0 commit comments

Comments
 (0)