Skip to content

Commit

Permalink
[NF] Add functional argument tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 5, 2018
1 parent 88e51f6 commit ba472c6
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
46 changes: 46 additions & 0 deletions flattening/modelica/scodeinst/FunctionalArg1.mo
@@ -0,0 +1,46 @@
// name: FunctionalArg1
// keywords:
// status: correct
// cflags: -d=newInst
//

partial function F
input Real x;
output Real y;
end F;

function f1
input F f;
input Real x;
output Real y;
algorithm
y := f(x);
end f1;

function f2
input Real x;
output Real y = x * 2;
end f2;

model FunctionalArg1
Real x = f1(f2, 1);
end FunctionalArg1;

// Result:
// function f1
// input f<function>(#Real x) => #Real f;
// input Real x;
// output Real y;
// algorithm
// y := unbox(f(#(x)));
// end f1;
//
// function f2
// input Real x;
// output Real y = x * 2.0;
// end f2;
//
// class FunctionalArg1
// Real x = f1(f2, 1.0);
// end FunctionalArg1;
// endResult
48 changes: 48 additions & 0 deletions flattening/modelica/scodeinst/FunctionalArg2.mo
@@ -0,0 +1,48 @@
// name: FunctionalArg2
// keywords:
// status: correct
// cflags: -d=newInst
//

partial function F
input Real x;
output Real y;
end F;

function f1
input F f;
input Real x;
output Real y;
algorithm
y := f(x);
end f1;

function f2
input Real x;
input Real z = 1.0;
output Real y = x * 2;
end f2;

model FunctionalArg2
Real x = f1(f2, 1);
end FunctionalArg2;

// Result:
// function f1
// input f<function>(#Real x) => #Real f;
// input Real x;
// output Real y;
// algorithm
// y := unbox(f(#(x)));
// end f1;
//
// function f2
// input Real x;
// input Real z = 1.0;
// output Real y = x * 2.0;
// end f2;
//
// class FunctionalArg2
// Real x = f1(f2, 1.0);
// end FunctionalArg2;
// endResult
40 changes: 40 additions & 0 deletions flattening/modelica/scodeinst/FunctionalArgInvalidType1.mo
@@ -0,0 +1,40 @@
// name: FunctionalArgInvalidType1
// keywords:
// status: incorrect
// cflags: -d=newInst
//

partial function F
input Real x;
output Real y;
end F;

function f1
input F f;
input Real x;
output Real y;
algorithm
y := f(x);
end f1;

function f2
input Integer x;
output Integer y = x * 2;
end f2;

model FunctionalArgInvalidType1
Real x = f1(f2, 1);
end FunctionalArgInvalidType1;

// Result:
// Error processing file: FunctionalArgInvalidType1.mo
// [flattening/modelica/scodeinst/FunctionalArgInvalidType1.mo:26:3-26:21:writable] Error: Type mismatch for positional argument 1 in f1(f=f2). The argument has type:
// f2<function>(Integer) => Integer
// expected type:
// f<function>(#Real) => #Real
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
3 changes: 3 additions & 0 deletions flattening/modelica/scodeinst/Makefile
Expand Up @@ -471,6 +471,9 @@ FuncVectorizationCastConflict1.mo \
FuncVectorizationMap1.mo \
FuncWildcard.mo \
FuncWrongType.mo \
FunctionalArg1.mo \
FunctionalArg2.mo \
FunctionalArgInvalidType1.mo \
FunctionDerivative1.mo \
FunctionDerivativeInvalidInput1.mo \
FunctionDerivativeInvalidOrder1.mo \
Expand Down

0 comments on commit ba472c6

Please sign in to comment.