mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
7034019: ClassCastException in javac with conjunction types
Resolve.mostSpecific doesn't handle case of raw override Reviewed-by: dlsmith
This commit is contained in:
parent
c46387423a
commit
02daeca60e
7 changed files with 146 additions and 5 deletions
|
@ -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
|
||||
|
|
46
langtools/test/tools/javac/generics/7034019/T7034019a.java
Normal file
46
langtools/test/tools/javac/generics/7034019/T7034019a.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
46
langtools/test/tools/javac/generics/7034019/T7034019b.java
Normal file
46
langtools/test/tools/javac/generics/7034019/T7034019b.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
23
langtools/test/tools/javac/generics/7034019/T7034019c.java
Normal file
23
langtools/test/tools/javac/generics/7034019/T7034019c.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
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
|
23
langtools/test/tools/javac/generics/7034019/T7034019d.java
Normal file
23
langtools/test/tools/javac/generics/7034019/T7034019d.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue