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 90e4cb2f811..d12a952a6b9 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 @@ -12395,6 +12395,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt"); } + @Test + @TestMetadata("kt46515.kt") + public void testKt46515() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt46515.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() 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 69506977f3d..d4d98d8ab9a 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 @@ -12395,6 +12395,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt"); } + @Test + @TestMetadata("kt46515.kt") + public void testKt46515() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt46515.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt index c9829eafbc3..ab35ec2b6bd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt @@ -185,9 +185,12 @@ class FirTowerDataContextsForClassParts( modeMap[mode] = value } - fun setAnonymousFunctionContext(symbol: FirAnonymousFunctionSymbol) { - mode = SPECIAL - modeMap[SPECIAL] = towerDataContextForAnonymousFunctions.getValue(symbol) + fun setAnonymousFunctionContextIfAny(symbol: FirAnonymousFunctionSymbol) { + val context = towerDataContextForAnonymousFunctions[symbol] + if (context != null) { + mode = SPECIAL + modeMap[SPECIAL] = context + } } fun setCallableReferenceContextIfAny(access: FirCallableReferenceAccess) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt index 67a66f973ce..4db0ea288ea 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt @@ -296,7 +296,7 @@ class BodyResolveContext( @OptIn(PrivateForInline::class) inline fun withAnonymousFunctionTowerDataContext(symbol: FirAnonymousFunctionSymbol, f: () -> T): T { return withTowerModeCleanup { - towerDataContextsForClassParts.setAnonymousFunctionContext(symbol) + towerDataContextsForClassParts.setAnonymousFunctionContextIfAny(symbol) f() } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index fbc09746d58..453e3783039 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -261,8 +261,8 @@ class ResolvedAtomCompleter( } } - val substitutedValueParameterTypes = descriptor.valueParameters.mapIndexed { i, valueParameter -> - valueParameterTypes[i].substituteAndApproximate(substitutor).also { + val substitutedValueParameterTypes = descriptor.valueParameters.mapIndexedNotNull { i, valueParameter -> + valueParameterTypes.getOrNull(i)?.substituteAndApproximate(substitutor)?.also { if (valueParameter is ValueParameterDescriptorImpl && valueParameter.type.shouldBeUpdated()) { valueParameter.setOutType(it.approximatedType) } diff --git a/compiler/testData/diagnostics/tests/inference/kt46515.kt b/compiler/testData/diagnostics/tests/inference/kt46515.kt new file mode 100644 index 00000000000..813350195d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt46515.kt @@ -0,0 +1,6 @@ +// FIR_IDENTICAL +// WITH_RUNTIME + +fun bar() { + listOf(1, 2, 3).maxOf { foo } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt46515.txt b/compiler/testData/diagnostics/tests/inference/kt46515.txt new file mode 100644 index 00000000000..19a5b8840b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt46515.txt @@ -0,0 +1,3 @@ +package + +public fun bar(): kotlin.Unit 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 2e55dc0e168..b40ad5d601d 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 @@ -12401,6 +12401,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt"); } + @Test + @TestMetadata("kt46515.kt") + public void testKt46515() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt46515.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 5933dbbda32..67dcb1679ca 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -10791,6 +10791,11 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt"); } + @TestMetadata("kt46515.kt") + public void testKt46515() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt46515.kt"); + } + @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");