Commit 38497d6e authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - a trait class can only extends a trait class (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 01bf6283
......@@ -38,6 +38,10 @@ type class BadExtends extends MinimalClass, MinimalAbstractClass, MinimalFinalCl
// dummy
}
type class @trait BadExtends2 extends MinimalFinalClass, MinimalTraitClass {
// dummy
}
type class SuperClass {
var integer vl_a;
template MyUnion t_union := { a := 10 }
......
......@@ -34,6 +34,9 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
* */
public final class ClassTypeReferenceList extends ASTNode implements ILocateableNode, IIncrementallyUpdateable {
private final String ONLYONNONTRAIT = "A class can only extend one non-trait class";
private final String TRAITEXTENDSTRAIT = "A trait class can only extend trait classes";
private Class_Type parentClass;
private final List<Reference> classReferences;
private Location location;
......@@ -50,6 +53,10 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
reference.setFullNameParent(this);
}
public void setParentClass(Class_Type parentClass) {
this.parentClass = parentClass;
}
public List<ClassTypeBody> getClassBodies() {
return orderedClassTypeBodies;
}
......@@ -87,8 +94,14 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
final Class_Type extClass = (Class_Type)type;
if (! extClass.isTrait()) {
nrNonTraitExtends++;
if (nrNonTraitExtends > 1) {
classRef.getLocation().reportSemanticError(ONLYONNONTRAIT);
if (parentClass.isTrait()) {
classRef.getLocation().reportSemanticError(TRAITEXTENDSTRAIT);
parentClass.setIsErroneous(true);
} else {
if (nrNonTraitExtends > 1) {
classRef.getLocation().reportSemanticError(ONLYONNONTRAIT);
parentClass.setIsErroneous(true);
}
}
}
}
......
......@@ -9035,6 +9035,9 @@ pr_ClassTypeDef returns[Def_Type def_type]
body = new ClassTypeBody($i.identifier, refs);
}
Type type = new Class_Type(body, isAbstract, isFinal, isTrait, getLocation($kw.stop, $i.start), finallyBlock);
if (refs != null) {
refs.setParentClass((Class_Type)type);
}
type.setLocation(getLocation($start, getLastVisibleToken()));
$def_type = new Def_Type($i.identifier, type);
$def_type.setLocation(getLocation($kw.start, $i.stop));
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(21);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(22);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 9;
......@@ -53,6 +53,8 @@ public class OOP_Semantic_tests {
for (i = 0; i < 2; i++) {
markersToCheck.add(new MarkerToCheck("A class can only extend one non-trait class", lineNum, IMarker.SEVERITY_ERROR));
}
lineNum += 4;
markersToCheck.add(new MarkerToCheck("A trait class can only extend trait classes", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 15;
markersToCheck.add(new MarkerToCheck("Reference to non-existent field `nonexist' in union template for type `@classesNegativeSemantic.MyUnion'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
......@@ -85,7 +87,6 @@ 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));
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