lambda: return type checks initial

This commit is contained in:
anna
2012-07-20 15:43:06 +02:00
parent d019234100
commit c3276bd56e
6 changed files with 177 additions and 2 deletions

View File

@@ -0,0 +1,72 @@
class ReturnTypeIncompatibility {
interface I1<T extends Number> {
T m(Integer x);
}
interface I2<L extends String> {
L m(Integer x);
}
interface I3<K> {
void m(Integer x);
}
static <P extends Number> void call(I1<P> i1) {
i1.m(1);
}
static <P extends String> void call(I2<P> i2) {
i2.m(2);
}
static <Q> void call(I3<Q> i3) {
i3.m(3);
}
public static void main(String[] args) {
call(i-> {return i;});
}
}
class ReturnTypeCompatibility {
interface I1<T extends Number> {
T m(T x);
}
interface I2<L extends String> {
L m(L x);
}
interface I3<K> {
void m(K x);
}
static <P extends Number> void call(I1<P> i1) {
i1.m(null);
}
static <P extends String> void call(I2<P> i2) {
i2.m(null);
}
static <Q> void call(I3<Q> i3) {
i3.m(null);
}
public static void main(String[] args) {
<error descr="Cannot resolve method 'call(<lambda expression>)'">call</error>(i-> {return i;});
}
}
class ReturnTypeChecks1 {
interface I<K extends Number, V extends Number> {
V m(K k);
}
I<Integer, Integer> accepted = i -> { return i; };
<error descr="Incompatible types. Found: '<lambda expression>', required: 'ReturnTypeChecks1.I<java.lang.Double,java.lang.Integer>'">I<Double, Integer> rejected = i -> { return i; };</error>
}

View File

@@ -16,4 +16,20 @@ class Foo {
bar((int i) -> {System.out.println(i);});
}
void bar(I i){}
}
class ReturnTypeCompatibility {
interface I1<L> {
L m(L x);
}
static <P> void call(I1<P> i2) {
i2.m(null);
}
public static void main(String[] args) {
call((String i)->{ return i;});
call<error descr="'call(ReturnTypeCompatibility.I1<java.lang.Object>)' in 'ReturnTypeCompatibility' cannot be applied to '(<lambda expression>)'">((int i)->{ return i;})</error>;
}
}

View File

@@ -1,3 +1,5 @@
import java.lang.Integer;
interface I {
void m(int i);
}
@@ -18,6 +20,14 @@ class Foo {
<error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">int i = ab;</error>
};
{
A<String> a1;
a1 = (ab)->{
String s = ab;
<error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">int i = ab;</error>
};
}
A<Integer> bazz() {
bar((o) -> {
String s = o;
@@ -33,3 +43,18 @@ class Foo {
void bar(A<String> a){}
}
class CastInference {
public interface I1<X> {
X m();
}
public interface I2<X> {
X m();
}
public static <X> void foo(I1<X> s) {}
public static <X> void foo(I2<X> s) {}
public static void main(String[] args) {
foo((I1<Integer>)() -> 42);
I1<Integer> i1 = (I1<Integer>)() -> 42;
}
}