Commit 134b3e1b authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - duplicate references in the 'extends' list (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 1291d980
......@@ -30,6 +30,7 @@ type class BadInheritance extends MyUnion {
}
type class MinimalClass { }
type class @trait BaseClass { }
type class @abstract MinimalAbstractClass { }
type class @final MinimalFinalClass { }
type class @trait MinimalTraitClass { }
......@@ -46,6 +47,10 @@ type class BadExtends3 extends MinimalFinalClass {
}
type class RepeatedExtends extends MinimalClass, BaseClass, MinimalClass {
}
type class @trait BadTraitClass {
public var integer m_int := 0;
public timer Timer;
......
......@@ -9,6 +9,7 @@ package org.eclipse.titan.designer.AST.TTCN3.types;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -36,6 +37,8 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
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 final String FINALCANNOTBEEXTENDED = "A final class cannot be extended";
private final String DUPLICATECOMPONENTREFERENCEFIRST = "Duplicate reference to class `{0}'' was first declared here";
private final String DUPLICATECOMPONENTREFERENCEREPEATED = "Duplicate reference to class `{0}'' was declared here again";
private Class_Type parentClass;
......@@ -144,10 +147,10 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
if (classTypeBody != null) {
if (classTypeBodies.containsKey(classTypeBody)) {
classTypeBodies.get(classTypeBody).getId().getLocation().reportSingularSemanticError(
MessageFormat.format(ComponentTypeReferenceList.DUPLICATECOMPONENTREFERENCEFIRST, classTypeBody.getIdentifier()
MessageFormat.format(DUPLICATECOMPONENTREFERENCEFIRST, classTypeBody.getIdentifier()
.getDisplayName()));
reference.getLocation().reportSemanticError(
MessageFormat.format(ComponentTypeReferenceList.DUPLICATECOMPONENTREFERENCEREPEATED, reference.getDisplayName()));
MessageFormat.format(DUPLICATECOMPONENTREFERENCEREPEATED, reference.getDisplayName()));
} else {
classTypeBodies.put(classTypeBody, reference);
orderedClassTypeBodies.add(classTypeBody);
......
......@@ -45,10 +45,10 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(41);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(44);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 9;
lineNum += 10;
int i = 0;
for (i = 0; i < 2; i++) {
markersToCheck.add(new MarkerToCheck("A class can only extend one non-trait class", lineNum, IMarker.SEVERITY_ERROR));
......@@ -58,6 +58,10 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("A trait class can only extend trait classes", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("A final class cannot be extended", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("A class can only extend one non-trait class", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Duplicate reference to class `MinimalClass' was declared here again", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Duplicate reference to class `MinimalClass' was first declared here", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 5;
for (i = 0; i < 2; i++) {
markersToCheck.add(new MarkerToCheck("Trait classes can only declare methods", lineNum++, IMarker.SEVERITY_ERROR));
......
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