Skip to content

Commit 6d60ea0

Browse files
authored
Singelton ut containing non singelton ut are treated as singeltons (#914)
* Singelton ut containing non singelton ut are treated as singeltons
1 parent c007a39 commit 6d60ea0

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

OMCompiler/Compiler/FrontEnd/InstMeta.mo

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,38 @@ public function fixUniontype
5757
algorithm
5858
outType := match (inState, inClassDef)
5959
local
60+
Absyn.Path p, p2, utPathOfRestriction, utPath;
6061
Boolean isSingleton;
61-
Absyn.Path p,p2;
62+
DAE.EvaluateSingletonType singletonType;
63+
FCore.Graph env_1;
64+
SCode.Element c;
65+
String name;
6266
list<Absyn.Path> paths;
6367
list<DAE.Type> typeVarsTypes;
6468
list<String> names, typeVars;
65-
DAE.EvaluateSingletonType singletonType;
66-
SCode.Element c;
67-
FCore.Graph env_1;
68-
6969
case (ClassInf.META_UNIONTYPE(typeVars=typeVars), SCode.PARTS())
7070
algorithm
71+
utPath := inState.path;
7172
p := AbsynUtil.makeFullyQualified(inState.path);
72-
names := SCodeUtil.elementNames(list(e for e guard match e case SCode.CLASS(restriction=SCode.R_METARECORD()) then true; else false; end match in inClassDef.elementLst));
73+
names := SCodeUtil.elementNames(list(
74+
e for e
75+
guard match e
76+
case SCode.CLASS(restriction=SCode.R_METARECORD(name = utPathOfRestriction))
77+
then AbsynUtil.pathSuffixOf(utPathOfRestriction, utPath);
78+
else false;
79+
end match
80+
in inClassDef.elementLst));
7381
paths := list(AbsynUtil.suffixPath(p, n) for n in names);
74-
isSingleton := listLength(paths)==1;
82+
isSingleton := listLength(paths) == 1;
7583
if isSingleton then
7684
p2 := listGet(paths, 1);
77-
singletonType := DAE.EVAL_SINGLETON_TYPE_FUNCTION(function fixUniontype2(arr=arrayCreate(1, (cache,inEnv,p2,NONE()))));
85+
singletonType := DAE.EVAL_SINGLETON_TYPE_FUNCTION(function fixUniontype2(arr=arrayCreate(1, (cache, inEnv, p2, NONE()))));
7886
else
7987
singletonType := DAE.NOT_SINGLETON();
8088
end if;
8189
typeVarsTypes := list(DAE.T_METAPOLYMORPHIC(tv) for tv in typeVars);
8290
then
83-
SOME(DAE.T_METAUNIONTYPE(paths,typeVarsTypes,isSingleton,singletonType,p));
84-
91+
SOME(DAE.T_METAUNIONTYPE(paths, typeVarsTypes, isSingleton, singletonType, p));
8592
else NONE();
8693
end match;
8794
end fixUniontype;

testsuite/metamodelica/meta/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ UniontypeFunc1.mos \
136136
UniontypeConst1.mos \
137137
UniontypeConst2.mos \
138138
UniontypeConst3.mos \
139+
UniontypeNestedSingelton.mos
139140
# test that currently fail. Move up when fixed.
140141
# Run make testfailing
141142
FAILINGTESTFILES=
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
uniontype UT
2+
record R
3+
Real RI;
4+
end R;
5+
function f
6+
output Real ro;
7+
protected
8+
UT tmpUT = R(1.0);
9+
algorithm
10+
ro := tmpUT.RI;
11+
end f;
12+
uniontype UT2
13+
record R1
14+
end R1;
15+
record R2
16+
end R2;
17+
end UT2;
18+
end UT;
19+
20+
function test
21+
output Real x;
22+
algorithm
23+
x := UT.f();
24+
end test;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// name: UniontypeConst4
2+
// keywords: uniontype singelton record
3+
// status: correct
4+
// cflags: -g=MetaModelica -d=gen
5+
//
6+
// This tests check that asserts that singelton uniontype
7+
// that contains non singelton subuniontypes are treated as singeltons.
8+
//
9+
10+
loadFile("UniontypeNestedSingelton.mo"); getErrorString();
11+
test(); getErrorString();
12+
13+
// Result:
14+
// true
15+
// ""
16+
// 1.0
17+
// ""
18+
// endResult

0 commit comments

Comments
 (0)