new inference: overload resolution for SAM return type for implicit lambda should be ignored

This commit is contained in:
anna
2013-09-25 16:12:44 +02:00
parent 66926021e9
commit f5257087e9
19 changed files with 43 additions and 39 deletions
@@ -5,7 +5,7 @@ class Test {
<K extends Throwable> void foo(F<K> f) throws K { }
{
foo(<error descr="Cyclic inference">(t)->{}</error>);
<error descr="Unhandled exception: java.lang.Throwable">foo((t)->{});</error>
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo((ClassNotFoundException t)->{});</error>
}
}
@@ -1,6 +1,6 @@
public interface IDEA99969 {
default IntStream distinct(Stream s) {
return s.map(i -> (int) i);
return s.map<error descr="Ambiguous method call: both 'Stream.map(Function)' and 'Stream.map(IntFunction)' match">(i -> <error descr="Inconvertible types; cannot cast '<lambda parameter>' to 'int'">(int) i</error>)</error>;
}
}
interface Stream<T> {
@@ -8,19 +8,19 @@ public class Test<A, B extends Number> {
}
private void foo(IO<? extends A> <warning descr="Parameter 'p' is never used">p</warning>) {}
private void <warning descr="Private method 'foo(Test.IO<? extends A>)' is never used">foo</warning>(IO<? extends A> <warning descr="Parameter 'p' is never used">p</warning>) {}
private void <warning descr="Private method 'foo(Test.IN<? extends B>)' is never used">foo</warning>(IN<? extends B> <warning descr="Parameter 'p' is never used">p</warning>) {}
private static class Inner<A extends Object, B extends Number> {
private void <warning descr="Private method 'm8(Test.IO<? extends A>)' is never used">m8</warning>(IO<? extends A> <warning descr="Parameter 'p' is never used">p</warning>) {}
private void m8(IN<? extends B> <warning descr="Parameter 'p' is never used">p</warning>) {}
private void <warning descr="Private method 'm8(Test.IN<? extends B>)' is never used">m8</warning>(IN<? extends B> <warning descr="Parameter 'p' is never used">p</warning>) {}
}
public static void main(String[] args) {
Inner<Number, Double> inn = new Inner<>();
inn.m8(p -> 1.0);
new Test<Number, Integer>().foo(p -> 1.0);
inn.m8<error descr="Ambiguous method call: both 'Inner.m8(IO<? extends Number>)' and 'Inner.m8(IN<? extends Double>)' match">(p -> 1.0)</error>;
new Test<Number, Integer>().foo<error descr="Ambiguous method call: both 'Test.foo(IO<? extends Number>)' and 'Test.foo(IN<? extends Integer>)' match">(p -> 1.0)</error>;
}
}
@@ -8,8 +8,8 @@ class Test {
IntStream mi = sp.map(Inner::foo);
Stream<Integer> mI = sp.map(Inner::fooBoxed);
IntStream li = sp.map(inner->inner.foo());
Stream<Integer> lI = sp.map(inner -> inner.fooBoxed());
IntStream li = sp.map<error descr="Ambiguous method call: both 'Stream.map(Function<? super Inner,?>)' and 'Stream.map(IntFunction<? super Inner>)' match">(inner->inner.<error descr="Cannot resolve method 'foo()'">foo</error>())</error>;
Stream<Integer> lI = sp.map<error descr="Ambiguous method call: both 'Stream.map(Function<? super Inner,? extends Integer>)' and 'Stream.map(IntFunction<? super Inner>)' match">(inner -> inner.<error descr="Cannot resolve method 'fooBoxed()'">fooBoxed</error>())</error>;
}
interface Stream<T> {
@@ -1,15 +1,15 @@
class IntStream {
private void foo(IntStream s) {
s.map(i -> 1 << i);
s.map(i -> 1);
s.map(i -> i);
s.map<error descr="Ambiguous method call: both 'IntStream.map(IntUnaryOperator)' and 'IntStream.map(ObjIntFunction<Integer>)' match">(i -> <error descr="Operator '<<' cannot be applied to 'int', '<lambda parameter>'">1 << i</error>)</error>;
s.map<error descr="Ambiguous method call: both 'IntStream.map(IntUnaryOperator)' and 'IntStream.map(ObjIntFunction<Integer>)' match">(i -> 1)</error>;
s.map<error descr="Ambiguous method call: both 'IntStream.map(IntUnaryOperator)' and 'IntStream.map(ObjIntFunction<Integer>)' match">(i -> i)</error>;
}
public static void main(String[] args) {
new IntStream().foo(null);
}
private IntStream map(IntUnaryOperator mapper) {
private IntStream <warning descr="Private method 'map(IntUnaryOperator)' is never used">map</warning>(IntUnaryOperator mapper) {
System.out.println(mapper);
return null;
}
@@ -15,13 +15,13 @@ class InferenceFromArgs {
private static <E> void bazz(I<? super E, Integer> i) { }
void foo(B<Integer> b) {
bar(null, <error descr="Cyclic inference">(k, v) -> v</error>);
bar(null, (k, v) -> v);
bar(null, null);
bar(b, (k, v) -> {return v;});
bar(b, (k, v) -> {<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.String'">String i = k;</error> return v;});
bar(b, (k, v) -> {Integer i = k; return v;});
bazz(<error descr="Cyclic inference">(k, v) -> v</error>);
bazz((k, v) -> v);
bazz((k, v) -> {<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">int i = k;</error> return v;});
}
@@ -12,7 +12,7 @@ class Test1 {
class Test2 {
protected <T, U> U exerciseOps(TestData<T> data, TerminalOp<T, U> terminal, IntermediateOp... ops) {
return exerciseOps(data, <error descr="Cyclic inference">(u, v) -> u.equals(v)</error>, terminal);
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'U'">return exerciseOps(data, (u, v) -> u.equals(v), terminal);</error>
}
}
@@ -23,15 +23,15 @@ class Test3 {
static <T> void bar(I<T> i, List<T> l){
bar(x -> {}, l);
bar(<error descr="Cyclic inference">x -> {}</error>, null);
bar(x -> {}, null);
bar((I<T>)x -> {}, null);
bar((T x) -> {}, null);
bar(x -> {}, new ArrayList<T>());
bar(<error descr="Cyclic inference">x -> {}</error>, new ArrayList());
bar(x -> {}, new ArrayList());
}
static {
bar(<error descr="Cyclic inference">x->{}</error>, new ArrayList());
bar(x->{}, new ArrayList());
}
}
@@ -21,7 +21,7 @@ class NoInferenceResult {
m((String s1) -> s1.length());
m((String s1) -> s1);
m1(<error descr="Cyclic inference">() -> { }</error>);
m1<error descr="'m1(T)' in 'NoInferenceResult' cannot be applied to '(<lambda expression>)'">(() -> { })</error>;
Foo<String> foo = new Foo<String>();
foo.map(v -> null);
@@ -25,7 +25,7 @@ class ReturnTypeIncompatibility {
}
public static void main(String[] args) {
call(i-> {return i;});
call<error descr="Ambiguous method call: both 'ReturnTypeIncompatibility.call(I1<Integer>)' and 'ReturnTypeIncompatibility.call(I2<String>)' match">(i-> {return i;})</error>;
}
}
@@ -21,9 +21,9 @@ class Test {
}
void foo(Foo<String> as, final Foo<Character> ac) {
boolean b1 = as.forAll(s -> ac.forAll(c -> false));
String s1 = as.forAll(s -> ac.forAll(c -> ""));
<error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">boolean b2 = as.forAll(s -> ac.forAll(c -> ""));</error>
boolean b1 = as.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<String,Boolean>)' and 'Foo.forAll(II<String,String>)' match">(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> false)</error>)</error>;
String s1 = as.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<String,Boolean>)' and 'Foo.forAll(II<String,String>)' match">(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> "")</error>)</error>;
boolean b2 = as.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<String,Boolean>)' and 'Foo.forAll(II<String,String>)' match">(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> "")</error>)</error>;
String s2 = as.forAll2(s -> ac.forAll2(<error descr="Incompatible return type boolean in lambda expression">c -> false</error>));
boolean b3 = as.forAll((I<String, Boolean>)s -> ac.forAll((I<Character, Boolean>)<error descr="Incompatible return type String in lambda expression">c -> ""</error>));
String s3 = as.forAll((II<String, String>)s -> ac.forAll((II<Character, String>)<error descr="Incompatible return type boolean in lambda expression">c -> false</error>));
@@ -64,8 +64,8 @@ class Test2 {
static <T> void bar3(I<T> i, T t){}
{
bar(<error descr="Cyclic inference">x -> x</error>);
bar1(<error descr="Cyclic inference">x -> x</error>);
bar(x -> x);
bar1(x -> x);
bar2(1, <error descr="Incompatible return type List<Integer> in lambda expression">x -> x</error>);
bar2("", <error descr="Incompatible return type List<String> in lambda expression">x -> x</error>);
bar3(<error descr="Incompatible return type List<String> in lambda expression">x -> x</error>, "");
@@ -84,8 +84,8 @@ class Test3 {
static <T> void bar3(I<T> i, T t){}
{
bar(<error descr="Cyclic inference">x -> x</error>);
bar1(<error descr="Cyclic inference">x -> x</error>);
bar(x -> x);
bar1(x -> x);
bar2(1, x -> x);
bar2("", x -> x);
@@ -8,13 +8,13 @@ class NoLambda {
void bazz() {
bar(null);
bar(<error descr="Cyclic inference">(z)-> {System.out.println();}</error>);
bar((z)-> {System.out.println();});
}
static <T> T id(T i2) {return i2;}
{
id(<error descr="Cyclic inference">() -> {System.out.println("hi");}</error>);
id<error descr="'id(T)' in 'NoLambda' cannot be applied to '(<lambda expression>)'">(() -> {System.out.println("hi");})</error>;
NoLambda.<Runnable>id(() -> {System.out.println("hi");});
}
}
@@ -30,8 +30,8 @@ class ReturnTypeCompatibility {
public static void main(String[] args) {
call((String i)->{ return i;});
call(<error descr="Cyclic inference">i->{ return i;}</error>);
call(<error descr="Cyclic inference">i->""</error>);
call(i->{ return i;});
call(i->"");
call((<error descr="Incompatible parameter types in lambda expression">int i</error>)->{ return i;});
}
}