8014494: javac crashes when varargs element of a method reference is inferred from the context

Fri, 24 May 2013 15:27:27 +0100

author
mcimadamore
date
Fri, 24 May 2013 15:27:27 +0100
changeset 1780
6e5076af4660
parent 1779
97a9b4b3e63a
child 1781
0f8e9a0e5d9a

8014494: javac crashes when varargs element of a method reference is inferred from the context
Summary: varargs element is not refreshed after type-inference
Reviewed-by: jjg, vromero

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/TargetType73.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri May 24 15:27:12 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri May 24 15:27:27 2013 +0100
     1.3 @@ -3732,7 +3732,7 @@
     1.4                      noteWarner);
     1.5  
     1.6              return chk.checkMethod(owntype, sym, env, argtrees, argtypes, env.info.lastResolveVarargs(),
     1.7 -                    noteWarner.hasNonSilentLint(LintCategory.UNCHECKED));
     1.8 +                    noteWarner.hasNonSilentLint(LintCategory.UNCHECKED), resultInfo.checkContext.inferenceContext());
     1.9          } catch (Infer.InferenceException ex) {
    1.10              //invalid target type - propagate exception outwards or report error
    1.11              //depending on the current check context
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri May 24 15:27:12 2013 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri May 24 15:27:27 2013 +0100
     2.3 @@ -853,7 +853,8 @@
     2.4                              final List<JCExpression> argtrees,
     2.5                              List<Type> argtypes,
     2.6                              boolean useVarargs,
     2.7 -                            boolean unchecked) {
     2.8 +                            boolean unchecked,
     2.9 +                            InferenceContext inferenceContext) {
    2.10          // System.out.println("call   : " + env.tree);
    2.11          // System.out.println("method : " + owntype);
    2.12          // System.out.println("actuals: " + argtypes);
    2.13 @@ -917,7 +918,7 @@
    2.14                                    argtype);
    2.15              }
    2.16              if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) {
    2.17 -                TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
    2.18 +                setVarargsElement(env, types.elemtype(argtype), inferenceContext);
    2.19              }
    2.20           }
    2.21           PolyKind pkind = (sym.type.hasTag(FORALL) &&
    2.22 @@ -927,6 +928,17 @@
    2.23           return owntype;
    2.24      }
    2.25      //where
    2.26 +        private void setVarargsElement(final Env<AttrContext> env, final Type elemtype, InferenceContext inferenceContext) {
    2.27 +            if (inferenceContext.free(elemtype)) {
    2.28 +                inferenceContext.addFreeTypeListener(List.of(elemtype), new FreeTypeListener() {
    2.29 +                    public void typesInferred(InferenceContext inferenceContext) {
    2.30 +                        setVarargsElement(env, inferenceContext.asInstType(elemtype), inferenceContext);
    2.31 +                    }
    2.32 +                });
    2.33 +            }
    2.34 +            TreeInfo.setVarargsElement(env.tree, elemtype);
    2.35 +        }
    2.36 +
    2.37          private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
    2.38              if (types.isConvertible(actual, formal, warn))
    2.39                  return;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/lambda/TargetType73.java	Fri May 24 15:27:27 2013 +0100
     3.3 @@ -0,0 +1,47 @@
     3.4 +/*
     3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 8014494
    3.30 + * @summary javac crashes when varargs element of a method reference is inferred from the context
    3.31 + * @compile TargetType73.java
    3.32 + */
    3.33 +import java.util.List;
    3.34 +
    3.35 +class TargetType73 {
    3.36 +
    3.37 +    interface Function<X,Y> {
    3.38 +        Y m(X x);
    3.39 +    }
    3.40 +
    3.41 +    static void test() {
    3.42 +        m(TargetType73::g);
    3.43 +    }
    3.44 +
    3.45 +    public static <T> List<T> g(T... a) {
    3.46 +        return null;
    3.47 +    }
    3.48 +
    3.49 +    public static <C> void m(Function<String, C> zipper) {  }
    3.50 +}

mercurial