Commit 8e163ab4 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - public method can be only overriden as public (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 134b3e1b
......@@ -211,6 +211,10 @@ type class ClassWithPrivate {
public function f_override3(in float pl_float) return integer {
return 1;
}
public function f_override4() {
}
}
type class ClassWithPrivateExt extends ClassWithPrivate {
......@@ -225,6 +229,8 @@ type class ClassWithPrivateExt extends ClassWithPrivate {
public function f_override3(charstring pl_chr) return charstring {
return pl_chr;
}
function f_override4() { }
}
// function with class parameter
......
......@@ -55,6 +55,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
public static final String HIDINGMODULEIDENTIFIER = "Inherited definition with name `{0}'' hides a module identifier";
public static final String FORMALPARAMSDIFFER = "Formal parameter list differs from previous definition";
public static final String OVERRIDDENFORMALPARAM = "Definition is overridden with different formal parameters";
public static final String PUBLICOVERRIDEPUBLIC = "Public method can only be overriden by a public method";
public static final String TRAITMETHODSONLY = "Trait classes can only declare methods";
public static final String TRAITMETHODHASBODY = "Trait method cannot have a function body";
......@@ -251,6 +252,9 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
localDefinition.getIdentifier().getLocation().reportSemanticError(FORMALPARAMSDIFFER);
definition.getIdentifier().getLocation().reportSemanticError(OVERRIDDENFORMALPARAM);
}
if (modifier == VisibilityModifier.Public && localDefinition.getVisibilityModifier() != VisibilityModifier.Public) {
localDefinition.getIdentifier().getLocation().reportSemanticError(PUBLICOVERRIDEPUBLIC);
}
}
} else {
localDefinition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(44);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(45);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
......@@ -100,11 +100,13 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
lineNum += 14;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 7;
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Public method can only be overriden by a public method", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 5;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 6;
markersToCheck.add(new MarkerToCheck("Class functions cannot have a `runs on` clause", 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