8199762: JShell API: Failed to detect override when snippet to be overridden has been changed before

Reviewed-by: rfield
This commit is contained in:
Shinya Yoshida 2018-03-24 14:43:04 +09:00
parent c003e3af3b
commit 4b6cd06e3d
3 changed files with 30 additions and 16 deletions

View File

@ -42,7 +42,7 @@ import jdk.jshell.Key.MethodKey;
public class MethodSnippet extends DeclarationSnippet {
final String signature;
private String qualifiedParamaterTypes;
private String qualifiedParameterTypes;
MethodSnippet(MethodKey key, String userSource, Wrap guts,
String name, String signature, Wrap corralled,
@ -90,10 +90,10 @@ public class MethodSnippet extends DeclarationSnippet {
}
String qualifiedParameterTypes() {
return qualifiedParamaterTypes;
return qualifiedParameterTypes;
}
void setQualifiedParamaterTypes(String sig) {
qualifiedParamaterTypes = sig;
void setQualifiedParameterTypes(String sig) {
qualifiedParameterTypes = sig;
}
}

View File

@ -397,17 +397,14 @@ final class Unit {
if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent);
// Defined methods can overwrite methods of other (equivalent) snippets
if (isNew && si.kind() == Kind.METHOD && status.isDefined()) {
MethodSnippet msi = (MethodSnippet)si;
String oqpt = msi.qualifiedParameterTypes();
String nqpt = computeQualifiedParameterTypes(at, msi);
if (!nqpt.equals(oqpt)) {
msi.setQualifiedParamaterTypes(nqpt);
Status overwrittenStatus = overwriteMatchingMethod(msi);
if (overwrittenStatus != null) {
prevStatus = overwrittenStatus;
signatureChanged = true;
}
if (si.kind() == Kind.METHOD && status.isDefined()) {
MethodSnippet msi = (MethodSnippet) si;
msi.setQualifiedParameterTypes(
computeQualifiedParameterTypes(at, msi));
Status overwrittenStatus = overwriteMatchingMethod(msi);
if (overwrittenStatus != null) {
prevStatus = overwrittenStatus;
signatureChanged = true;
}
}
}

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8080357 8167643 8187359
* @bug 8080357 8167643 8187359 8199762
* @summary Tests for EvaluationState.methods
* @build KullaTesting TestingInputStream ExpectedDiagnostic
* @run testng MethodsTest
@ -199,6 +199,23 @@ public class MethodsTest extends KullaTesting {
assertActiveKeys();
}
// 8199762
public void methodsRedeclaration5() {
Snippet m1 = methodKey(assertEval("int m(Object o) { return 10; }"));
assertMethods(method("(Object)int", "m"));
Snippet m2 = methodKey(assertEval("int m(Object o) { return 30; }",
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(m1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
assertEval("<T> int m(T o) { return 30; }",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(m2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertMethods(method("(T)int", "m"));
assertEval("m(null)", "30");
assertActiveKeys();
}
public void methodsErrors() {
assertDeclareFail("String f();",
new ExpectedDiagnostic("compiler.err.missing.meth.body.or.decl.abstract", 0, 11, 7, -1, -1, Diagnostic.Kind.ERROR));