Github user daniel-huss commented on a diff in the pull request: https://github.com/apache/groovy/pull/643#discussion_r157355618 --- 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 -- I'm confused :) This works because `foo` happens to always pass a String to `p::test`, but what if it passed `new Object()` instead? If testPredicate were `@CompileStatic` I would expect a compile error here. Is this disparity intentional?
---