mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8199762: JShell API: Failed to detect override when snippet to be overridden has been changed before
Reviewed-by: rfield
This commit is contained in:
parent
c003e3af3b
commit
4b6cd06e3d
3 changed files with 30 additions and 16 deletions
|
@ -42,7 +42,7 @@ import jdk.jshell.Key.MethodKey;
|
||||||
public class MethodSnippet extends DeclarationSnippet {
|
public class MethodSnippet extends DeclarationSnippet {
|
||||||
|
|
||||||
final String signature;
|
final String signature;
|
||||||
private String qualifiedParamaterTypes;
|
private String qualifiedParameterTypes;
|
||||||
|
|
||||||
MethodSnippet(MethodKey key, String userSource, Wrap guts,
|
MethodSnippet(MethodKey key, String userSource, Wrap guts,
|
||||||
String name, String signature, Wrap corralled,
|
String name, String signature, Wrap corralled,
|
||||||
|
@ -90,10 +90,10 @@ public class MethodSnippet extends DeclarationSnippet {
|
||||||
}
|
}
|
||||||
|
|
||||||
String qualifiedParameterTypes() {
|
String qualifiedParameterTypes() {
|
||||||
return qualifiedParamaterTypes;
|
return qualifiedParameterTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setQualifiedParamaterTypes(String sig) {
|
void setQualifiedParameterTypes(String sig) {
|
||||||
qualifiedParamaterTypes = sig;
|
qualifiedParameterTypes = sig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,12 +397,10 @@ final class Unit {
|
||||||
if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent);
|
if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent);
|
||||||
|
|
||||||
// Defined methods can overwrite methods of other (equivalent) snippets
|
// Defined methods can overwrite methods of other (equivalent) snippets
|
||||||
if (isNew && si.kind() == Kind.METHOD && status.isDefined()) {
|
if (si.kind() == Kind.METHOD && status.isDefined()) {
|
||||||
MethodSnippet msi = (MethodSnippet)si;
|
MethodSnippet msi = (MethodSnippet) si;
|
||||||
String oqpt = msi.qualifiedParameterTypes();
|
msi.setQualifiedParameterTypes(
|
||||||
String nqpt = computeQualifiedParameterTypes(at, msi);
|
computeQualifiedParameterTypes(at, msi));
|
||||||
if (!nqpt.equals(oqpt)) {
|
|
||||||
msi.setQualifiedParamaterTypes(nqpt);
|
|
||||||
Status overwrittenStatus = overwriteMatchingMethod(msi);
|
Status overwrittenStatus = overwriteMatchingMethod(msi);
|
||||||
if (overwrittenStatus != null) {
|
if (overwrittenStatus != null) {
|
||||||
prevStatus = overwrittenStatus;
|
prevStatus = overwrittenStatus;
|
||||||
|
@ -410,7 +408,6 @@ final class Unit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check if there is a method whose user-declared parameter types are
|
// Check if there is a method whose user-declared parameter types are
|
||||||
// different (and thus has a different snippet) but whose compiled parameter
|
// different (and thus has a different snippet) but whose compiled parameter
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8080357 8167643 8187359
|
* @bug 8080357 8167643 8187359 8199762
|
||||||
* @summary Tests for EvaluationState.methods
|
* @summary Tests for EvaluationState.methods
|
||||||
* @build KullaTesting TestingInputStream ExpectedDiagnostic
|
* @build KullaTesting TestingInputStream ExpectedDiagnostic
|
||||||
* @run testng MethodsTest
|
* @run testng MethodsTest
|
||||||
|
@ -199,6 +199,23 @@ public class MethodsTest extends KullaTesting {
|
||||||
assertActiveKeys();
|
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() {
|
public void methodsErrors() {
|
||||||
assertDeclareFail("String f();",
|
assertDeclareFail("String f();",
|
||||||
new ExpectedDiagnostic("compiler.err.missing.meth.body.or.decl.abstract", 0, 11, 7, -1, -1, Diagnostic.Kind.ERROR));
|
new ExpectedDiagnostic("compiler.err.missing.meth.body.or.decl.abstract", 0, 11, 7, -1, -1, Diagnostic.Kind.ERROR));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue