Skip to content

Commit

Permalink
[NF] Added partial function application tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 23, 2018
1 parent a3d1bab commit e980f70
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flattening/modelica/scodeinst/Makefile
Expand Up @@ -636,6 +636,9 @@ OperatorOverloadConstructorSimple.mo \
OperatorOverloadError1.mo \
PackageConstant1.mo \
ParameterBug.mos \
PartialApplication1.mo \
PartialApplicationInvalidArg1.mo \
PartialApplicationInvalidArg2.mo \
Prefix1.mo \
Prefix2.mo \
Prefix3.mo \
Expand Down
50 changes: 50 additions & 0 deletions flattening/modelica/scodeinst/PartialApplication1.mo
@@ -0,0 +1,50 @@
// name: PartialApplication1
// keywords:
// status: correct
// cflags: -d=newInst
//

function f1
input Real x;
input Real y;
output Real z = x + y;
end f1;

partial function pf
input Real x;
output Real z;
end pf;

function f2
input Real x;
input pf func;
output Real z = x * func(x);
end f2;

function f3
input Real x;
output Real z = x;
end f3;

model PartialApplication1
Real x = f2(time, function f1(y = 2.0));
//Real x = f2(time, f3);
end PartialApplication1;

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

function f1
input Real x;
input Real y;
output Real z = x + y;
end f1;

partial function pf
input Real x;
output Real z;
end pf;

function f2
input Real x;
input pf func;
output Real z = x * func(x);
end f2;

function f3
input Real x;
output Real z = x;
end f3;

model PartialApplicationInvalidArg1
Real x = f2(time, function f1(y = "fish"));
end PartialApplicationInvalidArg1;

// Result:
// Error processing file: PartialApplicationInvalidArg1.mo
// [flattening/modelica/scodeinst/PartialApplicationInvalidArg1.mo:30:3-30:45:writable] Error: Type mismatch for named argument in f1(y="fish"). The argument has type:
// String
// expected type:
// Real
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
41 changes: 41 additions & 0 deletions flattening/modelica/scodeinst/PartialApplicationInvalidArg2.mo
@@ -0,0 +1,41 @@
// name: PartialApplicationInvalidArg2
// keywords:
// status: incorrect
// cflags: -d=newInst
//

function f1
input Real x;
input Real y;
output Real z = x + y;
end f1;

partial function pf
input Real x;
output Real z;
end pf;

function f2
input Real x;
input pf func;
output Real z = x * func(x);
end f2;

function f3
input Real x;
output Real z = x;
end f3;

model PartialApplicationInvalidArg2
Real x = f2(time, function f1(z = 2.0));
end PartialApplicationInvalidArg2;

// Result:
// Error processing file: PartialApplicationInvalidArg2.mo
// [flattening/modelica/scodeinst/PartialApplicationInvalidArg2.mo:30:3-30:42:writable] Error: Function f1 has no input parameter named z.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult

0 comments on commit e980f70

Please sign in to comment.