Skip to content

Commit c511dae

Browse files
perostOpenModelica-Hudson
authored andcommitted
Updated nfinst function tests.
1 parent f30ef94 commit c511dae

23 files changed

+478
-144
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// name: CompAsFunc.mo
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that a proper error message is given when trying to use a component as
7+
// a function.
8+
//
9+
10+
model CompAsFunc
11+
Real x;
12+
Real y = x(2);
13+
end CompAsFunc;
14+
15+
// Result:
16+
// Error processing file: CompAsFunc.mo
17+
// [flattening/modelica/scodeinst/CompAsFunc.mo:12:3-12:16:writable] Error: Expected x to be a function, but found component instead.
18+
//
19+
// # Error encountered! Exiting...
20+
// # Please check the error message and the flags.
21+
//
22+
// Execution failed!
23+
// endResult
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// name: FuncBuiltin
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
// Tests some builtin functions.
7+
//
8+
9+
model FuncBuiltin
10+
Real r1 = abs(-2.0);
11+
Integer r2 = abs(3);
12+
end FuncBuiltin;
13+
14+
// Result:
15+
// class FuncBuiltin
16+
// Real r1 = abs(-2.0);
17+
// Integer r2 = abs(3);
18+
// end FuncBuiltin;
19+
// endResult
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// name: FuncClassParam
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that function parameters are not allowed to be e.g. models.
7+
//
8+
9+
model A
10+
Real x;
11+
end A;
12+
13+
function f
14+
input A a;
15+
output Real x;
16+
algorithm
17+
x := a.x;
18+
end f;
19+
20+
model FuncClassParam
21+
A a;
22+
Real x = f(a);
23+
end FuncClassParam;
24+
25+
// Result:
26+
// Error processing file: FuncClassParam.mo
27+
// [flattening/modelica/scodeinst/FuncClassParam.mo:14:3-14:12:writable] Error: Invalid type A for function component a.
28+
//
29+
// # Error encountered! Exiting...
30+
// # Please check the error message and the flags.
31+
//
32+
// Execution failed!
33+
// endResult
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// name: FuncExtends
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
7+
function f
8+
input Real x;
9+
end f;
10+
11+
function f2
12+
extends f;
13+
output Real y = x;
14+
end f2;
15+
16+
model M
17+
Real x = f2(1.0);
18+
end M;
19+
20+
// Result:
21+
// function f2
22+
// input Real x;
23+
// output Real y = x;
24+
// end f2;
25+
//
26+
// class M
27+
// Real x = f2(1.0);
28+
// end M;
29+
// endResult
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// name: FuncInnerParam
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that inner is not a valid function parameter prefix.
7+
//
8+
9+
model FuncInnerParam
10+
function f
11+
inner input Real x;
12+
output Real y;
13+
algorithm
14+
y := x;
15+
end f;
16+
17+
Real x = f(x);
18+
end FuncInnerParam;
19+
20+
// Result:
21+
// Error processing file: FuncInnerParam.mo
22+
// [flattening/modelica/scodeinst/FuncInnerParam.mo:11:5-11:23:writable] Error: Invalid prefix inner on formal parameter x.
23+
//
24+
// # Error encountered! Exiting...
25+
// # Please check the error message and the flags.
26+
//
27+
// Execution failed!
28+
// endResult
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// name: FuncInteger
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
// Checks that the Integer function works.
7+
//
8+
9+
model FuncInteger
10+
type E = enumeration(one, two, three);
11+
E e = E.two;
12+
13+
Integer i = Integer(E.one);
14+
Integer j = Integer(e);
15+
end FuncInteger;
16+
17+
// Result:
18+
// class FuncInteger
19+
// enumeration(one, two, three) e = E.two;
20+
// Integer i = Integer(E.one);
21+
// Integer j = Integer(e);
22+
// end FuncInteger;
23+
// endResult
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// name: FuncIntegerWrongType
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that type checking works for Integer.
7+
//
8+
9+
model FuncIntegerWrongType
10+
Integer i = Integer(1.0);
11+
end FuncIntegerWrongType;
12+
13+
// Result:
14+
// Error processing file: FuncIntegerWrongType.mo
15+
// [flattening/modelica/scodeinst/FuncIntegerWrongType.mo:10:3-10:27:writable] Error: Type mismatch for positional argument 1 in Integer(e=1). The argument has type:
16+
// Real
17+
// expected type:
18+
// enumeration(:)
19+
//
20+
// # Error encountered! Exiting...
21+
// # Please check the error message and the flags.
22+
//
23+
// Execution failed!
24+
// endResult
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// name: FuncLocals
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
// Checks that functions can have local parameters.
7+
//
8+
9+
function f
10+
input Real x;
11+
output Real y;
12+
protected
13+
parameter Real z = 2.0;
14+
algorithm
15+
y := x * z;
16+
end f;
17+
18+
model FuncLocals
19+
Real x = f(4.0);
20+
end FuncLocals;
21+
22+
// Result:
23+
// function f
24+
// input Real x;
25+
// output Real y;
26+
// protected parameter Real z = 2.0;
27+
// algorithm
28+
// y := x * z;
29+
// end f;
30+
//
31+
// class FuncLocals
32+
// Real x = f(4.0);
33+
// end FuncLocals;
34+
// endResult
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// name: FuncMissingDefault1
2+
// keywords:
3+
// status: incorrect
4+
// cflags: -d=newInst
5+
//
6+
// Checks that missing default arguments are detected.
7+
//
8+
9+
function f
10+
input Real x;
11+
input Real y;
12+
output Real z = x + y;
13+
end f;
14+
15+
model M
16+
Real x = f(1.0);
17+
end M;
18+
19+
// Result:
20+
// Error processing file: FuncMissingDefault1.mo
21+
// [flattening/modelica/scodeinst/FuncMissingDefault1.mo:16:3-16:18:writable] Error: Function parameter y was not given by the function call, and does not have a default value.
22+
//
23+
// # Error encountered! Exiting...
24+
// # Please check the error message and the flags.
25+
//
26+
// Execution failed!
27+
// endResult
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// name: FuncMissingDefault2
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
// Checks that a warning is given when a parameter that doesn't have a default
7+
// argument is after a parameter that does.
8+
//
9+
10+
function f
11+
input Real x;
12+
input Real y = 1.0;
13+
input Real z;
14+
output Real w = x + y + z;
15+
end f;
16+
17+
model M
18+
Real x = f(1.0, 2.0, 3.0);
19+
end M;
20+
21+
// Result:
22+
// function f
23+
// input Real x;
24+
// input Real y = 1.0;
25+
// input Real z;
26+
// output Real w = x + y + z;
27+
// end f;
28+
//
29+
// class M
30+
// Real x = f(1.0, 2.0, 3.0);
31+
// end M;
32+
// [flattening/modelica/scodeinst/FuncMissingDefault2.mo:13:3-13:15:writable] Warning: Missing default argument on function parameter z.
33+
//
34+
// endResult

0 commit comments

Comments
 (0)