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 b3e68f01d65..fb2646cdd0f 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 @@ -13670,6 +13670,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/discardInapplicableCandidateWithNotSatisfyingSelfType.kt"); } + @Test + @TestMetadata("dontThrowEmptyIntersectionException.kt") + public void testDontThrowEmptyIntersectionException() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt"); + } + @Test @TestMetadata("equalitySubstitutionInsideNonInvariantType.kt") public void testEqualitySubstitutionInsideNonInvariantType() throws Exception { @@ -14327,6 +14333,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); } + @Test + @TestMetadata("kt48031.kt") + public void testKt48031() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() 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 af8283a2190..c2a623de926 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 @@ -14333,6 +14333,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); } + @Test + @TestMetadata("kt48031.kt") + public void testKt48031() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() 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 560120ff045..cefaed3433d 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 @@ -14333,6 +14333,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); } + @Test + @TestMetadata("kt48031.kt") + public void testKt48031() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 0a565914b3c..b7614d9468e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -53,6 +53,7 @@ import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.SmartcastStability +import org.jetbrains.kotlin.types.model.safeSubstitute import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs import kotlin.contracts.ExperimentalContracts @@ -488,7 +489,9 @@ fun BodyResolveComponents.initialTypeOfCandidate(candidate: Candidate): ConeKotl } private fun initialTypeOfCandidate(candidate: Candidate, typeRef: FirResolvedTypeRef): ConeKotlinType { - return candidate.substitutor.substituteOrSelf(typeRef.type) + val system = candidate.system + val resultingSubstitutor = system.buildCurrentSubstitutor() + return resultingSubstitutor.safeSubstitute(system, candidate.substitutor.substituteOrSelf(typeRef.type)) as ConeKotlinType } fun FirCallableDeclaration.getContainingClass(session: FirSession): FirRegularClass? = diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 139e7d82a74..45740d7a621 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -15,9 +15,7 @@ import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReference import org.jetbrains.kotlin.resolve.calls.components.candidate.SimpleResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.addEqualityConstraintIfCompatible -import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter -import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode -import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle +import org.jetbrains.kotlin.resolve.calls.inference.components.* import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage.Empty.hasContradiction import org.jetbrains.kotlin.resolve.calls.inference.model.ExpectedTypeConstraintPositionImpl import org.jetbrains.kotlin.resolve.calls.model.* @@ -304,7 +302,10 @@ class KotlinCallCompleter( private fun ResolutionCandidate.substitutedReturnType(): UnwrappedType? { val returnType = resolvedCall.candidateDescriptor.returnType?.unwrap() ?: return null - return resolvedCall.freshVariablesSubstitutor.safeSubstitute(returnType) + val substitutedReturnTypeWithVariables = resolvedCall.freshVariablesSubstitutor.safeSubstitute(returnType) + return (getResultingSubstitutor() as? NewTypeSubstitutorByConstructorMap) + ?.safeSubstitute(substitutedReturnTypeWithVariables) + ?: substitutedReturnTypeWithVariables } private fun ResolutionCandidate.addExpectedTypeConstraint( diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt index 6c3c1bb7f17..63d9b32b075 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImp import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.* import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker import java.util.ArrayList sealed class ResolutionCandidate : Candidate, KotlinDiagnosticsHolder { @@ -55,6 +56,8 @@ sealed class ResolutionCandidate : Candidate, KotlinDiagnosticsHolder { private var newSystem: NewConstraintSystemImpl? = null private var currentApplicability: CandidateApplicability = CandidateApplicability.RESOLVED + fun getResultingSubstitutor(): TypeSubstitutorMarker? = newSystem?.buildCurrentSubstitutor() + abstract fun getSubResolvedAtoms(): List abstract fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt new file mode 100644 index 00000000000..40f5106b2af --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +// WITH_STDLIB + +class Flow + +@OverloadResolutionByLambdaReturnType +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +fun Flow.debounce(timeoutMillis: (T) -> Long): Flow = this + +@JvmName("debounceDuration") +@OptIn(kotlin.experimental.ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +fun Flow.debounce(timeout: (T) -> String): Flow = this + +fun invalidFlow(x: Flow): Flow = x.debounce { value -> 0 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt48031.txt b/compiler/testData/diagnostics/tests/inference/builderInference/kt48031.txt new file mode 100644 index 00000000000..3ffc76144c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt48031.txt @@ -0,0 +1,12 @@ +package + +public fun invalidFlow(/*0*/ x: Flow): Flow +@kotlin.OverloadResolutionByLambdaReturnType @kotlin.OptIn(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun Flow.debounce(/*0*/ timeoutMillis: (T) -> kotlin.Long): Flow +@kotlin.jvm.JvmName(name = "debounceDuration") @kotlin.OptIn(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) @kotlin.OverloadResolutionByLambdaReturnType public fun Flow.debounce(/*0*/ timeout: (T) -> kotlin.String): Flow + +public final class Flow { + public constructor Flow() + 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 +} 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 6b5bdda878d..81add57ff9e 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 @@ -14339,6 +14339,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); } + @Test + @TestMetadata("kt48031.kt") + public void testKt48031() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt48031.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() throws Exception {