From f00af72e0fb61e6da5fb452c3a27fa67d308b5dd Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 21 Oct 2015 17:38:33 +0300 Subject: [PATCH] Fixed 'OnlyInputTypes' working with platform types --- ...lyInputTypesAnnotationWithPlatformTypes.kt | 19 +++++++++++++++++++ ...yInputTypesAnnotationWithPlatformTypes.txt | 14 ++++++++++++++ ...JetDiagnosticsTestWithStdLibGenerated.java | 6 ++++++ .../resolve/calls/inference/TypeBoundsImpl.kt | 3 ++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt new file mode 100644 index 00000000000..154c475e0c7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt @@ -0,0 +1,19 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER + +//FILE:Foo.java + +public class Foo { + public static String foo() { + return null; + } +} + +//FILE:Bar.kt + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun <@kotlin.internal.OnlyInputTypes T> assertEquals1(t1: T, t2: T) {} + +fun test() { + assertEquals1(null, Foo.foo()) + assertEquals1("", Foo.foo()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.txt new file mode 100644 index 00000000000..f6a9c1b9bdb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.txt @@ -0,0 +1,14 @@ +package + +@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun assertEquals1(/*0*/ t1: T, /*1*/ t2: T): kotlin.Unit +public fun test(): kotlin.Unit + +public open class Foo { + public constructor Foo() + 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 + + // Static members + public open fun foo(): kotlin.String! +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java index 0cdb26ff94a..c19bc50f6eb 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java @@ -708,6 +708,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic doTest(fileName); } + @TestMetadata("onlyInputTypesAnnotationWithPlatformTypes.kt") + public void testOnlyInputTypesAnnotationWithPlatformTypes() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt"); + doTest(fileName); + } + @TestMetadata("resolveWithOnlyInputTypesAnnotation.kt") public void testResolveWithOnlyInputTypesAnnotation() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt index 6aa9c481b87..e9c86a6ee85 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt @@ -147,7 +147,8 @@ public class TypeBoundsImpl( // Only type mentioned in bounds might be the result val typesInBoundsSet = bounds.filter { it.isProper && it.constrainingType.constructor.isDenotable }.map { it.constrainingType }.toSet() - if (typesInBoundsSet.contains(possibleAnswer)) return true + // Flexible types are equal to inflexible + if (typesInBoundsSet.any { KotlinTypeChecker.DEFAULT.equalTypes(it, possibleAnswer) }) return true // For non-denotable number types only, no valid types are mentioned, so common supertype is valid val numberLowerBounds = filterBounds(bounds, LOWER_BOUND).filter { it.constructor is IntegerValueTypeConstructor }