Commit 74e53504 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: issue a warning if overridden formal param name differs


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 212ffaac
......@@ -48,12 +48,12 @@ type class BadExtends3 extends MinimalFinalClass {
}
type class RepeatedExtends extends MinimalClass, BaseClass, MinimalClass {
}
// self extend
type class @trait TC {}
type class AA extends DD, TC { }
type class AA extends DD, TC, DD { }
type class BB extends AA { }
type class CC extends BB { }
type class DD extends CC { }
......@@ -230,12 +230,12 @@ type class ClassWithPrivateExt extends ClassWithPrivate {
return pl_chr;
}
public function f_override2(charstring pl_chr) return charstring {
return pl_chr;
public function f_override2(in float pl_float) return charstring {
return pl_float;
}
public function f_override3(charstring pl_chr) return charstring {
return pl_chr;
public function f_override3(charstring pl_float) return charstring {
return pl_float;
}
function f_override4() { }
......
......@@ -921,10 +921,17 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
}
for (int i = 0; i < parameters.size(); i++) {
final FormalParameter localParam = parameters.get(i);
final FormalParameter prevParam = fpList.getParameterByIndex(i);
final FormalParameter prevParam = parameters.get(i);
final FormalParameter localParam = fpList.getParameterByIndex(i);
if (! localParam.getIdentifier().getName().equals(prevParam.getIdentifier().getName())) {
return false;
localParam.getLocation().reportSemanticWarning(
/*
* It is unclear in the standard if only the formal parameter types should match
* or also the names.
* Right now we issue a warning if the names differ.
*/
MessageFormat.format("Formal parameter name `{0}'' differs from previous name `{1}''",
localParam.getIdentifier().getName(), prevParam.getIdentifier().getName()));
}
if (localParam.getType(timestamp).getTypetype() != prevParam.getType(timestamp).getTypetype()) {
return false;
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(50);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(52);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
......@@ -63,7 +63,12 @@ public class OOP_Semantic_tests {
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 += 6;
for (i = 0; i < 5; i++) {
markersToCheck.add(new MarkerToCheck("A class cannot extend itself neither directly nor indirectly", lineNum, IMarker.SEVERITY_ERROR));
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 `DD' was declared here again", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Duplicate reference to class `DD' was first declared here", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 1;
for (i = 0; i < 4; i++) {
markersToCheck.add(new MarkerToCheck("A class cannot extend itself neither directly nor indirectly", lineNum++, IMarker.SEVERITY_ERROR));
}
lineNum += 2;
......@@ -100,13 +105,11 @@ public class OOP_Semantic_tests {
lineNum += 10;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `charstring'", 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 += 15;
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
lineNum += 19;
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 14;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
lineNum += 15;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Public method can only be overriden by a public method", 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