ambiguous method calls: conflict resolver, tests

(IDEA-67919; IDEA-67863; IDEA-67920;
 IDEA-67831; IDEA-67833; IDEA-67674;
 IDEA-67587; IDEA-57646; IDEA-57407;
 IDEA-57279; IDEA-57296; IDEA-57297;
 IDEA-57316; IDEA-57331)
This commit is contained in:
anna
2012-04-06 11:55:43 +02:00
parent 4aaf383d47
commit dc5c191afc
16 changed files with 414 additions and 4 deletions
@@ -0,0 +1,21 @@
package pck;
import java.util.List;
import static pck.C.foo;
import static pck.D.foo;
class C {
static <T> void foo(List<? extends List<T>> x) { }
}
class D {
static <T> String foo(List<List<T>> x) { return null; }
}
public class Main {
public static void main(String[] args){
List<List<String>> x = null;
foo(x).toLowerCase();
}
}
@@ -0,0 +1,21 @@
package pck;
import java.util.List;
import static pck.C.foo;
import static pck.D.foo;
class C {
static <T> void foo(List<T> x) { }
}
class D {
static <T> String foo(List<T[]> x) { return null; }
}
public class Main {
public static void main(String[] args){
List<String[]> x = null;
foo(x).toLowerCase();
}
}
@@ -0,0 +1,16 @@
package pck;
interface A<T>
{
T foo();
}
interface B<T> extends A<T[]> { }
class C<T extends A<Object[]> & B<?>>
{
void foo(T x)
{
Object[] foo = x.foo();
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pck;
interface A<T>
{
T foo();
}
interface B<T extends Cloneable> extends A<T> { }
class C<T extends A<?> & B<?>>
{
void bar(T x)
{
x.foo();
}
}
@@ -0,0 +1,28 @@
package pck;
interface IA<T> {
T a();
}
interface IB {
String a();
}
abstract class C implements IA<String>, IB {
{
a();
}
}
interface IAO {
Object a();
}
abstract class CO implements IAO, IB {
{
a();
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pck;
interface IA<T> {
T a();
}
interface IB {
String a();
}
abstract class C implements IA<String>, IB {
{
a();
}
}
interface IAO {
Object a();
}
abstract class CO implements IAO, IB {
{
a();
}
}
@@ -0,0 +1,15 @@
package pck;
class A<T> {}
interface IA{
void foo(A<?> x);
}
interface IB{
<T> void foo(A<T> x);
}
class C {
<T extends IA & IB> void bar(T x, A<String> y){
x.foo<error descr="Ambiguous method call: both 'IA.foo(A<?>)' and 'IB.foo(A<String>)' match">(y)</error>;
}
}
@@ -0,0 +1,15 @@
package pck;
class A<T> {}
interface IA{
<T> void foo(A<A<T>> x);
}
interface IB{
<T> void foo(A<? super A<T>> x);
}
class C {
<T extends IB & IA> void bar(T x, A<A<String>> y){
x.foo(y);
}
}
@@ -0,0 +1,11 @@
package pck;
class B<K> {}
class A<K> extends B<K> {
void foo(A<A<String>> b){
bar(b);
}
<T> void bar(B<? extends A<?>> a){}
<T> void bar(A<? extends A<T>> a){}
}
@@ -0,0 +1,21 @@
package pck;
import java.util.List;
import static pck.C.foo;
import static pck.D.foo;
class C {
static <T> void foo(List<T> x) { }
}
class D {
static <T extends List<?>> String foo(List<T> x) { return null; }
}
public class Main {
public static void main(String[] args){
List<List<String>> x = null;
foo(x).toCharArray();
}
}
@@ -0,0 +1,16 @@
package pck;
import static pck.C.foo;
import static pck.D.foo;
public class C {
public static void foo(){}
}
class D {
public static <T> void foo(){}
}
class B {
{
foo<error descr="Ambiguous method call: both 'C.foo()' and 'D.foo()' match">()</error>;
}
}
@@ -0,0 +1,17 @@
package pck;
import static pck.D.foo;
import static pck.C.foo;
public class C {
public static <T> void foo(Comparable<T> x){}
}
class D {
public static void foo(Comparable<?> x){}
}
class B{
public static void bar(Comparable<?> x){
foo<error descr="Ambiguous method call: both 'D.foo(Comparable<?>)' and 'C.foo(Comparable<?>)' match">(x)</error>;
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pck;
abstract class A {
abstract void foo(Object... x);
abstract void foo(int... x);
{
foo<error descr="Ambiguous method call: both 'A.foo(Object...)' and 'A.foo(int...)' match">(1)</error>;
}
}
@@ -0,0 +1,9 @@
package pck;
abstract class A {
abstract <T> void foo(T... y);
abstract <T> void foo(T[]... y);
void bar(){
foo();
}
}
@@ -17,6 +17,9 @@ package com.intellij.codeInsight.daemon;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.defUse.DefUseInspection;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.JavaVersionService;
import com.intellij.openapi.projectRoots.JavaVersionServiceImpl;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
@@ -60,4 +63,73 @@ public class AdvHighlightingJdk7Test extends DaemonAnalyzerTestCase {
public void testStaticAndSingleImportConflict() throws Exception {
doTest(BASE_PATH + "staticImportConflict/UsageMixed.java", BASE_PATH + "/staticImportConflict", false, false);
}
//ambiguous method calls
private void doTestAmbiguous() throws Exception {
final String name = getTestName(true);
final JavaVersionServiceImpl versionService = (JavaVersionServiceImpl)JavaVersionService.getInstance();
try {
versionService.setTestVersion(JavaSdkVersion.JDK_1_7);
doTest(BASE_PATH + name + "/pck/AmbiguousMethodCall.java", BASE_PATH + "/" + name, false, false);
}
finally {
versionService.setTestVersion(null);
}
}
public void testAmbiguous() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousArrayInSubst() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousTypeParamExtends() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousTypeParamNmb() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousTypeParamNmb1() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousInheritance() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousInheritance1() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousVarargs() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousVarargs1() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousMultiIntInheritance() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousMultipleTypeParamExtends() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousMultipleTypeParamExtends1() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousMultipleTypeParamExtends2() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousMultipleTypeParamExtends3() throws Exception {
doTestAmbiguous();
}
}