Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NF] Added partial function application tests.
Belonging to [master]: - OpenModelica/OMCompiler#2797 - OpenModelica/OpenModelica-testsuite#1080
- Loading branch information
1 parent
a3d1bab
commit e980f70
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
44
flattening/modelica/scodeinst/PartialApplicationInvalidArg1.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
41
flattening/modelica/scodeinst/PartialApplicationInvalidArg2.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |