Skip to content

Commit

Permalink
Added tests for #3535.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 12, 2017
1 parent 12cc9eb commit 15a59b0
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 6 deletions.
23 changes: 23 additions & 0 deletions flattening/modelica/declarations/DoubleClassDeclaration1.mo
@@ -0,0 +1,23 @@
// name: DoubleClassDeclaration1.mo
// status: incorrect
//
// Checks that duplicate top-level classes are detected.
//

model M
end M;

model M
end M;

// Result:
// Error processing file: DoubleClassDeclaration1.mo
// [flattening/modelica/declarations/DoubleClassDeclaration1.mo:7:1-8:6:writable] Notification: From here:
// [flattening/modelica/declarations/DoubleClassDeclaration1.mo:10:1-11:6:writable] Error: An element with name M is already declared in this scope.
// Error: Error occurred while flattening model M
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
29 changes: 29 additions & 0 deletions flattening/modelica/declarations/DoubleClassDeclaration2.mo
@@ -0,0 +1,29 @@
// name: DoubleClassDeclaration2.mo
// status: incorrect
//
// Checks that duplicate classes are detected.
//

model M
model A
Real x;
end A;

model A
Real y;
end A;

A a;
end M;

// Result:
// Error processing file: DoubleClassDeclaration2.mo
// [flattening/modelica/declarations/DoubleClassDeclaration2.mo:8:3-10:8:writable] Notification: From here:
// [flattening/modelica/declarations/DoubleClassDeclaration2.mo:12:3-14:8:writable] Error: An element with name A is already declared in this scope.
// Error: Error occurred while flattening model M
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
31 changes: 31 additions & 0 deletions flattening/modelica/declarations/DoubleFuncDeclaration.mo
@@ -0,0 +1,31 @@
// name: DoubleFuncDeclaration.mo
// status: incorrect
//
// Checks that duplicate functions are detected.
//

model DoubleFuncDeclaration
function f
input Real x;
output Real y = x;
end f;

function f
input String x;
output String y = x;
end f;

Real x = f(1.0);
end DoubleFuncDeclaration;

// Result:
// Error processing file: DoubleFuncDeclaration.mo
// [flattening/modelica/declarations/DoubleFuncDeclaration.mo:8:3-11:8:writable] Notification: From here:
// [flattening/modelica/declarations/DoubleFuncDeclaration.mo:13:3-16:8:writable] Error: An element with name f is already declared in this scope.
// Error: Error occurred while flattening model DoubleFuncDeclaration
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
3 changes: 3 additions & 0 deletions flattening/modelica/declarations/Makefile
Expand Up @@ -37,6 +37,9 @@ DiscreteDeclConnector.mo \
DiscreteDeclRecord.mo \
DiscreteDeclType.mo \
DoubleDeclaration.mo \
DoubleClassDeclaration1.mo \
DoubleClassDeclaration2.mo \
DoubleFuncDeclaration.mo \
ErrorExternalModel.mo\
ErrorRecursionLimit.mo \
FloatingPoint.mo \
Expand Down
4 changes: 2 additions & 2 deletions openmodelica/interactive-API/interactive_api_calls.mo
Expand Up @@ -2,8 +2,8 @@ class C Real x; end C;
record B String name; Integer age; end B;
block Mul input Real x; output Real result; equation result = x; end Mul;
type vector3D = Real[3](each start = 5, nominal = {1, 2, 3, 4, 5});
function div input Real x; output Real result; algorithm result := x; end div;
type size = enumeration(Small, Medium, Large);
function f input Real x; output Real result; algorithm result := x; end f;
type sizeE = enumeration(Small, Medium, Large);
model M "A class comment" parameter Integer i = 1; Real r = 4 if i > 0 "A component comment"; end M;
model ReplaceableClass replaceable model M1 end M1; end ReplaceableClass;
connector RealSignal replaceable type SignalType = Real; extends SignalType; end RealSignal;
Expand Down
8 changes: 4 additions & 4 deletions openmodelica/interactive-API/interactive_api_calls.mos
Expand Up @@ -32,8 +32,8 @@ isShortDefinition(vector3D); getErrorString();
isShortDefinition(C); getErrorString();
isEnumeration(C); getErrorString();
getEnumerationLiterals(C); getErrorString();
isEnumeration(size); getErrorString();
getEnumerationLiterals(size); getErrorString();
isEnumeration(sizeE); getErrorString();
getEnumerationLiterals(sizeE); getErrorString();
isReplaceable(ReplaceableClass, "M1"); getErrorString();
isReplaceable(RealSignal, "SignalType"); getErrorString();
isProtectedClass(RealSignal, "SignalType"); getErrorString();
Expand Down Expand Up @@ -229,11 +229,11 @@ getMessagesStringInternal(unique = false); // not unique
// {}
// Evaluating: getErrorString()
// ""
// Evaluating: isEnumeration(size)
// Evaluating: isEnumeration(sizeE)
// true
// Evaluating: getErrorString()
// ""
// Evaluating: getEnumerationLiterals(size)
// Evaluating: getEnumerationLiterals(sizeE)
// {"Small","Medium","Large"}
// Evaluating: getErrorString()
// ""
Expand Down

0 comments on commit 15a59b0

Please sign in to comment.