From 2979c370018564e598d67f3a3763c15ee59316ca Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Mon, 31 Aug 2020 19:27:45 +0300 Subject: [PATCH] [NI] Fix resolution status for UnstableSmartCastDiagnostic RESOLVED_WITH_ERROR was initially added for reproducing OI behavior. The intention was to preserve resolution into unstable smart cast and to keep failing candidate. However, this idea was abandoned after OI behavior proved inconsistent in cases involving generics. This commit restores RUNTIME_ERROR status of UnstableSmartCastDiagnostic. ^KT-41357 Fixed --- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 +++++ .../resolve/calls/tower/ImplicitScopeTower.kt | 2 +- .../testData/codegen/box/regressions/kt41357.kt | 16 ++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++++ .../codegen/LightAnalysisModeTestGenerated.java | 5 +++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++++ 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/regressions/kt41357.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index e5032e166eb..f961ea15ecb 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -28056,6 +28056,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/regressions/kt39088.kt"); } + @TestMetadata("kt41357.kt") + public void testKt41357() throws Exception { + runTest("compiler/testData/codegen/box/regressions/kt41357.kt"); + } + @TestMetadata("kt4142.kt") public void testKt4142() throws Exception { runTest("compiler/testData/codegen/box/regressions/kt4142.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index 638093ce48f..0594fbf3e50 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -120,7 +120,7 @@ object ErrorDescriptorDiagnostic : ResolutionDiagnostic(RESOLVED) // todo discus object LowPriorityDescriptorDiagnostic : ResolutionDiagnostic(RESOLVED_LOW_PRIORITY) object DynamicDescriptorDiagnostic : ResolutionDiagnostic(RESOLVED_LOW_PRIORITY) object ResolvedUsingNewFeatures : ResolutionDiagnostic(RESOLVED_NEED_PRESERVE_COMPATIBILITY) -object UnstableSmartCastDiagnostic : ResolutionDiagnostic(RESOLVED_WITH_ERROR) +object UnstableSmartCastDiagnostic : ResolutionDiagnostic(MAY_THROW_RUNTIME_ERROR) object HiddenExtensionRelatedToDynamicTypes : ResolutionDiagnostic(HIDDEN) object HiddenDescriptor : ResolutionDiagnostic(HIDDEN) diff --git a/compiler/testData/codegen/box/regressions/kt41357.kt b/compiler/testData/codegen/box/regressions/kt41357.kt new file mode 100644 index 00000000000..67066b8f974 --- /dev/null +++ b/compiler/testData/codegen/box/regressions/kt41357.kt @@ -0,0 +1,16 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +open class Foo(val id: Int) + +class CustomFoo : Foo(1) + +fun test(): Boolean { + val fooList = listOf(CustomFoo(), Foo(2)) + return fooList.first() is CustomFoo && fooList.last().id == 2 // ClassCastException +} + +fun box(): String { + check(test()) + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 763e9111b7b..fd7b8ebba57 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -29652,6 +29652,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/regressions/kt39088.kt"); } + @TestMetadata("kt41357.kt") + public void testKt41357() throws Exception { + runTest("compiler/testData/codegen/box/regressions/kt41357.kt"); + } + @TestMetadata("kt4142.kt") public void testKt4142() throws Exception { runTest("compiler/testData/codegen/box/regressions/kt4142.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8c87ec61ab6..f2493756a6f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -27286,6 +27286,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/regressions/kt39088.kt"); } + @TestMetadata("kt41357.kt") + public void testKt41357() throws Exception { + runTest("compiler/testData/codegen/box/regressions/kt41357.kt"); + } + @TestMetadata("kt4142.kt") public void testKt4142() throws Exception { runTest("compiler/testData/codegen/box/regressions/kt4142.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c5f573f8f3f..4bf973852b8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -28056,6 +28056,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/regressions/kt39088.kt"); } + @TestMetadata("kt41357.kt") + public void testKt41357() throws Exception { + runTest("compiler/testData/codegen/box/regressions/kt41357.kt"); + } + @TestMetadata("kt4142.kt") public void testKt4142() throws Exception { runTest("compiler/testData/codegen/box/regressions/kt4142.kt");