Thu, 25 Jul 2013 14:51:40 +0100
8020843: javac crashes on accessibility check with method reference with typevar receiver
Summary: method reference overload check doesn't walk through type-variable receivers
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 1998, 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 4147520 |
duke@1 | 27 | * @summary Verify correct implementation of qualified 'this' and 'super'. |
duke@1 | 28 | * @author maddox |
duke@1 | 29 | * |
duke@1 | 30 | * @run compile QualifiedThisAndSuper_3.java |
duke@1 | 31 | * @run main QualifiedThisAndSuper_3 |
duke@1 | 32 | */ |
duke@1 | 33 | |
duke@1 | 34 | class AS { |
duke@1 | 35 | String s = "ass"; |
duke@1 | 36 | private String t = "ast"; |
duke@1 | 37 | protected String u = "asu"; |
duke@1 | 38 | String m() { return "asm"; } |
duke@1 | 39 | private String n() { return "asn"; } |
duke@1 | 40 | protected String o() { return "aso"; } |
duke@1 | 41 | |
duke@1 | 42 | static String xs = "xass"; |
duke@1 | 43 | static private String xt = "xast"; |
duke@1 | 44 | static protected String xu = "xasu"; |
duke@1 | 45 | static String xm() { return "xasm"; } |
duke@1 | 46 | static private String xn() { return "xasn"; } |
duke@1 | 47 | static protected String xo() { return "xaso"; } |
duke@1 | 48 | } |
duke@1 | 49 | |
duke@1 | 50 | class BS { |
duke@1 | 51 | String s = "bss"; |
duke@1 | 52 | private String t = "bst"; |
duke@1 | 53 | protected String u = "bsu"; |
duke@1 | 54 | String m() { return "bsm"; } |
duke@1 | 55 | private String n() { return "bsn"; } |
duke@1 | 56 | protected String o() { return "bso"; } |
duke@1 | 57 | } |
duke@1 | 58 | |
duke@1 | 59 | class CS { |
duke@1 | 60 | String s = "css"; |
duke@1 | 61 | private String t = "cst"; |
duke@1 | 62 | protected String u = "csu"; |
duke@1 | 63 | String m() { return "csm"; } |
duke@1 | 64 | private String n() { return "csn"; } |
duke@1 | 65 | protected String o() { return "cso"; } |
duke@1 | 66 | } |
duke@1 | 67 | |
duke@1 | 68 | public class QualifiedThisAndSuper_3 extends AS { |
duke@1 | 69 | |
duke@1 | 70 | void check(String expr, String result, String expected) { |
duke@1 | 71 | if (!result.equals(expected)) { |
duke@1 | 72 | throw new Error("Evaluated "+ expr + |
duke@1 | 73 | " : result " + result + ", expected " + expected); |
duke@1 | 74 | } |
duke@1 | 75 | } |
duke@1 | 76 | |
duke@1 | 77 | |
duke@1 | 78 | QualifiedThisAndSuper_3() { super(); } |
duke@1 | 79 | String s = "as"; |
duke@1 | 80 | private String t = "at"; |
duke@1 | 81 | protected String u = "au"; |
duke@1 | 82 | String m() { return "am"; } |
duke@1 | 83 | private String n() { return "an"; } |
duke@1 | 84 | protected String o() { return "ao"; } |
duke@1 | 85 | |
duke@1 | 86 | static String xs = "xas"; |
duke@1 | 87 | static private String xt = "xat"; |
duke@1 | 88 | static protected String xu = "xau"; |
duke@1 | 89 | static String xm() { return "xam"; } |
duke@1 | 90 | static private String xn() { return "xan"; } |
duke@1 | 91 | static protected String xo() { return "xao"; } |
duke@1 | 92 | |
duke@1 | 93 | public class B extends BS { |
duke@1 | 94 | B() { super(); } |
duke@1 | 95 | String s = "bs"; |
duke@1 | 96 | private String t = "bt"; |
duke@1 | 97 | protected String u = "bu"; |
duke@1 | 98 | String m() { return "bm"; } |
duke@1 | 99 | private String n() { return "bn"; } |
duke@1 | 100 | protected String o() { return "bo"; } |
duke@1 | 101 | public class C extends CS { |
duke@1 | 102 | C() { super(); } |
duke@1 | 103 | String s = "cs"; |
duke@1 | 104 | private String t = "ct"; |
duke@1 | 105 | protected String u = "cu"; |
duke@1 | 106 | String m() { return "cm"; } |
duke@1 | 107 | private String n() { return "cn"; } |
duke@1 | 108 | protected String o() { return "co"; } |
duke@1 | 109 | void test() { |
duke@1 | 110 | |
duke@1 | 111 | check("QualifiedThisAndSuper_3.super.xm()", QualifiedThisAndSuper_3.super.xm(), "xasm"); |
duke@1 | 112 | // Private to another package-member class: not accessible |
duke@1 | 113 | // check("QualifiedThisAndSuper_3.super.xn()", QualifiedThisAndSuper_3.super.xn(), "xasn"); |
duke@1 | 114 | check("QualifiedThisAndSuper_3.super.xo()", QualifiedThisAndSuper_3.super.xo(), "xaso"); |
duke@1 | 115 | |
duke@1 | 116 | check("QualifiedThisAndSuper_3.super.xs", QualifiedThisAndSuper_3.super.xs, "xass"); |
duke@1 | 117 | // Private to another package-member class: not accessible |
duke@1 | 118 | // check("QualifiedThisAndSuper_3.super.xt", QualifiedThisAndSuper_3.super.xt, "xast"); |
duke@1 | 119 | check("QualifiedThisAndSuper_3.super.xu", QualifiedThisAndSuper_3.super.xu, "xasu"); |
duke@1 | 120 | |
duke@1 | 121 | check("QualifiedThisAndSuper_3.this.xm()", QualifiedThisAndSuper_3.this.xm(), "xam"); |
duke@1 | 122 | check("QualifiedThisAndSuper_3.this.xn()", QualifiedThisAndSuper_3.this.xn(), "xan"); |
duke@1 | 123 | check("QualifiedThisAndSuper_3.this.xo()", QualifiedThisAndSuper_3.this.xo(), "xao"); |
duke@1 | 124 | |
duke@1 | 125 | check("QualifiedThisAndSuper_3.this.xs", QualifiedThisAndSuper_3.this.xs, "xas"); |
duke@1 | 126 | check("QualifiedThisAndSuper_3.this.xt", QualifiedThisAndSuper_3.this.xt, "xat"); |
duke@1 | 127 | check("QualifiedThisAndSuper_3.this.xu", QualifiedThisAndSuper_3.this.xu, "xau"); |
duke@1 | 128 | |
duke@1 | 129 | //--- |
duke@1 | 130 | |
duke@1 | 131 | check("this.m()", this.m(), "cm"); |
duke@1 | 132 | |
duke@1 | 133 | check("QualifiedThisAndSuper_3.this.m()", QualifiedThisAndSuper_3.this.m(), "am"); |
duke@1 | 134 | check("B.this.m()", B.this.m(), "bm"); |
duke@1 | 135 | check("C.this.m()", C.this.m(), "cm"); |
duke@1 | 136 | |
duke@1 | 137 | check("super.m()", super.m(), "csm"); |
duke@1 | 138 | |
duke@1 | 139 | check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm"); |
duke@1 | 140 | check("B.super.m()", B.super.m(), "bsm"); |
duke@1 | 141 | check("C.super.m()", C.super.m(), "csm"); |
duke@1 | 142 | |
duke@1 | 143 | // should re-use access methods. |
duke@1 | 144 | check("QualifiedThisAndSuper_3.super.m()", QualifiedThisAndSuper_3.super.m(), "asm"); |
duke@1 | 145 | check("B.super.m()", B.super.m(), "bsm"); |
duke@1 | 146 | check("C.super.m()", C.super.m(), "csm"); |
duke@1 | 147 | |
duke@1 | 148 | //--- |
duke@1 | 149 | |
duke@1 | 150 | check("this.n()", this.n(), "cn"); |
duke@1 | 151 | |
duke@1 | 152 | check("QualifiedThisAndSuper_3.this.n()", QualifiedThisAndSuper_3.this.n(), "an"); |
duke@1 | 153 | check("B.this.n()", B.this.n(), "bn"); |
duke@1 | 154 | check("C.this.n()", C.this.n(), "cn"); |
duke@1 | 155 | |
duke@1 | 156 | /***** |
duke@1 | 157 | check("super.n()", super.n(), "csn"); |
duke@1 | 158 | |
duke@1 | 159 | check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn"); |
duke@1 | 160 | check("B.super.n()", B.super.n(), "bsn"); |
duke@1 | 161 | check("C.super.n()", C.super.n(), "csn"); |
duke@1 | 162 | |
duke@1 | 163 | // should re-use access methods. |
duke@1 | 164 | check("QualifiedThisAndSuper_3.super.n()", QualifiedThisAndSuper_3.super.n(), "asn"); |
duke@1 | 165 | check("B.super.n()", B.super.n(), "bsn"); |
duke@1 | 166 | check("C.super.n()", C.super.n(), "csn"); |
duke@1 | 167 | *****/ |
duke@1 | 168 | |
duke@1 | 169 | //--- |
duke@1 | 170 | |
duke@1 | 171 | check("this.o()", this.o(), "co"); |
duke@1 | 172 | |
duke@1 | 173 | check("QualifiedThisAndSuper_3.this.o()", QualifiedThisAndSuper_3.this.o(), "ao"); |
duke@1 | 174 | check("B.this.o()", B.this.o(), "bo"); |
duke@1 | 175 | check("C.this.o()", C.this.o(), "co"); |
duke@1 | 176 | |
duke@1 | 177 | check("super.o()", super.o(), "cso"); |
duke@1 | 178 | |
duke@1 | 179 | check("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.super.o(), "aso"); |
duke@1 | 180 | check("B.super.o()", B.super.o(), "bso"); |
duke@1 | 181 | check("C.super.o()", C.super.o(), "cso"); |
duke@1 | 182 | |
duke@1 | 183 | // should re-use access methods. |
duke@1 | 184 | check("QualifiedThisAndSuper_3.super.o()", QualifiedThisAndSuper_3.super.o(), "aso"); |
duke@1 | 185 | check("B.super.o()", B.super.o(), "bso"); |
duke@1 | 186 | check("C.super.o()", C.super.o(), "cso"); |
duke@1 | 187 | |
duke@1 | 188 | //--- |
duke@1 | 189 | |
duke@1 | 190 | check("this.s", this.s, "cs"); |
duke@1 | 191 | |
duke@1 | 192 | check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.this.s, "as"); |
duke@1 | 193 | check("B.this.s", B.this.s, "bs"); |
duke@1 | 194 | check("C.this.s", C.this.s, "cs"); |
duke@1 | 195 | |
duke@1 | 196 | //--- |
duke@1 | 197 | |
duke@1 | 198 | check("this.t", this.t, "ct"); |
duke@1 | 199 | |
duke@1 | 200 | check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.this.t, "at"); |
duke@1 | 201 | check("B.this.t", B.this.t, "bt"); |
duke@1 | 202 | check("C.this.t", C.this.t, "ct"); |
duke@1 | 203 | |
duke@1 | 204 | //--- |
duke@1 | 205 | |
duke@1 | 206 | check("this.u", this.u, "cu"); |
duke@1 | 207 | |
duke@1 | 208 | check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.this.u, "au"); |
duke@1 | 209 | check("B.this.u", B.this.u, "bu"); |
duke@1 | 210 | check("C.this.u", C.this.u, "cu"); |
duke@1 | 211 | |
duke@1 | 212 | //--- |
duke@1 | 213 | |
duke@1 | 214 | check("super.s", super.s, "css"); |
duke@1 | 215 | |
duke@1 | 216 | check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "ass"); |
duke@1 | 217 | check("B.super.s", B.super.s, "bss"); |
duke@1 | 218 | check("C.super.s", C.super.s, "css"); |
duke@1 | 219 | |
duke@1 | 220 | //--- |
duke@1 | 221 | |
duke@1 | 222 | /***** |
duke@1 | 223 | check("super.t", super.t, "cst"); |
duke@1 | 224 | |
duke@1 | 225 | check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "ast"); |
duke@1 | 226 | check("B.super.t", B.super.t, "bst"); |
duke@1 | 227 | check("C.super.t", C.super.t, "cst"); |
duke@1 | 228 | *****/ |
duke@1 | 229 | |
duke@1 | 230 | //--- |
duke@1 | 231 | |
duke@1 | 232 | check("super.u", super.u, "csu"); |
duke@1 | 233 | |
duke@1 | 234 | check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.super.u, "asu"); |
duke@1 | 235 | check("B.super.u", B.super.u, "bsu"); |
duke@1 | 236 | check("C.super.u", C.super.u, "csu"); |
duke@1 | 237 | |
duke@1 | 238 | //--- |
duke@1 | 239 | |
duke@1 | 240 | QualifiedThisAndSuper_3.this.s = "foo"; |
duke@1 | 241 | System.out.println(QualifiedThisAndSuper_3.this.s); |
duke@1 | 242 | check("QualifiedThisAndSuper_3.this.s", QualifiedThisAndSuper_3.this.s, "foo"); |
duke@1 | 243 | B.this.s = "bar"; |
duke@1 | 244 | System.out.println(B.this.s); |
duke@1 | 245 | check("B.this.s", B.this.s, "bar"); |
duke@1 | 246 | C.this.s = "baz"; |
duke@1 | 247 | System.out.println(C.this.s); |
duke@1 | 248 | check("C.this.s", C.this.s, "baz"); |
duke@1 | 249 | |
duke@1 | 250 | QualifiedThisAndSuper_3.this.t = "foo"; |
duke@1 | 251 | System.out.println(QualifiedThisAndSuper_3.this.t); |
duke@1 | 252 | check("QualifiedThisAndSuper_3.this.t", QualifiedThisAndSuper_3.this.t, "foo"); |
duke@1 | 253 | B.this.t = "bar"; |
duke@1 | 254 | System.out.println(B.this.t); |
duke@1 | 255 | check("B.this.t", B.this.t, "bar"); |
duke@1 | 256 | C.this.t = "baz"; |
duke@1 | 257 | System.out.println(C.this.t); |
duke@1 | 258 | check("C.this.t", C.this.t, "baz"); |
duke@1 | 259 | |
duke@1 | 260 | QualifiedThisAndSuper_3.this.u = "foo"; |
duke@1 | 261 | System.out.println(QualifiedThisAndSuper_3.this.u); |
duke@1 | 262 | check("QualifiedThisAndSuper_3.this.u", QualifiedThisAndSuper_3.this.u, "foo"); |
duke@1 | 263 | B.this.u = "bar"; |
duke@1 | 264 | System.out.println(B.this.u); |
duke@1 | 265 | check("B.this.u", B.this.u, "bar"); |
duke@1 | 266 | C.this.u = "baz"; |
duke@1 | 267 | System.out.println(C.this.u); |
duke@1 | 268 | check("C.this.u", C.this.u, "baz"); |
duke@1 | 269 | |
duke@1 | 270 | QualifiedThisAndSuper_3.super.s = "foo"; |
duke@1 | 271 | System.out.println(QualifiedThisAndSuper_3.super.s); |
duke@1 | 272 | check("QualifiedThisAndSuper_3.super.s", QualifiedThisAndSuper_3.super.s, "foo"); |
duke@1 | 273 | B.super.s = "bar"; |
duke@1 | 274 | System.out.println(B.super.s); |
duke@1 | 275 | check("B.super.s", B.super.s, "bar"); |
duke@1 | 276 | C.super.s = "baz"; |
duke@1 | 277 | System.out.println(C.super.s); |
duke@1 | 278 | check("C.super.s", C.super.s, "baz"); |
duke@1 | 279 | |
duke@1 | 280 | /***** |
duke@1 | 281 | QualifiedThisAndSuper_3.super.t = "foo"; |
duke@1 | 282 | System.out.println(QualifiedThisAndSuper_3.super.t); |
duke@1 | 283 | check("QualifiedThisAndSuper_3.super.t", QualifiedThisAndSuper_3.super.t, "foo"); |
duke@1 | 284 | B.super.t = "bar"; |
duke@1 | 285 | System.out.println(B.super.t); |
duke@1 | 286 | check("B.super.t", B.super.t, "bar"); |
duke@1 | 287 | C.super.t = "baz"; |
duke@1 | 288 | System.out.println(C.super.t); |
duke@1 | 289 | check("C.super.t", C.super.t, "baz"); |
duke@1 | 290 | *****/ |
duke@1 | 291 | |
duke@1 | 292 | QualifiedThisAndSuper_3.super.u = "foo"; |
duke@1 | 293 | System.out.println(QualifiedThisAndSuper_3.super.u); |
duke@1 | 294 | check("QualifiedThisAndSuper_3.super.u", QualifiedThisAndSuper_3.super.u, "foo"); |
duke@1 | 295 | B.super.u = "bar"; |
duke@1 | 296 | System.out.println(B.super.u); |
duke@1 | 297 | check("B.super.u", B.super.u, "bar"); |
duke@1 | 298 | C.super.u = "baz"; |
duke@1 | 299 | System.out.println(C.super.u); |
duke@1 | 300 | check("C.super.u", C.super.u, "baz"); |
duke@1 | 301 | |
duke@1 | 302 | } |
duke@1 | 303 | } |
duke@1 | 304 | void test() throws Exception { |
duke@1 | 305 | C c = new C(); |
duke@1 | 306 | c.test(); |
duke@1 | 307 | } |
duke@1 | 308 | } |
duke@1 | 309 | void test() throws Exception { |
duke@1 | 310 | B b = new B(); |
duke@1 | 311 | b.test(); |
duke@1 | 312 | } |
duke@1 | 313 | |
duke@1 | 314 | public static void main(String[] args) throws Exception { |
duke@1 | 315 | QualifiedThisAndSuper_3 a = new QualifiedThisAndSuper_3(); |
duke@1 | 316 | a.test(); |
duke@1 | 317 | } |
duke@1 | 318 | } |