Commit c53817ab authored by Miklos Magyari's avatar Miklos Magyari
Browse files

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


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent a7b20cdd
...@@ -223,6 +223,10 @@ type class ClassWithPrivate { ...@@ -223,6 +223,10 @@ type class ClassWithPrivate {
public function f_override4() { public function f_override4() {
} }
function f_override5() {
}
} }
type class ClassWithPrivateExt extends ClassWithPrivate { type class ClassWithPrivateExt extends ClassWithPrivate {
...@@ -239,6 +243,8 @@ type class ClassWithPrivateExt extends ClassWithPrivate { ...@@ -239,6 +243,8 @@ type class ClassWithPrivateExt extends ClassWithPrivate {
} }
function f_override4() { } function f_override4() { }
private function f_override5() { }
} }
// function with class parameter // function with class parameter
......
...@@ -56,6 +56,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -56,6 +56,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
public static final String FORMALPARAMSDIFFER = "Formal parameter list differs from previous definition"; 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 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 PUBLICOVERRIDEPUBLIC = "Public method can only be overriden by a public method";
public static final String PROTECTEDOVERRIDE = "Protected method can only be overriden by a public or protected method";
public static final String TRAITMETHODSONLY = "Trait classes can only declare methods"; public static final String TRAITMETHODSONLY = "Trait classes can only declare methods";
public static final String TRAITMETHODHASBODY = "Trait method cannot have a function body"; public static final String TRAITMETHODHASBODY = "Trait method cannot have a function body";
...@@ -255,6 +256,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -255,6 +256,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
if (modifier == VisibilityModifier.Public && localDefinition.getVisibilityModifier() != VisibilityModifier.Public) { if (modifier == VisibilityModifier.Public && localDefinition.getVisibilityModifier() != VisibilityModifier.Public) {
localDefinition.getIdentifier().getLocation().reportSemanticError(PUBLICOVERRIDEPUBLIC); localDefinition.getIdentifier().getLocation().reportSemanticError(PUBLICOVERRIDEPUBLIC);
} }
if (modifier == VisibilityModifier.Protected) {
final VisibilityModifier mod = localDefinition.getVisibilityModifier();
if (mod != VisibilityModifier.Protected && mod != VisibilityModifier.Public) {
localDefinition.getIdentifier().getLocation().reportSemanticError(PROTECTEDOVERRIDE);
}
}
} }
} else { } else {
localDefinition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format( localDefinition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(
......
...@@ -45,7 +45,7 @@ public class OOP_Semantic_tests { ...@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() { private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn //oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(54); ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(55);
int lineNum = 28; int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10; lineNum += 10;
...@@ -107,12 +107,14 @@ public class OOP_Semantic_tests { ...@@ -107,12 +107,14 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", ++lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", ++lineNum, IMarker.SEVERITY_ERROR));
lineNum += 19; lineNum += 19;
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 15; lineNum += 19;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3; lineNum += 3;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4; lineNum += 4;
markersToCheck.add(new MarkerToCheck("Public method can only be overriden by a public method", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Public method can only be overriden by a public method", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Protected method can only be overriden by a public or protected method", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 5; lineNum += 5;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 6; lineNum += 6;
......
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