From c1904004c4447685b322eeaf86faf02fcbc8f752 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Fri, 27 May 2022 16:07:38 +0300 Subject: [PATCH] FIR: Fix case when smartcast receiver is used for call to private method ^KT-54432 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 12 +++ ...irOldFrontendDiagnosticsTestGenerated.java | 12 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 +++ .../FirBlackBoxCodegenTestGenerated.java | 12 +++ .../kotlin/fir/resolve/calls/Candidate.kt | 2 +- .../fir/resolve/calls/VisibilityUtils.kt | 77 ++++++++++++++----- .../fir/resolve/calls/tower/TowerLevels.kt | 6 +- .../avoidSmartCastToDerivedForPrivate.kt | 16 ++++ .../codegen/box/smartCasts/kt52432.kt | 21 +++++ ...ivateThroughSubClassDoubleSmartCast.fir.kt | 25 ++++++ ...lePrivateThroughSubClassDoubleSmartCast.kt | 25 ++++++ ...nvisiblePrivateThroughSubClassSmartCast.kt | 15 ++++ .../test/runners/DiagnosticTestGenerated.java | 18 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 12 +++ .../IrBlackBoxCodegenTestGenerated.java | 12 +++ .../LightAnalysisModeTestGenerated.java | 10 +++ .../js/test/JsCodegenBoxTestGenerated.java | 12 +++ .../test/ir/IrJsCodegenBoxTestGenerated.java | 12 +++ .../IrCodegenBoxWasmTestGenerated.java | 10 +++ .../NativeCodegenBoxTestGenerated.java | 12 +++ 20 files changed, 306 insertions(+), 27 deletions(-) create mode 100644 compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt create mode 100644 compiler/testData/codegen/box/smartCasts/kt52432.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.fir.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 8fe122e1837..6e8cee95249 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -33508,6 +33508,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClass.kt"); } + @Test + @TestMetadata("invisiblePrivateThroughSubClassDoubleSmartCast.kt") + public void testInvisiblePrivateThroughSubClassDoubleSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt"); + } + + @Test + @TestMetadata("invisiblePrivateThroughSubClassSmartCast.kt") + public void testInvisiblePrivateThroughSubClassSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt"); + } + @Test @TestMetadata("invisibleSetterOfJavaClass.kt") public void testInvisibleSetterOfJavaClass() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index fc98b201c50..c7c5b97fc22 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -33508,6 +33508,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClass.kt"); } + @Test + @TestMetadata("invisiblePrivateThroughSubClassDoubleSmartCast.kt") + public void testInvisiblePrivateThroughSubClassDoubleSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt"); + } + + @Test + @TestMetadata("invisiblePrivateThroughSubClassSmartCast.kt") + public void testInvisiblePrivateThroughSubClassSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt"); + } + @Test @TestMetadata("invisibleSetterOfJavaClass.kt") public void testInvisibleSetterOfJavaClass() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 6a9ef8f6b59..9c11edc71fd 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -33508,6 +33508,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClass.kt"); } + @Test + @TestMetadata("invisiblePrivateThroughSubClassDoubleSmartCast.kt") + public void testInvisiblePrivateThroughSubClassDoubleSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt"); + } + + @Test + @TestMetadata("invisiblePrivateThroughSubClassSmartCast.kt") + public void testInvisiblePrivateThroughSubClassSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt"); + } + @Test @TestMetadata("invisibleSetterOfJavaClass.kt") public void testInvisibleSetterOfJavaClass() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 73ba0cc647f..44e20a83b21 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -45671,6 +45671,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @Test @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { @@ -45791,6 +45797,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/smartCasts/kt48163_smartCastToThrowable.kt"); } + @Test + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @Test @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt index 00b44e1b426..c36efd71a1f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.isSuccess class Candidate( override val symbol: FirBasedSymbol<*>, - override val dispatchReceiverValue: ReceiverValue?, + override var dispatchReceiverValue: ReceiverValue?, // In most cases, it contains zero or single element // More than one, only in case of context receiver group val givenExtensionReceiverOptions: List, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt index d89f05ca014..8bfa1a60322 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt @@ -6,17 +6,20 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.descriptors.Visibilities -import org.jetbrains.kotlin.fir.FirVisibilityChecker +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.FirBackingField import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.declarations.utils.getExplicitBackingField import org.jetbrains.kotlin.fir.declarations.utils.visibility +import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment -import org.jetbrains.kotlin.fir.isIntersectionOverride -import org.jetbrains.kotlin.fir.isSubstitutionOverride -import org.jetbrains.kotlin.fir.originalIfFakeOverride +import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionWithSmartcast +import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.isNullableNothing +import org.jetbrains.kotlin.fir.types.makeConeTypeDefinitelyNotNullOrNotNull +import org.jetbrains.kotlin.fir.types.typeContext fun FirVisibilityChecker.isVisible( declaration: FirMemberDeclaration, @@ -55,27 +58,59 @@ fun FirVisibilityChecker.isVisible( ): Boolean { val callInfo = candidate.callInfo - val visible = isVisible( - declaration, - callInfo, - candidate.dispatchReceiverValue - ) + if (!isVisible(declaration, callInfo, candidate.dispatchReceiverValue)) { + val dispatchReceiverWithoutSmartCastType = + removeSmartCastTypeForAttemptToFitVisibility(candidate.dispatchReceiverValue, candidate.callInfo.session) ?: return false - if (visible) { - val backingField = declaration.getBackingFieldIfApplicable() - if (backingField != null) { - candidate.hasVisibleBackingField = isVisible( - backingField, - callInfo.session, - callInfo.containingFile, - callInfo.containingDeclarations, - candidate.dispatchReceiverValue, - candidate.callInfo.callSite is FirVariableAssignment, - ) + if (!isVisible(declaration, callInfo, dispatchReceiverWithoutSmartCastType)) return false + + candidate.dispatchReceiverValue = dispatchReceiverWithoutSmartCastType + } + + val backingField = declaration.getBackingFieldIfApplicable() + if (backingField != null) { + candidate.hasVisibleBackingField = isVisible( + backingField, + callInfo.session, + callInfo.containingFile, + callInfo.containingDeclarations, + candidate.dispatchReceiverValue, + candidate.callInfo.callSite is FirVariableAssignment, + ) + } + + return true +} + +private fun removeSmartCastTypeForAttemptToFitVisibility(dispatchReceiverValue: ReceiverValue?, session: FirSession): ReceiverValue? { + val expressionWithSmartcastIfStable = + (dispatchReceiverValue?.receiverExpression as? FirExpressionWithSmartcast)?.takeIf { it.isStable } ?: return null + + if (dispatchReceiverValue.type.isNullableNothing) return null + + val originalTypeNotNullable = + expressionWithSmartcastIfStable.originalType.coneType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext) + + // Basically, this `if` is just for sake of optimizaton + // We have only nullability enhancement, here, so return initial smart cast receiver value + if (originalTypeNotNullable == dispatchReceiverValue.type) return null + + val expressionForReceiver = with(session.typeContext) { + when { + expressionWithSmartcastIfStable.originalType.coneType.isNullableType() && !dispatchReceiverValue.type.isNullableType() -> + buildExpressionWithSmartcast { + originalExpression = expressionWithSmartcastIfStable.originalExpression + smartcastType = + expressionWithSmartcastIfStable.originalExpression.typeRef.resolvedTypeFromPrototype(originalTypeNotNullable) + typesFromSmartCast = listOf(originalTypeNotNullable) + smartcastStability = expressionWithSmartcastIfStable.smartcastStability + } + else -> expressionWithSmartcastIfStable.originalExpression } } - return visible + return ExpressionReceiverValue(expressionForReceiver) + } private fun FirMemberDeclaration.getBackingFieldIfApplicable(): FirBackingField? { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt index 9fe66239994..3ab507ea2a2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt @@ -138,11 +138,7 @@ class MemberScopeTowerLevel( } val visibleCandidatesFromSmartcast = visibleCandidates.filter { candidatesMapping.getValue(it) } - if (visibleCandidatesFromSmartcast.isNotEmpty()) { - candidates += visibleCandidatesFromSmartcast - } else { - group.filterNotTo(candidates) { candidatesMapping.getValue(it) } - } + candidates += visibleCandidatesFromSmartcast.ifEmpty { group } } consumeCandidates(output, candidates) } diff --git a/compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt b/compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt new file mode 100644 index 00000000000..0b692697ffe --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt @@ -0,0 +1,16 @@ +open class Base { + fun foo(): String { + return when (this) { + is Derived -> baz() + else -> "fail 1" + } + } + + private fun baz(): String = "OK" +} + +class Derived : Base() + +fun box(): String { + return Derived().foo() +} diff --git a/compiler/testData/codegen/box/smartCasts/kt52432.kt b/compiler/testData/codegen/box/smartCasts/kt52432.kt new file mode 100644 index 00000000000..8d060591666 --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/kt52432.kt @@ -0,0 +1,21 @@ +abstract class Base { + fun foo(): String { + return when (this) { + is Derived -> baz() + else -> "fail 1" + } + } + + abstract fun bar(): String + + private fun Derived.baz(): String = bar() + k +} + +class Derived : Base() { + override fun bar(): String = "O" + val k: String get() = "K" +} + +fun box(): String { + return Derived().foo() +} diff --git a/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.fir.kt b/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.fir.kt new file mode 100644 index 00000000000..a2032cc3c76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.fir.kt @@ -0,0 +1,25 @@ +// SKIP_TXT +// ISSUE: KT-52543 + +abstract class A { + fun foo(a: Any) { + if (a is A) { + a.prv() + if (a is B) { + a.prv() + } + } + + if (a is B) { + a.prv() + if (a is A) { + a.prv() + } + } + } + + private fun prv() {} +} + + +open class B : A() diff --git a/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt b/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt new file mode 100644 index 00000000000..3a77c275587 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt @@ -0,0 +1,25 @@ +// SKIP_TXT +// ISSUE: KT-52543 + +abstract class A { + fun foo(a: Any) { + if (a is A) { + a.prv() + if (a is B) { + a.prv() + } + } + + if (a is B) { + a.prv() + if (a is A) { + a.prv() + } + } + } + + private fun prv() {} +} + + +open class B : A() diff --git a/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt b/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt new file mode 100644 index 00000000000..e0610b949f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +// SKIP_TXT + +abstract class A { + fun foo(a: A) { + a.prv() + if (a is B) { + a.prv() + } + } + + private fun prv() {} +} + +abstract class B : A() diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 4752f899a6e..75a1c79589b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -33592,6 +33592,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/visibility/innerNestedAndAnonymousClasses.kt"); } + @Test + @TestMetadata("invisiblePrivateThroughSubClass.kt") + public void testInvisiblePrivateThroughSubClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClass.kt"); + } + + @Test + @TestMetadata("invisiblePrivateThroughSubClassDoubleSmartCast.kt") + public void testInvisiblePrivateThroughSubClassDoubleSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassDoubleSmartCast.kt"); + } + + @Test + @TestMetadata("invisiblePrivateThroughSubClassSmartCast.kt") + public void testInvisiblePrivateThroughSubClassSmartCast() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/invisiblePrivateThroughSubClassSmartCast.kt"); + } + @Test @TestMetadata("invisibleSetterOfJavaClass.kt") public void testInvisibleSetterOfJavaClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index c1da4264fc8..ab79abd4418 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -45095,6 +45095,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @Test @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { @@ -45215,6 +45221,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/smartCasts/kt48163_smartCastToThrowable.kt"); } + @Test + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @Test @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 6330ad83b86..a4123707100 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -45671,6 +45671,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @Test @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { @@ -45791,6 +45797,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/smartCasts/kt48163_smartCastToThrowable.kt"); } + @Test + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @Test @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 33b764a9150..0c914fa9957 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -36494,6 +36494,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { runTest("compiler/testData/codegen/box/smartCasts/complexExplicitReceiver.kt"); @@ -36594,6 +36599,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/smartCasts/kt48163_smartCastToThrowable.kt"); } + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { runTest("compiler/testData/codegen/box/smartCasts/lambdaArgumentWithoutType.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index db95253bd20..bbc75a6d9bf 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -32791,6 +32791,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @Test + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @Test @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { @@ -32893,6 +32899,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt"); } + @Test + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @Test @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 38d538180ef..70ee720ecfa 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -32893,6 +32893,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @Test @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { @@ -32995,6 +33001,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt"); } + @Test + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @Test @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 1c29bc43f4b..d78664c5117 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -29453,6 +29453,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { runTest("compiler/testData/codegen/box/smartCasts/complexExplicitReceiver.kt"); @@ -29538,6 +29543,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt"); } + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception { runTest("compiler/testData/codegen/box/smartCasts/lambdaArgumentWithoutType.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 3db4fd6e32e..56c1980b76b 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -35902,6 +35902,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/smartCasts"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } + @Test + @TestMetadata("avoidSmartCastToDerivedForPrivate.kt") + public void testAvoidSmartCastToDerivedForPrivate() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/avoidSmartCastToDerivedForPrivate.kt"); + } + @Test @TestMetadata("complexExplicitReceiver.kt") public void testComplexExplicitReceiver() throws Exception { @@ -36004,6 +36010,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt"); } + @Test + @TestMetadata("kt52432.kt") + public void testKt52432() throws Exception { + runTest("compiler/testData/codegen/box/smartCasts/kt52432.kt"); + } + @Test @TestMetadata("lambdaArgumentWithoutType.kt") public void testLambdaArgumentWithoutType() throws Exception {