Commit 49d1e70d authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - abstract/trait classes cannot be instantiated (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent b402d6a5
......@@ -287,6 +287,10 @@ testcase tc_basicSyntax() runs on CT {
// nested class member reference
var octetstring vl_octet := vl_outer.NestedClass.InnerClass.EvenDeeper.Core.f_inside(1)
// instantiating abstract and trait classes is not allowed
var object vl_trait := MinimalTraitClass.create;
var MinimalAbstractClass vl_abstract := MinimalAbstractClass.create;
}
}
\ No newline at end of file
......@@ -54,6 +54,8 @@ public class UndefCreateExpression extends Expression_Value {
private static final String COMPONENTEXPECTED = "Operation `create'' should refer to a component type instead of {0}";
private static final String TYPEMISMATCH1 = "Type mismatch: reference to a component type was expected in operation `create'' instead of `{0}''";
private static final String TYPEMISMATCH2 = "Incompatible component type: operation `create'' should refer to `{0}'' instaed of `{1}''";
private static final String TRAITINSTANTIATED = "A trait class cannot be instantiated";
private static final String ABSTRACTINSTANTIATED = "An abstract class cannot be instantiated";
private static final String OPERATIONNAME = "create()";
private Reference componentReference;
......@@ -248,7 +250,20 @@ public class UndefCreateExpression extends Expression_Value {
realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false);
} else if (assignmentType instanceof Class_Type) {
final Class_Type classInstance = (Class_Type)assignmentType;
if (classInstance.isTrait()) {
getLocation().reportSemanticError(TRAITINSTANTIATED);
setIsErroneous(true);
}
if (classInstance.isAbstract()) {
getLocation().reportSemanticError(ABSTRACTINSTANTIATED);
setIsErroneous(true);
}
realExpression = new ClassConstructorExpression();
realExpression.setMyScope(getMyScope());
realExpression.setFullNameParent(this);
realExpression.setLocation(getLocation());
realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
// FIXME : implement
}
}
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(52);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(54);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
......@@ -132,6 +132,9 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("integer value was expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `octetstring' was expected instead of `charstring'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3;
markersToCheck.add(new MarkerToCheck("A trait class cannot be instantiated", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("An abstract class cannot be instantiated", ++lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment