提交 76303e0f 编写于 作者: M mcimadamore

7034019: ClassCastException in javac with conjunction types

Summary: Resolve.mostSpecific doesn't handle case of raw override
Reviewed-by: dlsmith
上级 8eaf586c
......@@ -770,12 +770,9 @@ public class Resolve {
return ambiguityError(m1, m2);
// both abstract, neither overridden; merge throws clause and result type
Symbol mostSpecific;
Type result2 = mt2.getReturnType();
if (mt2.tag == FORALL)
result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
if (types.isSubtype(mt1.getReturnType(), result2))
if (types.returnTypeSubstitutable(mt1, mt2))
mostSpecific = m1;
else if (types.isSubtype(result2, mt1.getReturnType()))
else if (types.returnTypeSubstitutable(mt2, mt1))
mostSpecific = m2;
else {
// Theoretically, this can't happen, but it is possible
......
/*
* Copyright (c) 2011, 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.
*
* 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 7034019
* @summary ClassCastException in javac with conjunction types
*
* @compile T7034019a.java
*/
class T7034019a {
interface A {
abstract <T> void foo();
}
interface B {
abstract void foo();
}
static class C<T extends A & B> {
void test(T x) {
x.foo();
}
}
}
/*
* Copyright (c) 2011, 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.
*
* 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 7034019
* @summary ClassCastException in javac with conjunction types
*
* @compile T7034019b.java
*/
class T7034019a {
interface A {
<T> void foo();
}
interface B {
void foo();
}
static abstract class E implements A,B {
void test() {
foo();
}
}
}
/*
* @test /nodynamiccopyright/
* @bug 7034019
* @summary ClassCastException in javac with conjunction types
*
* @compile/fail/ref=T7034019c.out -XDrawDiagnostics T7034019c.java
*/
class T7034019c {
interface A {
abstract <T extends Number> T foo();
}
interface B {
abstract <T> T foo();
}
static class C<T extends A & B> {
void test(T x) {
x.foo();
}
}
}
T7034019c.java:18:20: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
T7034019c.java:20:14: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
2 errors
/*
* @test /nodynamiccopyright/
* @bug 7034019
* @summary ClassCastException in javac with conjunction types
*
* @compile/fail/ref=T7034019d.out -XDrawDiagnostics T7034019d.java
*/
class T7034019c {
interface A {
abstract <T extends Number> T foo();
}
interface B {
abstract <T> T foo();
}
static abstract class E implements A,B {
void test() {
foo();
}
}
}
T7034019d.java:18:21: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
T7034019d.java:20:13: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
2 errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册