From 1df318ff28aabf9f955106129203dfa6f51cdff3 Mon Sep 17 00:00:00 2001 From: Nikita Nazarov Date: Fri, 1 Dec 2023 11:38:55 +0100 Subject: [PATCH] [FIR] Remove the redundant isFunctionType check ^KT-63865 fixed --- ...agnosticCompilerTestFirTestdataTestGenerated.java | 6 ++++++ ...edDiagnosticCompilerFirTestDataTestGenerated.java | 6 ++++++ .../castForFunctionsWithDifferentArities.fir.txt | 12 ++++++++++++ .../castForFunctionsWithDifferentArities.kt | 9 +++++++++ .../FirLightTreeDiagnosticsTestGenerated.java | 6 ++++++ .../test/runners/FirPsiDiagnosticTestGenerated.java | 6 ++++++ .../kotlin/fir/types/ConeInferenceContext.kt | 2 +- 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java index 427adda503c..ac14d865311 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java @@ -5266,6 +5266,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/backingField.kt"); } + @Test + @TestMetadata("castForFunctionsWithDifferentArities.kt") + public void testCastForFunctionsWithDifferentArities() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java index 77c2701006c..9f298d8c952 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java @@ -5266,6 +5266,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/backingField.kt"); } + @Test + @TestMetadata("castForFunctionsWithDifferentArities.kt") + public void testCastForFunctionsWithDifferentArities() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.fir.txt new file mode 100644 index 00000000000..24c451c7714 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.fir.txt @@ -0,0 +1,12 @@ +FILE: castForFunctionsWithDifferentArities.kt + public final fun test(b: R|kotlin/Boolean|, block1: R|kotlin/Any.() -> kotlin/Unit|, block2: R|(kotlin/Any.(kotlin/Any?) -> kotlin/Unit)?|): R|kotlin/Unit| { + when () { + R|/b| -> { + R|kotlin/requireNotNull| kotlin/Unit|>(R|/block1|) + } + else -> { + R|kotlin/requireNotNull| kotlin/Unit|>(R|/block2|) + } + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt new file mode 100644 index 00000000000..84a3dde466d --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt @@ -0,0 +1,9 @@ +// ISSUE: KT-63865 + +fun test(b: Boolean, block1: Any.() -> Unit, block2: (Any.(Any?) -> Unit)?) { + if (b) { + requireNotNull(block1) + } else { + requireNotNull(block2) + } +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java index b10497fbfec..f9d504eed58 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java @@ -5266,6 +5266,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/backingField.kt"); } + @Test + @TestMetadata("castForFunctionsWithDifferentArities.kt") + public void testCastForFunctionsWithDifferentArities() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java index d711a5b3ffc..0011a752fb0 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java @@ -5266,6 +5266,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/backingField.kt"); } + @Test + @TestMetadata("castForFunctionsWithDifferentArities.kt") + public void testCastForFunctionsWithDifferentArities() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/castForFunctionsWithDifferentArities.kt"); + } + @Test @TestMetadata("classLiteralForParameter.kt") public void testClassLiteralForParameter() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 585f8b561c6..00b8744f6c3 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -69,7 +69,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo ): SimpleTypeMarker { val attributesList = attributes?.filterIsInstanceTo, MutableList>>(mutableListOf()) val coneAttributes: ConeAttributes = if (isExtensionFunction) { - require(constructor is ConeClassLikeLookupTag && constructor.isSomeFunctionType(session)) + require(constructor is ConeClassLikeLookupTag) // We don't want to create new instance of ConeAttributes which // contains only CompilerConeAttributes.ExtensionFunctionType // to avoid memory consumption