KT-11733 Cannot infer type parameter in SAM with nullability annotations

#KT-11733 Fixed
This commit is contained in:
Stanislav Erokhin
2016-04-01 20:55:59 +03:00
parent c6fe1b715d
commit 832f468b13
6 changed files with 68 additions and 1 deletions
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.validation.InfixValidator
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.util.OperatorNameConventions
enum class ResolveArgumentsMode {
@@ -47,7 +48,7 @@ enum class ResolveArgumentsMode {
fun hasUnknownFunctionParameter(type: KotlinType): Boolean {
assert(ReflectionTypes.isCallableType(type)) { "type $type is not a function or property" }
return getParameterArgumentsOfCallableType(type).any {
TypeUtils.contains(it.type, DONT_CARE) || ErrorUtils.containsUninferredParameter(it.type)
it.type.contains { TypeUtils.isDontCarePlaceholder(it) } || ErrorUtils.containsUninferredParameter(it.type)
}
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
interface Predicate<T>
fun <T> Predicate(<!UNUSED_PARAMETER!>x<!>: (T?) -> Boolean): Predicate<T> = null!!
fun foo() {
process(Predicate {
x -> x checkType { _<String?>() }
true
})
}
fun process(<!UNUSED_PARAMETER!>x<!>: Predicate<String>) {}
@@ -0,0 +1,11 @@
package
public fun </*0*/ T> Predicate(/*0*/ x: (T?) -> kotlin.Boolean): Predicate<T>
public fun foo(): kotlin.Unit
public fun process(/*0*/ x: Predicate<kotlin.String>): kotlin.Unit
public interface Predicate</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,16 @@
// !CHECK_TYPE
// FILE: Predicate.java
import org.jetbrains.annotations.NotNull
public interface Predicate<T extends CharSequence> {
// Same effect with @Nullable here
boolean invoke(@NotNull T t);
}
// FILE: Main.kt
fun process(<!UNUSED_PARAMETER!>x<!>: Predicate<String>) {}
fun main(args: Array<String>) {
process(Predicate { x -> x checkType { _<String>() }
true
})
}
@@ -0,0 +1,12 @@
package
public /*synthesized*/ fun </*0*/ T : kotlin.CharSequence!> Predicate(/*0*/ function: (T) -> kotlin.Boolean): Predicate<T>
public fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
public fun process(/*0*/ x: Predicate<kotlin.String>): kotlin.Unit
public interface Predicate</*0*/ T : kotlin.CharSequence!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract operator fun invoke(/*0*/ @org.jetbrains.annotations.NotNull() t: T): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -6735,6 +6735,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt11733.kt")
public void testKt11733() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt11733.kt");
doTest(fileName);
}
@TestMetadata("kt11733_1.kt")
public void testKt11733_1() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.kt");
doTest(fileName);
}
@TestMetadata("kt2906.kt")
public void testKt2906() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");