mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-16 10:53:31 +00:00
6987475: Order of declarations affects whether abstract method considered overridden
Types.implementation erroneously returns first matching method in hierarchy. Reviewed-by: vromero
This commit is contained in:
parent
c4f3406133
commit
ded3a562b9
@ -2677,10 +2677,19 @@ public class Types {
|
||||
while (t.hasTag(TYPEVAR))
|
||||
t = t.getUpperBound();
|
||||
TypeSymbol c = t.tsym;
|
||||
Symbol bestSoFar = null;
|
||||
for (Symbol sym : c.members().getSymbolsByName(ms.name, implFilter)) {
|
||||
if (sym != null &&
|
||||
sym.overrides(ms, origin, Types.this, checkResult))
|
||||
return (MethodSymbol)sym;
|
||||
if (sym != null && sym.overrides(ms, origin, Types.this, checkResult)) {
|
||||
bestSoFar = sym;
|
||||
if ((sym.flags() & ABSTRACT) == 0) {
|
||||
//if concrete impl is found, exit immediately
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bestSoFar != null) {
|
||||
//return either the (only) concrete implementation or the first abstract one
|
||||
return (MethodSymbol)bestSoFar;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
29
langtools/test/tools/javac/generics/6987475/T6987475neg.java
Normal file
29
langtools/test/tools/javac/generics/6987475/T6987475neg.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 6987475
|
||||
*
|
||||
* @summary Order of declarations affects whether abstract method considered overridden
|
||||
* @compile/fail/ref=T6987475neg.out -XDrawDiagnostics T6987475neg.java
|
||||
*/
|
||||
|
||||
class T6987475neg {
|
||||
static abstract class Base<A> {
|
||||
public void go(String s) { }
|
||||
public abstract void go(A a);
|
||||
}
|
||||
|
||||
static abstract class BaseReverse<A> {
|
||||
public abstract void go(A a);
|
||||
public void go(String s) { }
|
||||
}
|
||||
|
||||
static abstract class Sub<A> extends Base<A> {
|
||||
public abstract void go(A a);
|
||||
}
|
||||
static abstract class SubReverse<A> extends BaseReverse<A> {
|
||||
public abstract void go(A a);
|
||||
}
|
||||
|
||||
static class Impl1 extends Sub<String> { }
|
||||
static class Impl2 extends SubReverse<String> { }
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
T6987475neg.java:27:12: compiler.err.does.not.override.abstract: T6987475neg.Impl1, go(java.lang.String), T6987475neg.Sub
|
||||
T6987475neg.java:28:12: compiler.err.does.not.override.abstract: T6987475neg.Impl2, go(java.lang.String), T6987475neg.SubReverse
|
||||
2 errors
|
||||
47
langtools/test/tools/javac/generics/6987475/T6987475pos.java
Normal file
47
langtools/test/tools/javac/generics/6987475/T6987475pos.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6987475
|
||||
*
|
||||
* @summary Order of declarations affects whether abstract method considered overridden
|
||||
* @compile T6987475pos.java
|
||||
*/
|
||||
|
||||
class T6987475pos {
|
||||
static abstract class Base<A> {
|
||||
public void go(String s) { }
|
||||
public abstract void go(A a);
|
||||
}
|
||||
|
||||
static abstract class BaseReverse<A> {
|
||||
public abstract void go(A a);
|
||||
public void go(String s) { }
|
||||
}
|
||||
|
||||
static class Impl1 extends Base<String> { }
|
||||
static class Impl2 extends BaseReverse<String> { }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user