Thu, 21 Feb 2013 15:26:46 +0000
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
Summary: Fix regression in varargs method resolution introduced by bad refactoring
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 4916607 |
duke@1 | 27 | * @summary Test casts (legal, warning, and errors) |
duke@1 | 28 | * @author gafter |
duke@1 | 29 | * |
darcy@289 | 30 | * @compile -Werror CastTest.java |
duke@1 | 31 | */ |
duke@1 | 32 | |
duke@1 | 33 | import java.util.*; |
duke@1 | 34 | |
duke@1 | 35 | class CastTest { |
duke@1 | 36 | |
duke@1 | 37 | // --- Directly transferring parameters --- |
duke@1 | 38 | |
duke@1 | 39 | private class AA<T> { } |
duke@1 | 40 | |
duke@1 | 41 | private class AB<T> extends AA<T> { } |
duke@1 | 42 | private class AC<T> extends AA<Vector<T>> { } |
duke@1 | 43 | private class AD<T> extends AA<Vector<? extends T>> { } |
duke@1 | 44 | private class AE<T> extends AA<Vector<? super T>> { } |
duke@1 | 45 | private class AF<T> extends AA<T[]> { } |
duke@1 | 46 | private class AG<T> extends AA<String> { } |
duke@1 | 47 | |
duke@1 | 48 | private void parameterTransfer() { |
duke@1 | 49 | Object o; |
duke@1 | 50 | |
duke@1 | 51 | o = (AB<String>) (AA<String>) null; // <<pass>> |
duke@1 | 52 | o = (AC<String>) (AA<Vector<String>>) null; // <<pass>> |
duke@1 | 53 | |
duke@1 | 54 | o = (AD<Number>) (AA<Vector<? extends Number>>) null; // <<pass>> |
duke@1 | 55 | o = (AD<?>) (AA<Vector<? extends Object>>) null; // <<pass>> |
duke@1 | 56 | o = (AD<Object>) (AA<Vector<?>>) null; // <<pass>> |
duke@1 | 57 | |
duke@1 | 58 | o = (AE<String>) (AA<Vector<? super String>>) null; // <<pass>> |
duke@1 | 59 | |
duke@1 | 60 | o = (AF<String>) (AA<String[]>) null; // <<pass>> |
duke@1 | 61 | |
duke@1 | 62 | o = (AG<?>) (AA<String>) null; // <<pass>> |
duke@1 | 63 | } |
duke@1 | 64 | |
duke@1 | 65 | // --- Inconsistent matches --- |
duke@1 | 66 | |
duke@1 | 67 | private class BA<T> { } |
duke@1 | 68 | private class BB<T, S> { } |
duke@1 | 69 | |
duke@1 | 70 | private class BC<T> extends BA<Integer> { } |
duke@1 | 71 | private class BD<T> extends BB<T, T> { } |
duke@1 | 72 | |
duke@1 | 73 | private void inconsistentMatches() { |
duke@1 | 74 | Object o; |
duke@1 | 75 | |
duke@1 | 76 | o = (BC<?>) (BA<Integer>) null; // <<pass>> |
duke@1 | 77 | o = (BD<String>) (BB<String, String>) null; // <<pass>> |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | private void whyMustEverythingBeSo_______Complicated() { |
duke@1 | 81 | // This has to work... |
duke@1 | 82 | BD<Number> bd = new BD<Number>(); |
duke@1 | 83 | BB<? extends Number, ? super Integer> bb = bd; |
duke@1 | 84 | |
duke@1 | 85 | // 4916620: wildcards: legal cast is rejected |
duke@1 | 86 | // bd = (BD<Number>) bb; // <<warn>> <<todo: cast-infer>> |
duke@1 | 87 | } |
duke@1 | 88 | |
duke@1 | 89 | // --- Transferring parameters via supertypes --- |
duke@1 | 90 | |
duke@1 | 91 | private interface CA<T> { } |
duke@1 | 92 | private interface CB<T> extends CA<T> { } |
duke@1 | 93 | private interface CC<T> extends CA<T> { } |
duke@1 | 94 | |
duke@1 | 95 | private class CD<T> implements CB<T> { } |
duke@1 | 96 | private interface CE<T> extends CC<T> { } |
duke@1 | 97 | |
duke@1 | 98 | private interface CF<S> { } |
duke@1 | 99 | private interface CG<T> { } |
duke@1 | 100 | private class CH<S, T> implements CF<S>, CG<T> { } |
duke@1 | 101 | private interface CI<S> extends CF<S> { } |
duke@1 | 102 | private interface CJ<T> extends CG<T> { } |
duke@1 | 103 | private interface CK<S, T> extends CI<S>, CJ<T> { } |
duke@1 | 104 | |
duke@1 | 105 | private void supertypeParameterTransfer() { |
duke@1 | 106 | Object o; |
duke@1 | 107 | o = (CE<String>) (CD<String>) null; // <<pass>> |
duke@1 | 108 | |
duke@1 | 109 | // 4916622: unnecessary warning with cast |
duke@1 | 110 | // o = (CH<String, Integer>) (CK<String, Integer>) null; // <<pass>> <<todo: cast-infer>> |
duke@1 | 111 | } |
duke@1 | 112 | |
duke@1 | 113 | // --- Disjoint --- |
duke@1 | 114 | |
duke@1 | 115 | private interface DA<T> { } |
duke@1 | 116 | private interface DB<T> extends DA<T> { } |
duke@1 | 117 | private interface DC<T> extends DA<Integer> { } |
duke@1 | 118 | |
duke@1 | 119 | private <N extends Number, I extends Integer, R extends Runnable, S extends String> void disjointness() { |
duke@1 | 120 | Object o; |
duke@1 | 121 | |
duke@1 | 122 | // Classes |
duke@1 | 123 | o = (DA<? extends Number>) (DA<Integer>) null; // <<pass>> |
duke@1 | 124 | o = (DA<? super Integer>) (DA<Number>) null; // <<pass>> |
duke@1 | 125 | o = (DA<?>) (DA<Integer>) null; // <<pass>> |
duke@1 | 126 | |
duke@1 | 127 | o = (DA<?>) (DA<? extends Integer>) null; // <<pass>> |
duke@1 | 128 | |
duke@1 | 129 | o = (DA<?>) (DA<? super String>) null; // <<pass>> |
duke@1 | 130 | |
duke@1 | 131 | o = (DA<?>) (DA<?>) null; // <<pass>> |
duke@1 | 132 | |
duke@1 | 133 | // Typevars |
duke@1 | 134 | o = (DA<? extends Number>) (DA<I>) null; // <<pass>> |
duke@1 | 135 | |
duke@1 | 136 | // Raw (asymmetrical!) |
duke@1 | 137 | o = (DA) (DB<Number>) null; // <<pass>> |
duke@1 | 138 | o = (DA<?>) (DB) null; // <<pass>> |
duke@1 | 139 | o = (DA<? extends Object>) (DB) null; // <<pass>> |
duke@1 | 140 | |
duke@1 | 141 | o = (DB) (DA<Number>) null; // <<pass>> |
duke@1 | 142 | o = (DB<?>) (DA) null; // <<pass>> |
duke@1 | 143 | o = (DB<? extends Object>) (DA) null; // <<pass>> |
duke@1 | 144 | |
duke@1 | 145 | // reported broken (5034609) |
duke@1 | 146 | // o = (DC<?>) (DA<?>) null; // <<pass>> |
duke@1 | 147 | } |
duke@1 | 148 | |
duke@1 | 149 | } |