Mon, 08 Sep 2014 10:48:18 +0200
8056014: Type inference may be skipped for a complex receiver generic method in a parameter position
Summary: When checking if deferred attribution is needed for a chain of methods, stop on any method that returns any type variable, as the rest of analysis cannot use the correct type.
Reviewed-by: mcimadamore, vromero
src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/lambda/T8056014.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Sep 10 10:51:36 2014 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon Sep 08 10:48:18 2014 +0200 1.3 @@ -1337,7 +1337,9 @@ 1.4 @Override 1.5 public Symbol process(MethodSymbol ms) { 1.6 ArgumentExpressionKind kind = ArgumentExpressionKind.methodKind(ms, types); 1.7 - return kind != ArgumentExpressionKind.POLY ? ms.getReturnType().tsym : null; 1.8 + if (kind == ArgumentExpressionKind.POLY || ms.getReturnType().hasTag(TYPEVAR)) 1.9 + return null; 1.10 + return ms.getReturnType().tsym; 1.11 } 1.12 @Override 1.13 public Symbol reduce(Symbol s1, Symbol s2) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/lambda/T8056014.java Mon Sep 08 10:48:18 2014 +0200 2.3 @@ -0,0 +1,70 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * @test 2.29 + * @bug 8056014 2.30 + * @summary Verify that full type inference is used when calling a method on a type variable. 2.31 + * @compile T8056014.java 2.32 + * @run main T8056014 2.33 + */ 2.34 + 2.35 +import java.util.*; 2.36 + 2.37 +public class T8056014 { 2.38 + public static void main(String[] args) { 2.39 + new T8056014().run(); 2.40 + } 2.41 + 2.42 + void run() { 2.43 + List<S> l = Arrays.asList(new S()); 2.44 + C<S> c = new C<>(new S()); 2.45 + foo(l.get(0).copy(1)); 2.46 + foo(c.get(0).copy(1)); 2.47 + } 2.48 + 2.49 + void foo(S d) { 2.50 + } 2.51 +} 2.52 + 2.53 +class B { 2.54 + public B copy(long j) { 2.55 + throw new AssertionError("Should not get here."); 2.56 + } 2.57 +} 2.58 + 2.59 +class S extends B { 2.60 + public <T> T copy(int i) { 2.61 + return null; 2.62 + } 2.63 +} 2.64 + 2.65 +class C<T extends B> { 2.66 + final T t; 2.67 + public C(T t) { 2.68 + this.t = t; 2.69 + } 2.70 + public T get(int i) { 2.71 + return t; 2.72 + } 2.73 +}