From 5062ce2804ce3ce45f4d911f4bb9887cc0fa334f Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 28 Jan 2016 17:08:15 +0300 Subject: [PATCH] Regression: correct smart cast from Type? to Type! --- .../calls/smartcasts/DelegatingDataFlowInfo.kt | 4 ++-- .../smartCasts/varnotnull/toFlexibleType.kt | 16 ++++++++++++++++ .../smartCasts/varnotnull/toFlexibleType.txt | 14 ++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt index 4307f9892f4..98e79a8b79f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt @@ -300,8 +300,8 @@ internal class DelegatingDataFlowInfo private constructor( val toDelete = newTypeInfo() for (value in typeInfo.keys()) { for (type in typeInfo[value]) { - // Remove original type and for not flexible type also all its supertypes (see also KT-10666) - if (if (value.type.isFlexible()) value.type == type else value.type.isSubtypeOf(type)) { + // Remove original type (see also KT-10666) + if (value.type == type) { toDelete.put(value, type) } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.kt new file mode 100644 index 00000000000..90c91e1a31b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.kt @@ -0,0 +1,16 @@ +// FILE: J.java + +class J { + static String foo() { return "abc"; } +} + +// FILE: test.kt + +fun bar() { + var v: String? + v = J.foo() + v.length + gav(v) +} + +fun gav(v: String) = v \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.txt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.txt new file mode 100644 index 00000000000..fa1c7984dea --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.txt @@ -0,0 +1,14 @@ +package + +public fun bar(): kotlin.Unit +public fun gav(/*0*/ v: kotlin.String): kotlin.String + +public/*package*/ open class J { + public/*package*/ constructor J() + 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/*package*/ open fun foo(): kotlin.String! +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index e43416095b1..6a2b6c3fe97 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -17435,6 +17435,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("toFlexibleType.kt") + public void testToFlexibleType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/toFlexibleType.kt"); + doTest(fileName); + } + @TestMetadata("unnecessary.kt") public void testUnnecessary() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessary.kt");