aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorvromero <none@none>2013-11-15 11:08:12 +0000
committervromero <none@none>2013-11-15 11:08:12 +0000
commit1ecce1151253a568713892fe57750b3da7142141 (patch)
tree1ffbaf5fce18d3f560aa275aee530283b6e9a9f0 /test
parentef11d62aaab62c958ffaa7a08aef215744730507 (diff)
8026231: Look at 'static' flag when checking method references
Reviewed-by: jjg, dlsmith
Diffstat (limited to 'test')
-rw-r--r--test/tools/javac/lambda/MethodReference22.java20
-rw-r--r--test/tools/javac/lambda/MethodReference22.out22
-rw-r--r--test/tools/javac/lambda/MethodReference51.java12
-rw-r--r--test/tools/javac/lambda/MethodReference68.out3
-rw-r--r--test/tools/javac/lambda/MethodReference73.java110
-rw-r--r--test/tools/javac/lambda/MethodReference73.out13
-rw-r--r--test/tools/javac/lambda/TargetType60.java2
-rw-r--r--test/tools/javac/lambda/TargetType60.out6
8 files changed, 151 insertions, 37 deletions
diff --git a/test/tools/javac/lambda/MethodReference22.java b/test/tools/javac/lambda/MethodReference22.java
index 9517ee00..094ef893 100644
--- a/test/tools/javac/lambda/MethodReference22.java
+++ b/test/tools/javac/lambda/MethodReference22.java
@@ -48,19 +48,19 @@ class MethodReference22 {
}
static void test2() {
- SAM2 s1 = MethodReference22::m1; //ambiguous
- call2(MethodReference22::m1); //ambiguous
- SAM2 s2 = MethodReference22::m2; //ambiguous
- call2(MethodReference22::m2); //ambiguous
- SAM2 s3 = MethodReference22::m3; //ambiguous
- call2(MethodReference22::m3); //ambiguous
- SAM2 s4 = MethodReference22::m4; //ambiguous
- call2(MethodReference22::m4); //ambiguous
+ SAM2 s1 = MethodReference22::m1; //ok
+ call2(MethodReference22::m1); //ok
+ SAM2 s2 = MethodReference22::m2; //ok
+ call2(MethodReference22::m2); //ok
+ SAM2 s3 = MethodReference22::m3; //fail
+ call2(MethodReference22::m3); //fail
+ SAM2 s4 = MethodReference22::m4; //fail
+ call2(MethodReference22::m4); //fail
}
static void test3() {
- call3(MethodReference22::m1); //fail
- call3(MethodReference22::m2); //ok
+ call3(MethodReference22::m1); //ok
+ call3(MethodReference22::m2); //ambiguous
call3(MethodReference22::m3); //ok
call3(MethodReference22::m4); //fail
}
diff --git a/test/tools/javac/lambda/MethodReference22.out b/test/tools/javac/lambda/MethodReference22.out
index dfd2ebe5..4a857282 100644
--- a/test/tools/javac/lambda/MethodReference22.out
+++ b/test/tools/javac/lambda/MethodReference22.out
@@ -1,19 +1,11 @@
MethodReference22.java:40:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m1(java.lang.String))
-MethodReference22.java:41:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m1(java.lang.String))
+MethodReference22.java:41:9: compiler.err.cant.apply.symbol: kindname.method, call1, MethodReference22.SAM1, @999, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.mref))
MethodReference22.java:46:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m4(java.lang.String))
-MethodReference22.java:47:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m4(java.lang.String))
-MethodReference22.java:51:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m1, kindname.method, m1(MethodReference22,java.lang.String), MethodReference22, kindname.method, m1(java.lang.String), MethodReference22))
-MethodReference22.java:52:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1401, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m1, kindname.method, m1(MethodReference22,java.lang.String), MethodReference22, kindname.method, m1(java.lang.String), MethodReference22)))
-MethodReference22.java:53:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m2, kindname.method, m2(MethodReference22,java.lang.String), MethodReference22, kindname.method, m2(java.lang.String), MethodReference22))
-MethodReference22.java:54:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1504, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m2, kindname.method, m2(MethodReference22,java.lang.String), MethodReference22, kindname.method, m2(java.lang.String), MethodReference22)))
-MethodReference22.java:55:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m3, kindname.method, m3(MethodReference22,java.lang.String), MethodReference22, kindname.method, m3(java.lang.String), MethodReference22))
-MethodReference22.java:56:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1607, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m3, kindname.method, m3(MethodReference22,java.lang.String), MethodReference22, kindname.method, m3(java.lang.String), MethodReference22)))
+MethodReference22.java:47:9: compiler.err.cant.apply.symbol: kindname.method, call1, MethodReference22.SAM1, @1270, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.mref))
+MethodReference22.java:55:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m3(MethodReference22,java.lang.String))
+MethodReference22.java:56:9: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1574, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.mref))
MethodReference22.java:57:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22))
-MethodReference22.java:58:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1710, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22)))
-MethodReference22.java:62:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22
-MethodReference22.java:62:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m1(java.lang.String))
+MethodReference22.java:58:14: compiler.err.cant.apply.symbol: kindname.method, call2, MethodReference22.SAM2, @1667, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22)))
MethodReference22.java:63:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22
-MethodReference22.java:64:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22
-MethodReference22.java:65:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference22.SAM1), MethodReference22, kindname.method, call3(MethodReference22.SAM2), MethodReference22
-MethodReference22.java:65:15: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m4(java.lang.String))
-18 errors
+MethodReference22.java:65:14: compiler.err.cant.apply.symbol: kindname.method, call3, MethodReference22.SAM2, @1881, kindname.class, MethodReference22, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference22,java.lang.String), MethodReference22, kindname.method, m4(java.lang.String), MethodReference22)))
+10 errors
diff --git a/test/tools/javac/lambda/MethodReference51.java b/test/tools/javac/lambda/MethodReference51.java
index 1ce3d74f..be0c65b0 100644
--- a/test/tools/javac/lambda/MethodReference51.java
+++ b/test/tools/javac/lambda/MethodReference51.java
@@ -36,11 +36,11 @@ class TestMethodReference51 {
static void test() {
- IntSam s1 = MethodReference51::unknown; //method not found
- IntSam s2 = MethodReference51::f; //inapplicable method
- IntSam s3 = MethodReference51::g; //inapplicable methods
- IntegerIntegerSam s4 = MethodReference51::g; //ambiguous
- IntSam s5 = MethodReference51::h; //static error
- IntSam s6 = MethodReference51.foo::j; //inaccessible method
+ IntSam s1 = MethodReference51::unknown; //fail
+ IntSam s2 = MethodReference51::f; //fail
+ IntSam s3 = MethodReference51::g; //fail
+ IntegerIntegerSam s4 = MethodReference51::g; //fail
+ IntSam s5 = MethodReference51::h; //fail
+ IntSam s6 = MethodReference51.foo::j; //fail
}
}
diff --git a/test/tools/javac/lambda/MethodReference68.out b/test/tools/javac/lambda/MethodReference68.out
index 2db24d17..1319f33a 100644
--- a/test/tools/javac/lambda/MethodReference68.out
+++ b/test/tools/javac/lambda/MethodReference68.out
@@ -1,2 +1,3 @@
MethodReference68.java:21:10: compiler.err.cant.apply.symbol: kindname.method, g, MethodReference68.F<Z>,Z[], @493,int, kindname.class, MethodReference68, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, MethodReference68.Foo,java.lang.Object)
-1 error
+MethodReference68.java:21:12: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, getName())
+2 errors
diff --git a/test/tools/javac/lambda/MethodReference73.java b/test/tools/javac/lambda/MethodReference73.java
new file mode 100644
index 00000000..a65d85bc
--- /dev/null
+++ b/test/tools/javac/lambda/MethodReference73.java
@@ -0,0 +1,110 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8026231
+ * @summary Look at 'static' flag when checking method references
+ * @compile/fail/ref=MethodReference73.out -XDrawDiagnostics MethodReference73.java
+ */
+
+public class MethodReference73 {
+
+ interface SAM {
+ void m(MethodReference73 rec, String x);
+ }
+
+ void m1(MethodReference73 rec, String x) {}
+ static void m1(MethodReference73 rec, Object x) {}
+ void m1(String x) {}
+
+ static void m2(MethodReference73 rec, String x) {}
+ void m2(Object x) {}
+ static void m2(String x) {}
+
+ static void m3(MethodReference73 rec, String x) {}
+ void m3(String x) {}
+
+ void m4(MethodReference73 rec, String x) {}
+ static void m4(MethodReference73 rec, Object x) {}
+ static void m4(String x) {}
+ void m4(Object x) {}
+
+ static void m5(MethodReference73 rec, String x) {}
+ static void m5(String x) {}
+
+ static void m6(MethodReference73 rec, String x) {}
+ void m6(String x, int i) {}
+
+ void m7(MethodReference73 rec, String x) {}
+ void m7(String x) {}
+
+ static void m8(MethodReference73 rec, String x, int i) {}
+ void m8(String x) {}
+
+ void m9(MethodReference73 rec, String x) {}
+ static void m9(MethodReference73 rec, Object x) {}
+ static void m9(String x) {}
+
+ void m10(MethodReference73 rec, String x) {}
+ static void m10(MethodReference73 rec, Object x) {}
+ void m10(String x, int i) {}
+
+ void m11(MethodReference73 rec, String x) {}
+ void m11(Object x) {}
+ static void m11(String x) {}
+
+ static void m12(MethodReference73 rec, String x, int i) {}
+ void m12(Object x) {}
+ static void m12(String x) {}
+
+ void m13(MethodReference73 rec, String x) {}
+ void m13(String x, int i) {}
+
+ static void m14(MethodReference73 rec, String x, int i) {}
+ static void m14(String x) {}
+
+ void m15(MethodReference73 rec, String x) {}
+ static void m15(String x) {}
+
+ static void m16(MethodReference73 rec, String x, int i) {}
+ void m16(String x, int i) {}
+
+ /** For method references with a type selector two searches are performed.
+ * Each of them may yield one of the following results:
+ * I) a good match
+ * II) a bad match more specific than a good match
+ * III) a bad match with no good matches
+ * IV) no applicable method found
+ *
+ * Whether a match is considered to be good or not depends on the staticness
+ * of the matched method. The expected result of the first search is a static
+ * method. The expected result of the second search is an instance method.
+ *
+ * If the most specific method has the wrong staticness but there is an
+ * applicable method with the right staticness then we have the (II) case.
+ * The (III) case is reserved for those cases when the most specific method
+ * has the wrong staticness but there is no applicable method with the right
+ * staticness.
+ */
+
+ static void test() {
+ SAM s1 = MethodReference73::m1; //(II, I) ambiguous
+ SAM s2 = MethodReference73::m2; //(I, II) ambiguous
+ SAM s3 = MethodReference73::m3; //(I, I) ambiguous
+ SAM s4 = MethodReference73::m4; //(II, II) ambiguous
+
+ SAM s5 = MethodReference73::m5; //(I, III) first search's result gets selected
+ SAM s6 = MethodReference73::m6; //(I, IV) first search's result gets selected
+
+ SAM s7 = MethodReference73::m7; //(III, I) second search's result gets selected
+ SAM s8 = MethodReference73::m8; //(IV, I) second search's result gets selected
+
+ SAM s9 = MethodReference73::m9; //(II, III) method matched by first search has the wrong staticness
+ SAM s10 = MethodReference73::m10; //(II, IV) method matched by first search has the wrong staticness
+ SAM s11 = MethodReference73::m11; //(III, II) method matched by second search has the wrong staticness
+ SAM s12 = MethodReference73::m12; //(IV, II) method matched by second search has the wrong staticness
+ SAM s13 = MethodReference73::m13; //(III, IV) method matched by first search has the wrong staticness
+ SAM s14 = MethodReference73::m14; //(IV, III) method matched by second search has the wrong staticness
+ SAM s15 = MethodReference73::m15; //(III, III) method matched by first search has the wrong staticness
+
+ SAM s16 = MethodReference73::m16; //(IV, IV) incompatible types, invalid method reference
+ }
+}
diff --git a/test/tools/javac/lambda/MethodReference73.out b/test/tools/javac/lambda/MethodReference73.out
new file mode 100644
index 00000000..717c414a
--- /dev/null
+++ b/test/tools/javac/lambda/MethodReference73.out
@@ -0,0 +1,13 @@
+MethodReference73.java:89:18: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m1, kindname.method, m1(MethodReference73,java.lang.String), MethodReference73, kindname.method, m1(java.lang.String), MethodReference73))
+MethodReference73.java:90:18: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m2, kindname.method, m2(MethodReference73,java.lang.String), MethodReference73, kindname.method, m2(java.lang.String), MethodReference73))
+MethodReference73.java:91:18: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m3, kindname.method, m3(MethodReference73,java.lang.String), MethodReference73, kindname.method, m3(java.lang.String), MethodReference73))
+MethodReference73.java:92:18: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.ref.ambiguous: m4, kindname.method, m4(MethodReference73,java.lang.String), MethodReference73, kindname.method, m4(java.lang.String), MethodReference73))
+MethodReference73.java:100:18: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m9(MethodReference73,java.lang.String))
+MethodReference73.java:101:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m10(MethodReference73,java.lang.String))
+MethodReference73.java:102:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.method.in.unbound.lookup: kindname.method, m11(java.lang.String))
+MethodReference73.java:103:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.method.in.unbound.lookup: kindname.method, m12(java.lang.String))
+MethodReference73.java:104:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m13(MethodReference73,java.lang.String))
+MethodReference73.java:105:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.static.method.in.unbound.lookup: kindname.method, m14(java.lang.String))
+MethodReference73.java:106:19: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, m15(MethodReference73,java.lang.String))
+MethodReference73.java:108:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbols: kindname.method, m16, MethodReference73,java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, MethodReference73, m16(MethodReference73,java.lang.String,int), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, MethodReference73, m16(java.lang.String,int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: MethodReference73, java.lang.String)))}))
+12 errors
diff --git a/test/tools/javac/lambda/TargetType60.java b/test/tools/javac/lambda/TargetType60.java
index 0506f39a..b5acd32d 100644
--- a/test/tools/javac/lambda/TargetType60.java
+++ b/test/tools/javac/lambda/TargetType60.java
@@ -57,7 +57,7 @@ class TargetType60 {
static void testUnbound() {
TargetType60 s1 = u(TargetType60::n0); //ok - resolves to u(Sam1)
- TargetType60 s2 = u(TargetType60::n1); //ambiguous (u(Sam1), u(Sam2) apply)
+ TargetType60 s2 = u(TargetType60::n1); //ok - resolves to u(Sam2)
TargetType60 s3 = u(TargetType60::n2); //none is applicable
TargetType60 s4 = u(TargetType60::n01);//ambiguous (u(Sam1), u(Sam2) apply)
TargetType60 s5 = u(TargetType60::n012);//ambiguous (u(Sam1), u(Sam2) apply)
diff --git a/test/tools/javac/lambda/TargetType60.out b/test/tools/javac/lambda/TargetType60.out
index e0bf52fc..2613d0bb 100644
--- a/test/tools/javac/lambda/TargetType60.out
+++ b/test/tools/javac/lambda/TargetType60.out
@@ -1,8 +1,6 @@
TargetType60.java:54:21: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType60.Sam0), TargetType60, kindname.method, <U>g(TargetType60.Sam1<U>), TargetType60
TargetType60.java:55:21: compiler.err.ref.ambiguous: g, kindname.method, <U>g(TargetType60.Sam1<U>), TargetType60, kindname.method, <U>g(TargetType60.Sam2<U,java.lang.String>), TargetType60
-TargetType60.java:60:27: compiler.err.ref.ambiguous: u, kindname.method, <U>u(TargetType60.Sam1<U>), TargetType60, kindname.method, <U>u(TargetType60.Sam2<U,java.lang.String>), TargetType60
-TargetType60.java:60:29: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, n1(java.lang.String))
-TargetType60.java:61:29: compiler.err.invalid.mref: kindname.method, (compiler.misc.non-static.cant.be.ref: kindname.method, n2(TargetType60,java.lang.String))
+TargetType60.java:61:27: compiler.err.cant.apply.symbols: kindname.method, u, @1639,{(compiler.misc.inapplicable.method: kindname.method, TargetType60, <U>u(TargetType60.Sam1<U>), (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, n2, TargetType60,java.lang.String, U, kindname.class, TargetType60, (compiler.misc.arg.length.mismatch))))),(compiler.misc.inapplicable.method: kindname.method, TargetType60, <U>u(TargetType60.Sam2<U,java.lang.String>), (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.resolve.location.args: kindname.method, n2, , U,java.lang.String, (compiler.misc.location: kindname.class, TargetType60, null)))))}
TargetType60.java:62:27: compiler.err.ref.ambiguous: u, kindname.method, <U>u(TargetType60.Sam1<U>), TargetType60, kindname.method, <U>u(TargetType60.Sam2<U,java.lang.String>), TargetType60
TargetType60.java:63:27: compiler.err.ref.ambiguous: u, kindname.method, <U>u(TargetType60.Sam1<U>), TargetType60, kindname.method, <U>u(TargetType60.Sam2<U,java.lang.String>), TargetType60
-7 errors
+5 errors