Skip to content

Commit e5d7afe

Browse files
perostOpenModelica-Hudson
authored andcommitted
Updated nfinst test cases.
1 parent 602b895 commit e5d7afe

File tree

7 files changed

+147
-14
lines changed

7 files changed

+147
-14
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// name: ClassExtends1.mo
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
// Tests that basic class extends works.
7+
//
8+
9+
model A
10+
replaceable model B
11+
Real x = 1.0;
12+
end B;
13+
14+
B b;
15+
end A;
16+
17+
model ClassExtends1
18+
extends A;
19+
20+
redeclare model extends B
21+
Real y = 2.0;
22+
end B;
23+
24+
B b2;
25+
end ClassExtends1;
26+
27+
// Result:
28+
// class ClassExtends1
29+
// Real b.x = 1.0;
30+
// Real b.y = 2.0;
31+
// Real b2.x = 1.0;
32+
// Real b2.y = 2.0;
33+
// end ClassExtends1;
34+
// endResult

flattening/modelica/scodeinst/classextends1.mo renamed to flattening/modelica/scodeinst/ClassExtends2.mo

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// name: classextends1.mo
1+
// name: ClassExtends2.mo
22
// keywords:
33
// status: correct
4-
// cflags: -d=newInst
4+
// cflags: -d=newInst
5+
//
6+
// Checks that class extends without redeclare works, although with a warning
7+
// since it was deprecated in Modelica 3.4.
58
//
69

710
model A
@@ -17,7 +20,7 @@ model A
1720
M2 m2_a;
1821
end A;
1922

20-
model B
23+
model ClassExtends2
2124
extends A;
2225

2326
model extends M1
@@ -30,10 +33,10 @@ model B
3033

3134
M1 m1_b;
3235
M2 m2_b;
33-
end B;
36+
end ClassExtends2;
3437

3538
// Result:
36-
// class B
39+
// class ClassExtends2
3740
// Real m1_a.x;
3841
// Real m1_a.y;
3942
// Real m2_a.x;
@@ -42,5 +45,7 @@ end B;
4245
// Real m1_b.y;
4346
// Real m2_b.x;
4447
// Real m2_b.y;
45-
// end B;
48+
// end ClassExtends2;
49+
// [flattening/modelica/scodeinst/ClassExtends2.mo:26:3-28:9:writable] Warning: Missing redeclare prefix on class extends M1, treating like redeclare anyway.
50+
//
4651
// endResult

flattening/modelica/scodeinst/classextends2.mo renamed to flattening/modelica/scodeinst/ClassExtends3.mo

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// name: classextends2.mo
1+
// name: ClassExtends3
22
// keywords:
33
// status: correct
4-
// cflags: -d=newInst
4+
// cflags: -d=newInst
5+
//
6+
// Checks that modifiers on class extends are applied.
57
//
68

79
model A
@@ -17,7 +19,7 @@ model A
1719
M2 m2_a;
1820
end A;
1921

20-
model B
22+
model ClassExtends3
2123
extends A;
2224

2325
model extends M1(x = 2.0)
@@ -30,10 +32,10 @@ model B
3032

3133
M1 m1_b;
3234
M2 m2_b;
33-
end B;
35+
end ClassExtends3;
3436

3537
// Result:
36-
// class B
38+
// class ClassExtends3
3739
// Real m1_a.x = 2.0;
3840
// Real m1_a.y;
3941
// Real m2_a.x = 3.0;
@@ -42,5 +44,7 @@ end B;
4244
// Real m1_b.y;
4345
// Real m2_b.x = 3.0;
4446
// Real m2_b.y;
45-
// end B;
47+
// end ClassExtends3;
48+
// [flattening/modelica/scodeinst/ClassExtends3.mo:25:3-27:9:writable] Warning: Missing redeclare prefix on class extends M1, treating like redeclare anyway.
49+
//
4650
// endResult
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// name: ClassExtendsBuiltin1.mo
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model A
8+
model B
9+
Real x;
10+
end B;
11+
end A;
12+
13+
model ClassExtendsBuiltin1
14+
extends A;
15+
16+
redeclare model extends B
17+
extends Real;
18+
Real y = 2.0;
19+
end B;
20+
21+
B x;
22+
end ClassExtendsBuiltin1;
23+
24+
// Result:
25+
// Error processing file: ClassExtendsBuiltin1.mo
26+
// [flattening/modelica/scodeinst/ClassExtendsBuiltin1.mo:17:5-17:17:writable] Error: A class extending from builtin type Real may not have other elements.
27+
//
28+
// # Error encountered! Exiting...
29+
// # Please check the error message and the flags.
30+
//
31+
// Execution failed!
32+
// endResult
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// name: ClassExtendsBuiltin2.mo
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
7+
model A
8+
type MyReal = Real;
9+
end A;
10+
11+
model ClassExtendsBuiltin2
12+
extends A;
13+
14+
redeclare model extends MyReal
15+
Real y = 2.0;
16+
end MyReal;
17+
18+
MyReal x;
19+
end ClassExtendsBuiltin2;
20+
21+
// Result:
22+
// Error processing file: ClassExtendsBuiltin2.mo
23+
// [flattening/modelica/scodeinst/ClassExtendsBuiltin2.mo:14:13-16:13:writable] Error: A class extending from builtin type MyReal may not have other elements.
24+
//
25+
// # Error encountered! Exiting...
26+
// # Please check the error message and the flags.
27+
//
28+
// Execution failed!
29+
// endResult
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// name: ClassExtends1.mo
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that a proper error message is given when no inherited element is found for a class extends.
7+
//
8+
9+
model ClassExtendsMissing1
10+
redeclare model extends B
11+
Real y = 2.0;
12+
end B;
13+
14+
B b;
15+
end ClassExtendsMissing1;
16+
17+
// Result:
18+
// Error processing file: ClassExtendsMissing1.mo
19+
// [flattening/modelica/scodeinst/ClassExtendsMissing1.mo:10:13-12:8:writable] Error: Base class targeted by class extends B not found in the inherited classes.
20+
//
21+
// # Error encountered! Exiting...
22+
// # Please check the error message and the flags.
23+
//
24+
// Execution failed!
25+
// endResult

flattening/modelica/scodeinst/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ ceval3.mo \
1717
ceval5.mo \
1818
ceval6.mo \
1919
ClassAsComponentError.mo \
20+
ClassExtends1.mo \
21+
ClassExtends2.mo \
22+
ClassExtends3.mo \
23+
ClassExtendsBuiltin1.mo \
24+
ClassExtendsBuiltin2.mo \
25+
ClassExtendsMissing1.mo \
2026
ClassMod1.mo \
2127
ClassMod2.mo \
2228
CompAsFunc.mo \
@@ -203,8 +209,6 @@ DuplicateElements6.mo \
203209
DuplicateElements7.mo \
204210
DuplicateElements8.mo \
205211
DuplicateElementsValid2.mo \
206-
classextends1.mo \
207-
classextends2.mo \
208212
classextends3.mo \
209213
ModClass2.mo \
210214
ModClass4.mo \

0 commit comments

Comments
 (0)