[FE 1.0] Substituted possible fixed type variables after completion in accordance with @OverloadResolutionByLambdaReturnType

^KT-48031 Fixed
This commit is contained in:
Victor Petukhov
2022-07-02 12:07:46 +02:00
committed by teamcity
parent 5b5da025f4
commit 3ed87c29c7
9 changed files with 69 additions and 5 deletions
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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? =
@@ -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(
@@ -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<ResolvedAtom>
abstract fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom)
@@ -0,0 +1,15 @@
// FIR_IDENTICAL
// WITH_STDLIB
class Flow<out T>
@OverloadResolutionByLambdaReturnType
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T> = this
@JvmName("debounceDuration")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
fun <T> Flow<T>.debounce(timeout: (T) -> String): Flow<T> = this
fun invalidFlow(x: Flow<Int>): Flow<Int> = x.debounce { value -> 0 }
@@ -0,0 +1,12 @@
package
public fun invalidFlow(/*0*/ x: Flow<kotlin.Int>): Flow<kotlin.Int>
@kotlin.OverloadResolutionByLambdaReturnType @kotlin.OptIn(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ T> Flow<T>.debounce(/*0*/ timeoutMillis: (T) -> kotlin.Long): Flow<T>
@kotlin.jvm.JvmName(name = "debounceDuration") @kotlin.OptIn(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) @kotlin.OverloadResolutionByLambdaReturnType public fun </*0*/ T> Flow<T>.debounce(/*0*/ timeout: (T) -> kotlin.String): Flow<T>
public final class Flow</*0*/ out T> {
public constructor Flow</*0*/ out T>()
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
}
@@ -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 {