8069545: javac shouldn't check nested stuck lambdas during overload resolution

Thu, 12 Feb 2015 10:16:19 +0530

author
vromero
date
Thu, 12 Feb 2015 10:16:19 +0530
changeset 2730
a513711d6171
parent 2724
e5b93c508212
child 2731
1006b37f1cc8

8069545: javac shouldn't check nested stuck lambdas during overload resolution
Summary: Nested lambdas should not be considered while overload resolution is in progress
Reviewed-by: mcimadamore
Contributed-by: vicente.romero@oracle.com, srikanth.adayapalam@oracle.com

src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8016177/T8016177g.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8016177/T8016177g.out file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8068399/T8068399.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8068430/T8068430.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8071432/T8071432.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8071432/T8071432.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed Mar 18 18:20:37 2015 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Feb 12 10:16:19 2015 +0530
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -224,7 +224,8 @@
    1.11              DeferredStuckPolicy deferredStuckPolicy;
    1.12              if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
    1.13                  deferredStuckPolicy = dummyStuckPolicy;
    1.14 -            } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) {
    1.15 +            } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE ||
    1.16 +                    resultInfo.checkContext.deferredAttrContext().insideOverloadPhase()) {
    1.17                  deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this);
    1.18              } else {
    1.19                  deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this);
     2.1 --- a/test/tools/javac/lambda/8016177/T8016177g.java	Wed Mar 18 18:20:37 2015 -0700
     2.2 +++ b/test/tools/javac/lambda/8016177/T8016177g.java	Thu Feb 12 10:16:19 2015 +0530
     2.3 @@ -1,6 +1,6 @@
     2.4  /*
     2.5   * @test /nodynamiccopyright/
     2.6 - * @bug 8016081 8016178
     2.7 + * @bug 8016081 8016178 8069545
     2.8   * @summary structural most specific and stuckness
     2.9   * @compile/fail/ref=T8016177g.out -XDrawDiagnostics T8016177g.java
    2.10   */
     3.1 --- a/test/tools/javac/lambda/8016177/T8016177g.out	Wed Mar 18 18:20:37 2015 -0700
     3.2 +++ b/test/tools/javac/lambda/8016177/T8016177g.out	Thu Feb 12 10:16:19 2015 +0530
     3.3 @@ -1,2 +1,3 @@
     3.4 -T8016177g.java:35:20: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, int)
     3.5 -1 error
     3.6 +T8016177g.java:34:14: compiler.err.cant.apply.symbol: kindname.method, print, java.lang.String, Test.Person, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: Test.Person, java.lang.String,java.lang.Object))
     3.7 +T8016177g.java:35:20: compiler.err.cant.apply.symbol: kindname.method, abs, int, java.lang.Double, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , R, int))
     3.8 +2 errors
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/lambda/8068399/T8068399.java	Thu Feb 12 10:16:19 2015 +0530
     4.3 @@ -0,0 +1,119 @@
     4.4 +/*
     4.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.  Oracle designates this
    4.11 + * particular file as subject to the "Classpath" exception as provided
    4.12 + * by Oracle in the LICENSE file that accompanied this code.
    4.13 + *
    4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.17 + * version 2 for more details (a copy is included in the LICENSE file that
    4.18 + * accompanied this code).
    4.19 + *
    4.20 + * You should have received a copy of the GNU General Public License version
    4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.23 + *
    4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.25 + * or visit www.oracle.com if you need additional information or have any
    4.26 + * questions.
    4.27 + */
    4.28 +/*
    4.29 + * @test
    4.30 + * @bug 8068399
    4.31 + * @summary structural most specific and stuckness
    4.32 + */
    4.33 +
    4.34 +import java.util.function.Function;
    4.35 +import java.util.stream.IntStream;
    4.36 +import java.util.stream.Stream;
    4.37 +
    4.38 +public class T8068399 {
    4.39 +
    4.40 +    public static class Spectrum {
    4.41 +        public double[] getEnergy() {
    4.42 +            return new double[0];
    4.43 +        }
    4.44 +    }
    4.45 +
    4.46 +    protected Spectrum spectrum;
    4.47 +
    4.48 +    public static class Ref<T> {
    4.49 +
    4.50 +        T value;
    4.51 +
    4.52 +        public Ref() {
    4.53 +        }
    4.54 +
    4.55 +        public Ref(T value) {
    4.56 +            this.value = value;
    4.57 +        }
    4.58 +
    4.59 +        public boolean isNull() {
    4.60 +            return value == null;
    4.61 +        }
    4.62 +
    4.63 +        public T get() {
    4.64 +            return value;
    4.65 +        }
    4.66 +
    4.67 +        public void set(T value) {
    4.68 +            this.value = value;
    4.69 +        }
    4.70 +    }
    4.71 +
    4.72 +    public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) {
    4.73 +        Ref<Double> max = new Ref<>();
    4.74 +        Ref<T> index = new Ref<>();
    4.75 +        stream.forEach(v -> {
    4.76 +            Double value = function.apply(v);
    4.77 +
    4.78 +            if (max.isNull() || value > max.get()) {
    4.79 +                max.set(value);
    4.80 +                index.set(v);
    4.81 +            }
    4.82 +        });
    4.83 +
    4.84 +        return index.get();
    4.85 +    }
    4.86 +
    4.87 +    public static int interpolate(int x, int x0, int x1, int y0, int y1) {
    4.88 +        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
    4.89 +    }
    4.90 +
    4.91 +    public static double interpolate(double x, double x0, double x1, double y0, double y1) {
    4.92 +        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
    4.93 +    }
    4.94 +
    4.95 +    protected int getXByFrequency(double frequency) {
    4.96 +        return (int) Math.round(interpolate(frequency,
    4.97 +                                            getMinSpectrumCoord(),
    4.98 +                                            getMaxSpectrumCoord(),
    4.99 +                                            0, getWidth()));
   4.100 +    }
   4.101 +
   4.102 +    private int getWidth() {
   4.103 +        return 0;
   4.104 +    }
   4.105 +
   4.106 +    private double getMaxSpectrumCoord() {
   4.107 +        return 0;
   4.108 +    }
   4.109 +
   4.110 +    private double getMinSpectrumCoord() {
   4.111 +        return 0;
   4.112 +    }
   4.113 +
   4.114 +    void foo() {
   4.115 +        int maxBpmIndex = 0;
   4.116 +        int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(),
   4.117 +                                          i -> Math.abs(spectrum.getEnergy()[i])));
   4.118 +    }
   4.119 +
   4.120 +    public static void main(String [] args) {
   4.121 +    }
   4.122 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/lambda/8068430/T8068430.java	Thu Feb 12 10:16:19 2015 +0530
     5.3 @@ -0,0 +1,46 @@
     5.4 +/*
     5.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.  Oracle designates this
    5.11 + * particular file as subject to the "Classpath" exception as provided
    5.12 + * by Oracle in the LICENSE file that accompanied this code.
    5.13 + *
    5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 + * version 2 for more details (a copy is included in the LICENSE file that
    5.18 + * accompanied this code).
    5.19 + *
    5.20 + * You should have received a copy of the GNU General Public License version
    5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 + *
    5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.25 + * or visit www.oracle.com if you need additional information or have any
    5.26 + * questions.
    5.27 + */
    5.28 +
    5.29 +/*
    5.30 + * @test
    5.31 + * @bug 8068430
    5.32 + * @summary structural most specific and stuckness
    5.33 + */
    5.34 +
    5.35 +import java.util.HashMap;
    5.36 +import java.util.Map;
    5.37 +
    5.38 +public class T8068430 {
    5.39 +    public static void main(String[] args) {
    5.40 +        Map<Integer, String> mp = new HashMap<>();
    5.41 +        mp.put(1, "a");
    5.42 +        mp.put(2, "b");
    5.43 +        mp.put(3, "c");
    5.44 +        mp.put(4, "d");
    5.45 +        System.out.println(mp.entrySet().stream().reduce(0,
    5.46 +                (i, e) -> i + e.getKey(),
    5.47 +                (i1, i2) -> i1 + i2));
    5.48 +    }
    5.49 +}
    5.50 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/lambda/8071432/T8071432.java	Thu Feb 12 10:16:19 2015 +0530
     6.3 @@ -0,0 +1,50 @@
     6.4 +/*
     6.5 + * @test /nodynamiccopyright/
     6.6 + * @bug 8071432
     6.7 + * @summary structural most specific and stuckness
     6.8 + * @compile/fail/ref=T8071432.out -XDrawDiagnostics T8071432.java
     6.9 + */
    6.10 +
    6.11 +import java.util.Arrays;
    6.12 +import java.util.Collection;
    6.13 +
    6.14 +class T8071432 {
    6.15 +
    6.16 +    static class Point {
    6.17 +
    6.18 +        private double x, y;
    6.19 +
    6.20 +        public Point(double x, double y) {
    6.21 +            this.x = x;
    6.22 +            this.y = y;
    6.23 +        }
    6.24 +
    6.25 +        public double getX() {
    6.26 +            return x;
    6.27 +        }
    6.28 +
    6.29 +        public double getY() {
    6.30 +            return y;
    6.31 +        }
    6.32 +
    6.33 +        public double distance(Point p) {
    6.34 +            return Math.sqrt((this.x - p.x) * (this.x - p.x) +
    6.35 +                             (this.y - p.y) * (this.y - p.y));
    6.36 +        }
    6.37 +
    6.38 +        public double distance() {
    6.39 +            return Math.sqrt(this.x * this.x + this.y * this.y);
    6.40 +        }
    6.41 +
    6.42 +        public String toString() {
    6.43 +            return "(" + x + ":" + y + ")";
    6.44 +        }
    6.45 +    }
    6.46 +
    6.47 +    public static void main(String[] args) {
    6.48 +        Collection<Point> c = Arrays.asList(new Point(1.0, 0.1));
    6.49 +        System.out.println("------- 1 ---------------");
    6.50 +        System.out.println(c.stream().reduce(0.0,
    6.51 +                                            (s, p) -> s += p.distance(), (d1, d2) -> 0));
    6.52 +    }
    6.53 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/lambda/8071432/T8071432.out	Thu Feb 12 10:16:19 2015 +0530
     7.3 @@ -0,0 +1,3 @@
     7.4 +T8071432.java:47:45: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double)))
     7.5 +T8071432.java:47:27: compiler.err.cant.apply.symbol: kindname.method, println, java.lang.Object, <any>, kindname.class, java.io.PrintStream, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double))))
     7.6 +2 errors

mercurial