constructor reference: don't ignore constructor parameters during method reference inference (IDEA-185578)

GitOrigin-RevId: e836468e05db28157713e9edd3c70382f8ecdebc
This commit is contained in:
Anna Kozlova
2019-06-12 12:40:39 +02:00
committed by intellij-monorepo-bot
parent 89bb3c6fda
commit 91f7445298
12737 changed files with 488037 additions and 160329 deletions

View File

@@ -77,7 +77,7 @@ abstract class AbstractCollection<E> implements Collection<E> {
public boolean add(E e) {
return true;
}
public boolean addAll(Collection<? extends E> <warning descr="Parameter 'c' is never used">c</warning>) {
public boolean addAll(Collection<? extends E> c) {
boolean modified = false;
return modified;
}

View File

@@ -7,7 +7,7 @@ interface B<BT> {
class Test {
public static void test() {
method1(Test::<error descr="Incompatible types: A<capture of ? super M> is not convertible to A<? super String>">method2</error>);
method1<error descr="'method1(B<A<? super M>>)' in 'Test' cannot be applied to '(<method reference>)'">(Test::method2)</error>;
}
static <M> void method1(B<A<? super M>> arg) { }

View File

@@ -0,0 +1,27 @@
import java.util.function.Function;
class MyTest {
{
Function<B, Try<A>> aNew = Try::new;
Try<B> bTry = new Try<>(new B());
Try<A> aTry = bTry.flatMap(Try::new);
}
private static class A { }
private static class B extends A { }
private static class Try<T> {
public Try(T t) {
}
public Try(Exception e) {
}
public <U> Try<U> flatMap(Function<? super T, Try<U>> mapper) {
return null;
}
}
}

View File

@@ -0,0 +1,23 @@
class Logger {}
class Test {
public static void main(String[] args) {
User user = new User();
Logger logger = null;
foo<error descr="'foo(T, java.util.logging.Logger, java.util.function.Function<T,java.lang.String>)' in 'Test' cannot be applied to '(User, Logger, <method reference>)'">(user, logger, User::getId)</error>;
}
private static <T> void foo(T val, java.util.logging.Logger logger, java.util.function.Function<T, String> idFunction) { }
}
class User {
private String Id;
public String getId() {
return Id;
}
public void setId(String id) {
this.Id = id;
}
}

View File

@@ -6,11 +6,11 @@ class Test {
Test m(List<Integer> l1, List<Integer> l2);
}
static Test meth(List<Integer>... <warning descr="Parameter 'lli' is never used">lli</warning>) {
static Test meth(List<Integer>... lli) {
return null;
}
Test(List<Integer>... <warning descr="Parameter 'lli' is never used">lli</warning>) {}
Test(List<Integer>... lli) {}
{
I <warning descr="Variable 'i1' is never used">i1</warning> = <warning descr="Unchecked generics array creation for varargs parameter">Test::meth</warning>;

View File

@@ -31,8 +31,8 @@ class Test {
String i1 = instanceCall(this::m0);
String i2 = instanceCall(this::m1);
String i3 = instanceCall(this::m2);
String i4 = instanceCall<error descr="Ambiguous method call: both 'Test.instanceCall(I0)' and 'Test.instanceCall(I1<Object>)' match">(this::m01)</error>;
String i5 = instanceCall<error descr="Ambiguous method call: both 'Test.instanceCall(I0)' and 'Test.instanceCall(I1<Object>)' match">(this::m012)</error>;
String i4 = instanceCall(this::<error descr="Cannot resolve method 'm01'">m01</error>);
String i5 = instanceCall(this::<error descr="Cannot resolve method 'm012'">m012</error>);
}
void n0() { }
@@ -53,7 +53,7 @@ class Test {
Test s1 = staticCall(Test::n0);
Test s2 = staticCall(Test::n1);
Test s3 = staticCall<error descr="Cannot resolve method 'staticCall(<method reference>)'">(Test::n2)</error>;
Test s4 = staticCall<error descr="Ambiguous method call: both 'Test.staticCall(I1<Object>)' and 'Test.staticCall(I2<Object, String>)' match">(Test::n01)</error>;
Test s5 = staticCall<error descr="Ambiguous method call: both 'Test.staticCall(I1<Object>)' and 'Test.staticCall(I2<Object, String>)' match">(Test::n012)</error>;
Test s4 = staticCall(Test::<error descr="Cannot resolve method 'n01'">n01</error>);
Test s5 = staticCall(Test::<error descr="Cannot resolve method 'n012'">n012</error>);
}
}

View File

@@ -34,7 +34,7 @@ class Test {
{
Set<String> m = replyWith(this::query);
System.out.println(m);
Set<String> m1 = replyWith<error descr="Ambiguous method call: both 'Test.replyWith(Function<Object, List<Object>>)' and 'Test.replyWith(Callable<List<Object>>)' match">(this::query1)</error>;
Set<String> m1 = replyWith(this::<error descr="Cannot resolve method 'query1'">query1</error>);
System.out.println(m1);
}
}

View File

@@ -10,6 +10,6 @@ class Test {
static void m(Test t, Object s) {}
static void test() {
<error descr="Incompatible types. Found: '<method reference>', required: 'Test.I'">I i = Test::m;</error>
I i = Test::<error descr="Cannot resolve method 'm'">m</error>;
}
}

View File

@@ -1,7 +1,7 @@
import java.util.stream.Stream;
class A {
private void test5(Integer <warning descr="Parameter 'i' is never used">i</warning>, String... <warning descr="Parameter 'strings' is never used">strings</warning>) {}
private void test5(Integer i, String... strings) {}
private void <warning descr="Private method 'test5(java.lang.Integer, java.lang.Integer, java.lang.String...)' is never used">test5</warning>(Integer i, Integer b, String... strings) {
System.out.println(i);
System.out.println(b);