8148100: Convert lambda most specific positive tests to check runtime behavior

Reviewed-by: mcimadamore
This commit is contained in:
Bernard Blaser 2017-01-05 11:16:39 -08:00 committed by Vicente Romero
parent 01fc0b7771
commit 37f7ab915c
9 changed files with 89 additions and 46 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,13 @@
* @test * @test
* @bug 8034223 * @bug 8034223
* @summary Structural most-specific logic for lambdas, method refs, parens, and conditionals * @summary Structural most-specific logic for lambdas, method refs, parens, and conditionals
* @compile MostSpecific10.java
*/ */
class MostSpecific10 {
public class MostSpecific10 {
public static void main(String[] args) {
new MostSpecific10().test(true);
}
interface GetInt { interface GetInt {
int get(); int get();
@ -38,7 +42,9 @@ class MostSpecific10 {
} }
void m(GetInt getter) {} void m(GetInt getter) {}
void m(GetInteger getter) {} void m(GetInteger getter) {
throw new AssertionError("Less-specific method invocation: " + getter.getClass());
}
void test(boolean cond) { void test(boolean cond) {
m(() -> 23); m(() -> 23);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,14 +25,19 @@
* @test * @test
* @bug 8034223 * @bug 8034223
* @summary Return type Object is not more specific than return type String * @summary Return type Object is not more specific than return type String
* @compile MostSpecific11.java
*/ */
class MostSpecific11 { public class MostSpecific11 {
public static void main(String[] args) {
new MostSpecific11().test();
}
interface I { Object run(); } interface I { Object run(); }
interface J { String run(); } interface J { String run(); }
void m(I arg) {} void m(I arg) {
throw new RuntimeException("Less-specific method invocation.");
}
void m(J arg) {} void m(J arg) {}
void test() { void test() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,18 @@
* @test * @test
* @bug 8143852 * @bug 8143852
* @summary Rename functional interface method type parameters during most specific test * @summary Rename functional interface method type parameters during most specific test
* @compile MostSpecific15.java
*/ */
class MostSpecific15 { public class MostSpecific15 {
public static void main(String[] args) {
new MostSpecific15().test();
}
interface F1 { <X> Object apply(X arg); } interface F1 { <X> Object apply(X arg); }
interface F2 { <Y> String apply(Y arg); } interface F2 { <Y> String apply(Y arg); }
static void m1(F1 f) {} static void m1(F1 f) {
throw new AssertionError("Less-specific method invocation.");
}
static void m1(F2 f) {} static void m1(F2 f) {}
static String foo(Object in) { return "a"; } static String foo(Object in) { return "a"; }
@ -39,5 +44,4 @@ class MostSpecific15 {
void test() { void test() {
m1(MostSpecific15::foo); m1(MostSpecific15::foo);
} }
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,12 @@
* @test * @test
* @bug 8143852 * @bug 8143852
* @summary Rename functional interface method type parameters during most specific test * @summary Rename functional interface method type parameters during most specific test
* @compile MostSpecific17.java
*/ */
class MostSpecific17 { public class MostSpecific17 {
public static void main(String[] args) {
new MostSpecific17().test();
}
interface A<T> {} interface A<T> {}
interface B<T> extends A<T> {} interface B<T> extends A<T> {}
@ -35,7 +38,9 @@ class MostSpecific17 {
interface F1 { <X> A<? super X> apply(Object arg); } interface F1 { <X> A<? super X> apply(Object arg); }
interface F2 { <Y> B<? super Y> apply(Object arg); } interface F2 { <Y> B<? super Y> apply(Object arg); }
static void m1(F1 f) {} static void m1(F1 f) {
throw new AssertionError("Less-specific method invocation.");
}
static void m1(F2 f) {} static void m1(F2 f) {}
static B<Object> foo(Object in) { return null; } static B<Object> foo(Object in) { return null; }
@ -43,5 +48,4 @@ class MostSpecific17 {
void test() { void test() {
m1(MostSpecific17::foo); m1(MostSpecific17::foo);
} }
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,18 @@
* @test * @test
* @bug 8143852 * @bug 8143852
* @summary Test that generic function interface method bounds are the same * @summary Test that generic function interface method bounds are the same
* @compile MostSpecific18.java
*/ */
class MostSpecific18 { public class MostSpecific18 {
public static void main(String[] args) {
new MostSpecific18().test();
}
interface F1 { <X extends Number> Object apply(X arg); } interface F1 { <X extends Number> Object apply(X arg); }
interface F2 { <Y extends Number> String apply(Y arg); } interface F2 { <Y extends Number> String apply(Y arg); }
static void m1(F1 f) {} static void m1(F1 f) {
throw new AssertionError("Less-specific method invocation.");
}
static void m1(F2 f) {} static void m1(F2 f) {}
static String foo(Object in) { return "a"; } static String foo(Object in) { return "a"; }
@ -39,5 +44,4 @@ class MostSpecific18 {
void test() { void test() {
m1(MostSpecific18::foo); m1(MostSpecific18::foo);
} }
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,18 @@
* @test * @test
* @bug 8143852 * @bug 8143852
* @summary Test that generic function interface method bounds are the same * @summary Test that generic function interface method bounds are the same
* @compile MostSpecific20.java
*/ */
class MostSpecific20 { public class MostSpecific20 {
public static void main(String[] args) {
new MostSpecific20().test();
}
interface F1 { <X extends Iterable<X>> Object apply(X arg); } interface F1 { <X extends Iterable<X>> Object apply(X arg); }
interface F2 { <Y extends Iterable<Y>> String apply(Y arg); } interface F2 { <Y extends Iterable<Y>> String apply(Y arg); }
static void m1(F1 f) {} static void m1(F1 f) {
throw new AssertionError("Less-specific method invocation.");
}
static void m1(F2 f) {} static void m1(F2 f) {}
static String foo(Object in) { return "a"; } static String foo(Object in) { return "a"; }
@ -39,5 +44,4 @@ class MostSpecific20 {
void test() { void test() {
m1(MostSpecific20::foo); m1(MostSpecific20::foo);
} }
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,19 @@
* @test * @test
* @bug 8143852 * @bug 8143852
* @summary Most specific inference constraints derived from both functional interface method parameters and tparam bounds * @summary Most specific inference constraints derived from both functional interface method parameters and tparam bounds
* @compile MostSpecific22.java
*/ */
class MostSpecific22 {
public class MostSpecific22 {
public static void main(String[] args) {
new MostSpecific22().test();
}
interface F1<T> { <X extends T> Object apply(T arg); } interface F1<T> { <X extends T> Object apply(T arg); }
interface F2 { <Y extends Number> String apply(Number arg); } interface F2 { <Y extends Number> String apply(Number arg); }
static <T> T m1(F1<T> f) { return null; } static <T> T m1(F1<T> f) {
throw new AssertionError("Less-specific method invocation.");
}
static Object m1(F2 f) { return null; } static Object m1(F2 f) { return null; }
static String foo(Object in) { return "a"; } static String foo(Object in) { return "a"; }
@ -40,4 +46,4 @@ class MostSpecific22 {
m1(MostSpecific22::foo); m1(MostSpecific22::foo);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,18 @@
* @test * @test
* @bug 8143852 * @bug 8143852
* @summary Most specific inference constraints derived from intersection bound * @summary Most specific inference constraints derived from intersection bound
* @compile MostSpecific27.java
*/ */
class MostSpecific27 { public class MostSpecific27 {
public static void main(String[] args) {
new MostSpecific27().test();
}
interface F1<T> { <X extends Iterable<T> & Runnable> Object apply(T arg); } interface F1<T> { <X extends Iterable<T> & Runnable> Object apply(T arg); }
interface F2 { <Y extends Iterable<Number> & Runnable> String apply(Number arg); } interface F2 { <Y extends Iterable<Number> & Runnable> String apply(Number arg); }
static <T> T m1(F1<T> f) { return null; } static <T> T m1(F1<T> f) {
throw new AssertionError("Less-specific method invocation.");
}
static Object m1(F2 f) { return null; } static Object m1(F2 f) { return null; }
static String foo(Object in) { return "a"; } static String foo(Object in) { return "a"; }
@ -40,4 +45,4 @@ class MostSpecific27 {
m1(MostSpecific27::foo); m1(MostSpecific27::foo);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,15 +25,20 @@
* @test * @test
* @bug 8144767 * @bug 8144767
* @summary Correct most-specific test when wildcards appear in functional interface type * @summary Correct most-specific test when wildcards appear in functional interface type
* @compile MostSpecific29.java
*/ */
class MostSpecific29 { public class MostSpecific29 {
public static void main(String[] args) {
new MostSpecific29().test();
}
interface Pred<T> { boolean test(T arg); } interface Pred<T> { boolean test(T arg); }
interface Fun<T,R> { R apply(T arg); } interface Fun<T,R> { R apply(T arg); }
static void m1(Pred<? super Integer> f) {} static void m1(Pred<? super Integer> f) {}
static void m1(Fun<Integer, Boolean> f) {} static void m1(Fun<Integer, Boolean> f) {
throw new AssertionError("Less-specific method invocation.");
}
void test() { void test() {
m1((Integer n) -> true); m1((Integer n) -> true);