Use initial system for completion if common one is effectively empty
Otherwise we can get unsubstituted type variables as expected types and then write wrong information for assertions #KT-41470 Fixed
This commit is contained in:
Generated
+5
@@ -12652,6 +12652,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
+14
-8
@@ -174,8 +174,13 @@ class CoroutineInferenceSession(
|
|||||||
diagnosticsHolder: KotlinDiagnosticsHolder,
|
diagnosticsHolder: KotlinDiagnosticsHolder,
|
||||||
): Map<TypeConstructor, UnwrappedType>? {
|
): Map<TypeConstructor, UnwrappedType>? {
|
||||||
val (commonSystem, effectivelyEmptyConstraintSystem) = buildCommonSystem(initialStorage)
|
val (commonSystem, effectivelyEmptyConstraintSystem) = buildCommonSystem(initialStorage)
|
||||||
|
val initialStorageSubstitutor = initialStorage.buildResultingSubstitutor(commonSystem, transformTypeVariablesToErrorTypes = false)
|
||||||
if (effectivelyEmptyConstraintSystem) {
|
if (effectivelyEmptyConstraintSystem) {
|
||||||
updateCalls(lambda, commonSystem)
|
updateCalls(
|
||||||
|
lambda,
|
||||||
|
initialStorageSubstitutor,
|
||||||
|
commonSystem.errors
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +193,9 @@ class CoroutineInferenceSession(
|
|||||||
diagnosticsHolder
|
diagnosticsHolder
|
||||||
)
|
)
|
||||||
|
|
||||||
updateCalls(lambda, commonSystem)
|
val resultingSubstitutor =
|
||||||
|
ComposedSubstitutor(initialStorageSubstitutor, commonSystem.buildCurrentSubstitutor() as NewTypeSubstitutor)
|
||||||
|
updateCalls(lambda, resultingSubstitutor, commonSystem.errors)
|
||||||
|
|
||||||
return commonSystem.fixedTypeVariables.cast() // TODO: SUB
|
return commonSystem.fixedTypeVariables.cast() // TODO: SUB
|
||||||
}
|
}
|
||||||
@@ -289,23 +296,22 @@ class CoroutineInferenceSession(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateCalls(lambda: ResolvedLambdaAtom, commonSystem: NewConstraintSystemImpl) {
|
private fun updateCalls(lambda: ResolvedLambdaAtom, substitutor: NewTypeSubstitutor, errors: List<ConstraintSystemError>) {
|
||||||
val nonFixedToVariablesSubstitutor = createNonFixedTypeToVariableSubstitutor()
|
val nonFixedToVariablesSubstitutor = createNonFixedTypeToVariableSubstitutor()
|
||||||
val commonSystemSubstitutor = commonSystem.buildCurrentSubstitutor() as NewTypeSubstitutor
|
|
||||||
|
|
||||||
val nonFixedTypesToResult = nonFixedToVariablesSubstitutor.map.mapValues { commonSystemSubstitutor.safeSubstitute(it.value) }
|
val nonFixedTypesToResult = nonFixedToVariablesSubstitutor.map.mapValues { substitutor.safeSubstitute(it.value) }
|
||||||
val nonFixedTypesToResultSubstitutor = ComposedSubstitutor(commonSystemSubstitutor, nonFixedToVariablesSubstitutor)
|
val nonFixedTypesToResultSubstitutor = ComposedSubstitutor(substitutor, nonFixedToVariablesSubstitutor)
|
||||||
|
|
||||||
val atomCompleter = createResolvedAtomCompleter(nonFixedTypesToResultSubstitutor, topLevelCallContext)
|
val atomCompleter = createResolvedAtomCompleter(nonFixedTypesToResultSubstitutor, topLevelCallContext)
|
||||||
|
|
||||||
for (completedCall in commonCalls) {
|
for (completedCall in commonCalls) {
|
||||||
updateCall(completedCall, nonFixedTypesToResultSubstitutor, nonFixedTypesToResult)
|
updateCall(completedCall, nonFixedTypesToResultSubstitutor, nonFixedTypesToResult)
|
||||||
reportErrors(completedCall, completedCall.resolvedCall, commonSystem.errors)
|
reportErrors(completedCall, completedCall.resolvedCall, errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (callInfo in partiallyResolvedCallsInfo) {
|
for (callInfo in partiallyResolvedCallsInfo) {
|
||||||
val resolvedCall = completeCall(callInfo, atomCompleter) ?: continue
|
val resolvedCall = completeCall(callInfo, atomCompleter) ?: continue
|
||||||
reportErrors(callInfo, resolvedCall, commonSystem.errors)
|
reportErrors(callInfo, resolvedCall, errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (simpleCall in simpleCommonCalls) {
|
for (simpleCall in simpleCommonCalls) {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:OptIn(kotlin.experimental.ExperimentalTypeInference::class)
|
||||||
|
|
||||||
|
interface Flow<out T> {
|
||||||
|
fun collect(collector: FlowCollector<T>)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FlowCollector<in T> {
|
||||||
|
fun emit(value: T)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> flow(block: FlowCollector<T>.() -> Unit): Flow<T> =
|
||||||
|
object : Flow<T> {
|
||||||
|
override fun collect(collector: FlowCollector<T>) = collector.block()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> Flow<T>.collect(action: (value: T) -> Unit): Unit =
|
||||||
|
collect(object : FlowCollector<T> {
|
||||||
|
override fun emit(value: T) = action(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
fun <T, R> Flow<T>.transform(@BuilderInference transform: FlowCollector<R>.(T) -> Unit): Flow<R> =
|
||||||
|
flow { collect { transform(it) } }
|
||||||
|
|
||||||
|
fun <T, R> Flow<T>.map(transform: (T) -> R): Flow<R> =
|
||||||
|
transform { emit(transform(it)) }
|
||||||
|
|
||||||
|
var result: Any? = "not null"
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
flow<Int> { emit(1) }.map { null }.collect { result = it }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
main()
|
||||||
|
return if (result == null) "OK" else "fail: $result"
|
||||||
|
}
|
||||||
+5
@@ -13877,6 +13877,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
+5
@@ -13877,6 +13877,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
+5
@@ -12652,6 +12652,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
runTest("compiler/testData/codegen/box/inference/manyFlexibleTypeParametersFromJavaAndConversions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
Generated
+5
@@ -10827,6 +10827,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
|
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
Generated
+5
@@ -10827,6 +10827,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
|
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
+5
@@ -10892,6 +10892,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
|
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mapCollectChainWithNullResult.kt")
|
||||||
|
public void testMapCollectChainWithNullResult() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/mapCollectChainWithNullResult.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
@TestMetadata("noCoercionToUniForNullableLambdaReturnType.kt")
|
||||||
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
public void testNoCoercionToUniForNullableLambdaReturnType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
runTest("compiler/testData/codegen/box/inference/noCoercionToUniForNullableLambdaReturnType.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user