You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by daniel-huss <gi...@git.apache.org> on 2018/02/14 18:47:24 UTC
[GitHub] groovy pull request #643: GROOVY-8241 SAM parameter type inference for expli...
Github user daniel-huss commented on a diff in the pull request:
https://github.com/apache/groovy/pull/643#discussion_r168272512
--- Diff: src/test/groovy/transform/stc/MethodCallsSTCTest.groovy ---
@@ -383,6 +406,94 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
''', 'Reference to method is ambiguous'
}
+ void testShouldFailWithMultiplePossibleMethods2() {
+ shouldFailWithMessages '''
+ static String foo(String s) {
+ 'String'
+ }
+ static String foo(Integer s) {
+ 'Integer'
+ }
+ static String foo(Boolean s) {
+ 'Boolean'
+ }
+ ['foo',123,true].each { argument ->
+ if (argument instanceof String || argument instanceof Boolean || argument instanceof Integer) {
+ foo(argument)
+ }
+ }
+ ''', 'Reference to method is ambiguous'
+ }
+
+ void testInstanceOfOnExplicitParameter() {
+ assertScript '''
+ 1.with { obj ->
+ if (obj instanceof String) {
+ obj.toUpperCase()
+ }
+ }
+ '''
+ }
+
+ void testSAMWithExplicitParameter() {
+ assertScript '''
+ public interface SAM {
+ boolean run(String var1, Thread th);
+ }
+
+ static boolean foo(SAM sam) {
+ sam.run("foo", new Thread())
+ }
+
+ static def callSAM() {
+ foo { str, th ->
+ str.toUpperCase().equals(th.getName())
+ }
+ }
+ '''
+ }
+
+ void testGroovy8241() {
+ assertScript '''
+ import java.util.function.Predicate
+
+ static boolean foo(Predicate<? super String> p) {
+ p.test("foo")
+ }
+
+ static def testPredicate() {
+ foo { it ->
+ it.toUpperCase()
--- End diff --
Oh, you're right. I forgot Groovy's interpretation of <? super X> is simply <X> :)
---