method refs: filter more specific

This commit is contained in:
anna
2012-10-02 17:57:02 +02:00
parent 340ebdccdb
commit 9c796a4342
7 changed files with 189 additions and 16 deletions

View File

@@ -54,7 +54,7 @@ class MyTest2 {
static void call(Integer i, I s) { }
static void test() {
call<error descr="Cannot resolve method 'call(int, <method reference>)'">(1, MyTest2::m)</error>; //ambiguous
call<error descr="Ambiguous method call: both 'MyTest2.call(int, I)' and 'MyTest2.call(Integer, I)' match">(1, MyTest2::m)</error>; //ambiguous
}
}

View File

@@ -0,0 +1,52 @@
class MyTest {
interface I1 {
void m(String s);
}
interface I2 {
void m(Integer s);
}
interface I3 {
void m(Object o);
}
static <T extends Number> void m(T p) {}
static <T1> void m1(T1 fx) { }
static void foo(I1 i) {}
static void foo(I2 i) {} //m
static void foo(I3 i) {}
static {
foo(MyTest::m);
foo<error descr="Ambiguous method call: both 'MyTest.foo(I2)' and 'MyTest.foo(I3)' match">(MyTest::m1)</error>;
}
}
class MyTest1 {
interface I1 {
void m(Integer s);
}
interface I2 {
void m(Integer s);
}
static <T extends Number> void m(T p) { }
static <T> void m1(T p) { }
static void foo1(I1 i) { }
static void foo2(I1 i) { }
static void foo2(I2 i) { }
static {
foo1(MyTest1::m);
foo2<error descr="Ambiguous method call: both 'MyTest1.foo2(I1)' and 'MyTest1.foo2(I2)' match">(MyTest1::m)</error>;
foo1(MyTest1::m1);
foo2<error descr="Ambiguous method call: both 'MyTest1.foo2(I1)' and 'MyTest1.foo2(I2)' match">(MyTest1::m1)</error>;
}
}

View File

@@ -1,6 +1,5 @@
class MethodReference27 {
interface SAM {
class MyTest1 {
interface I {
void m(int i1, int i2);
}
@@ -13,10 +12,63 @@ class MethodReference27 {
static void m2(int... is) { }
static void m2(double... ds) {}
static void m3(int... is) { }
static void m3(Object... ds) {}
public static void main(String[] args) {
SAM s1 = MethodReference27::m1;
s1.m(42,42);
SAM s2 = MethodReference27 :: m2;
s2.m(42,42);
I i1 = MyTest1::m1;
i1.m(42,42);
I i2 = MyTest1 :: m2;
i2.m(42,42);
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest1.I'">I i3 = MyTest1 :: m3;</error>
}
}
class MyTest {
interface I1 {
void m(int i);
}
interface I2 {
void m(MyTest t, int i);
}
static void static_1(Integer i) {}
static void static_2(Integer i1, Integer i2) {}
static void static_3(String s) {}
static void static_4(String... ss) {}
void _1(Integer i) {}
void _2(Integer i1, Integer i2) {}
void _3(String s) {}
void _4(String... ss) {}
static {
I1 i1 = MyTest::static_1;
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i2 = MyTest::static_2;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i3 = MyTest::static_3;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i4 = MyTest::static_4;</error>
}
{
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_1 = MyTest::_1;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_2 = MyTest::_2;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_3 = MyTest::_3;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_4 = MyTest::_4;</error>
I1 i1 = this::_1;
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i2 = this::_2;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i3 = this::_3;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i4 = this::_4;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i21 = MyTest::m1;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i22 = MyTest::m2;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i23 = MyTest::m3;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i24 = MyTest::m4;</error>
}
}