diff options
author | Manoj Palat | 2018-04-23 06:13:08 +0000 |
---|---|---|
committer | Manoj Palat | 2018-04-23 06:13:08 +0000 |
commit | 747856a76606d57cb67c300aa2c06c7104b1d436 (patch) | |
tree | 1b72d1fb26fdd075de1fd91809f2b4fc92d0efad | |
parent | 235a3d96bce67e31626ffca69b9b34eaacd105d9 (diff) | |
download | eclipse.jdt.core-747856a76606d57cb67c300aa2c06c7104b1d436.tar.gz eclipse.jdt.core-747856a76606d57cb67c300aa2c06c7104b1d436.tar.xz eclipse.jdt.core-747856a76606d57cb67c300aa2c06c7104b1d436.zip |
Bug 488328 [1.8][compiler][inference] Wrong method overload resolutionI20180423-2000I20180423-0655I20180423-0640
(may lead to VerifyError)
Change-Id: I55e2bbe22af96ce8e5b7be0ae70532d210c0366a
2 files changed, 54 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java index f223ff5643..8eb270a59c 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java @@ -8935,4 +8935,51 @@ public void testBug508834_comment0() { }; runner.runConformTest(); } + public void testBug488328_001() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static class A<R> {\n" + + " class I {\n" + + " }\n" + + " }\n" + + "\n" + + " public static <R> void m(A<R>.I instance, R generic) {\n" + + " System.out.println(\"called with A<R>.I\");\n" + + " }\n" + + "\n" + + " public static void m(long l, Object o) {\n" + + " System.out.println(\"called with long\");\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " Long l = new Long(3);\n" + + " m(l, l);\n" + + " }\n" + + "}" + }); + } + public void testBug488328_002() { + runConformTest( + new String[] { + "Test.java", + "class A1<R> {\n"+ + " class I1<S> {}\n"+ + "}\n"+ + "public class Test<R> extends A1<R>{\n" + + " class A2 {\n" + + " class I2 extends A1<R>.I1<R> {}\n" + + " }\n" + + "\n" + + " public static <R> void m(A1<R>.I1<R> instance) {\n" + + " System.out.println(\"called with A1<R>.I1<R>\");\n" + + " }\n" + + " public static void main(String... args) {\n" + + " Test<Integer>.A2.I2 l = new Test<Integer>().new A2().new I2();\n" + + " m(l);\n" + + " }\n" + + "}" + }); + } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java index 334c93b3ad..b76340911d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 GK Software AG. + * Copyright (c) 2013, 2018 GK Software AG, and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -262,9 +262,11 @@ class ConstraintTypeFormula extends ConstraintFormula { case Binding.PARAMETERIZED_TYPE: { List<ConstraintFormula> constraints = new ArrayList<>(); + boolean isFirst = true; while (superCandidate != null && superCandidate.kind() == Binding.PARAMETERIZED_TYPE && subCandidate != null) { if (!addConstraintsFromTypeParameters(subCandidate, (ParameterizedTypeBinding) superCandidate, constraints)) - return FALSE; + if (isFirst) return FALSE; + isFirst = false; // travel to enclosing types to check if they have type parameters, too: superCandidate = superCandidate.enclosingType(); subCandidate = subCandidate.enclosingType(); @@ -378,9 +380,6 @@ class ConstraintTypeFormula extends ConstraintFormula { } boolean addConstraintsFromTypeParameters(TypeBinding subCandidate, ParameterizedTypeBinding ca, List<ConstraintFormula> constraints) { - TypeBinding[] ai = ca.arguments; // C<A1,A2,...> - if (ai == null) - return true; // no arguments here means nothing to check TypeBinding cb = subCandidate.findSuperTypeOriginatingFrom(ca); // C<B1,B2,...> if (cb == null) return false; // nothing here means we failed @@ -391,6 +390,9 @@ class ConstraintTypeFormula extends ConstraintFormula { return ca.isParameterizedWithOwnVariables(); } TypeBinding[] bi = ((ParameterizedTypeBinding) cb).arguments; + TypeBinding[] ai = ca.arguments; // C<A1,A2,...> + if (ai == null) + return true; // no arguments here means nothing to check if (cb.isRawType() || bi == null || bi.length == 0) return (this.isSoft && InferenceContext18.SIMULATE_BUG_JDK_8026527) ? true : false; // FALSE would conform to the spec for (int i = 0; i < ai.length; i++) |