[FIR] Support determining emptiness of an intersection type with type parameters' types

This commit is contained in:
Victor Petukhov
2022-04-05 17:19:06 +03:00
committed by teamcity
parent 313da6f41e
commit 47d6236a2d
97 changed files with 1970 additions and 106 deletions
@@ -13888,6 +13888,24 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
}
@Test
@TestMetadata("kt48935_2.kt")
public void testKt48935_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt");
}
@Test
@TestMetadata("kt48935_3.kt")
public void testKt48935_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt");
}
@Test
@TestMetadata("kt48935_4.kt")
public void testKt48935_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt");
}
@Test
@TestMetadata("kt49658.kt")
public void testKt49658() throws Exception {
@@ -13840,12 +13840,126 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
}
@Test
@TestMetadata("kt45461_10.kt")
public void testKt45461_10() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_10.kt");
}
@Test
@TestMetadata("kt45461_11.kt")
public void testKt45461_11() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_11.kt");
}
@Test
@TestMetadata("kt45461_12.kt")
public void testKt45461_12() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_12.kt");
}
@Test
@TestMetadata("kt45461_13.kt")
public void testKt45461_13() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_13.kt");
}
@Test
@TestMetadata("kt45461_14.kt")
public void testKt45461_14() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_14.kt");
}
@Test
@TestMetadata("kt45461_15.kt")
public void testKt45461_15() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_15.kt");
}
@Test
@TestMetadata("kt45461_16.kt")
public void testKt45461_16() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_16.kt");
}
@Test
@TestMetadata("kt45461_17.kt")
public void testKt45461_17() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_17.kt");
}
@Test
@TestMetadata("kt45461_18.kt")
public void testKt45461_18() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_18.kt");
}
@Test
@TestMetadata("kt45461_19.kt")
public void testKt45461_19() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_19.kt");
}
@Test
@TestMetadata("kt45461_2.kt")
public void testKt45461_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt");
}
@Test
@TestMetadata("kt45461_20.kt")
public void testKt45461_20() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_20.kt");
}
@Test
@TestMetadata("kt45461_21.kt")
public void testKt45461_21() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_21.kt");
}
@Test
@TestMetadata("kt45461_22.kt")
public void testKt45461_22() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_22.kt");
}
@Test
@TestMetadata("kt45461_23.kt")
public void testKt45461_23() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_23.kt");
}
@Test
@TestMetadata("kt45461_24.kt")
public void testKt45461_24() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_24.kt");
}
@Test
@TestMetadata("kt45461_25.kt")
public void testKt45461_25() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_25.kt");
}
@Test
@TestMetadata("kt45461_26.kt")
public void testKt45461_26() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_26.kt");
}
@Test
@TestMetadata("kt45461_27.kt")
public void testKt45461_27() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_27.kt");
}
@Test
@TestMetadata("kt45461_28.kt")
public void testKt45461_28() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_28.kt");
}
@Test
@TestMetadata("kt45461_3.kt")
public void testKt45461_3() throws Exception {
@@ -13864,6 +13978,30 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt");
}
@Test
@TestMetadata("kt45461_6.kt")
public void testKt45461_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_6.kt");
}
@Test
@TestMetadata("kt45461_7.kt")
public void testKt45461_7() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_7.kt");
}
@Test
@TestMetadata("kt45461_8.kt")
public void testKt45461_8() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_8.kt");
}
@Test
@TestMetadata("kt45461_9.kt")
public void testKt45461_9() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_9.kt");
}
@Test
@TestMetadata("kt46515.kt")
public void testKt46515() throws Exception {
@@ -13888,6 +14026,36 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
}
@Test
@TestMetadata("kt48935_2.kt")
public void testKt48935_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt");
}
@Test
@TestMetadata("kt48935_3.kt")
public void testKt48935_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt");
}
@Test
@TestMetadata("kt48935_4.kt")
public void testKt48935_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt");
}
@Test
@TestMetadata("kt48935_5.kt")
public void testKt48935_5() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_5.kt");
}
@Test
@TestMetadata("kt48935_6.kt")
public void testKt48935_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_6.kt");
}
@Test
@TestMetadata("kt49658.kt")
public void testKt49658() throws Exception {
@@ -16459,6 +16627,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt");
}
@Test
@TestMetadata("nullableEmptyIntersection.kt")
public void testNullableEmptyIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("typeParameterAsUpperBound.kt")
public void testTypeParameterAsUpperBound() throws Exception {
@@ -13840,12 +13840,126 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
}
@Test
@TestMetadata("kt45461_10.kt")
public void testKt45461_10() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_10.kt");
}
@Test
@TestMetadata("kt45461_11.kt")
public void testKt45461_11() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_11.kt");
}
@Test
@TestMetadata("kt45461_12.kt")
public void testKt45461_12() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_12.kt");
}
@Test
@TestMetadata("kt45461_13.kt")
public void testKt45461_13() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_13.kt");
}
@Test
@TestMetadata("kt45461_14.kt")
public void testKt45461_14() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_14.kt");
}
@Test
@TestMetadata("kt45461_15.kt")
public void testKt45461_15() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_15.kt");
}
@Test
@TestMetadata("kt45461_16.kt")
public void testKt45461_16() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_16.kt");
}
@Test
@TestMetadata("kt45461_17.kt")
public void testKt45461_17() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_17.kt");
}
@Test
@TestMetadata("kt45461_18.kt")
public void testKt45461_18() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_18.kt");
}
@Test
@TestMetadata("kt45461_19.kt")
public void testKt45461_19() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_19.kt");
}
@Test
@TestMetadata("kt45461_2.kt")
public void testKt45461_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt");
}
@Test
@TestMetadata("kt45461_20.kt")
public void testKt45461_20() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_20.kt");
}
@Test
@TestMetadata("kt45461_21.kt")
public void testKt45461_21() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_21.kt");
}
@Test
@TestMetadata("kt45461_22.kt")
public void testKt45461_22() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_22.kt");
}
@Test
@TestMetadata("kt45461_23.kt")
public void testKt45461_23() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_23.kt");
}
@Test
@TestMetadata("kt45461_24.kt")
public void testKt45461_24() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_24.kt");
}
@Test
@TestMetadata("kt45461_25.kt")
public void testKt45461_25() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_25.kt");
}
@Test
@TestMetadata("kt45461_26.kt")
public void testKt45461_26() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_26.kt");
}
@Test
@TestMetadata("kt45461_27.kt")
public void testKt45461_27() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_27.kt");
}
@Test
@TestMetadata("kt45461_28.kt")
public void testKt45461_28() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_28.kt");
}
@Test
@TestMetadata("kt45461_3.kt")
public void testKt45461_3() throws Exception {
@@ -13864,6 +13978,30 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt");
}
@Test
@TestMetadata("kt45461_6.kt")
public void testKt45461_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_6.kt");
}
@Test
@TestMetadata("kt45461_7.kt")
public void testKt45461_7() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_7.kt");
}
@Test
@TestMetadata("kt45461_8.kt")
public void testKt45461_8() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_8.kt");
}
@Test
@TestMetadata("kt45461_9.kt")
public void testKt45461_9() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_9.kt");
}
@Test
@TestMetadata("kt46515.kt")
public void testKt46515() throws Exception {
@@ -13888,6 +14026,36 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
}
@Test
@TestMetadata("kt48935_2.kt")
public void testKt48935_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt");
}
@Test
@TestMetadata("kt48935_3.kt")
public void testKt48935_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt");
}
@Test
@TestMetadata("kt48935_4.kt")
public void testKt48935_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt");
}
@Test
@TestMetadata("kt48935_5.kt")
public void testKt48935_5() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_5.kt");
}
@Test
@TestMetadata("kt48935_6.kt")
public void testKt48935_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_6.kt");
}
@Test
@TestMetadata("kt49658.kt")
public void testKt49658() throws Exception {
@@ -16459,6 +16627,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt");
}
@Test
@TestMetadata("nullableEmptyIntersection.kt")
public void testNullableEmptyIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("typeParameterAsUpperBound.kt")
public void testTypeParameterAsUpperBound() throws Exception {
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
import org.jetbrains.kotlin.fir.resolve.substitution.NoSubstitutor
import org.jetbrains.kotlin.fir.resolve.substitution.createTypeSubstitutorByTypeConstructor
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
@@ -272,11 +273,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return ConeStubTypeForTypeVariableInSubtyping(typeVariable, ConeNullability.create(typeVariable.defaultType().isMarkedNullable()))
}
override fun KotlinTypeMarker.isFinal(): Boolean {
require(this is ConeKotlinType)
return !this.canHaveSubtypes(session)
}
override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker {
require(this is ConeKotlinType)
return withAttributes(ConeAttributes.Empty)
@@ -388,6 +384,13 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return this is ConeCapturedTypeConstructor
}
override fun KotlinTypeMarker.eraseContainingTypeParameters(): KotlinTypeMarker {
val erasedTypeParameters = this.extractTypeParameters()
.map { (it as ConeTypeParameterLookupTag).typeParameterSymbol }
.eraseToUpperBoundsAssociated(session, intersectUpperBounds = true, eraseRecursively = true)
return ConeSubstitutorByMap(erasedTypeParameters, session).safeSubstitute(this)
}
override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean {
return this.getTypeParameterClassifier() != null
}
@@ -477,7 +480,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return this.lowerBoundIfFlexible().safeAs<ConeKotlinType>()?.isExtensionFunctionType(session) == true
}
@OptIn(ExperimentalStdlibApi::class)
override fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List<KotlinTypeMarker> {
val builtInFunctionalType = getFunctionalTypeFromSupertypes().cast<ConeKotlinType>()
return buildList {
@@ -726,6 +726,9 @@ private fun SimpleTypeMarker.eraseArgumentsDeeply(
intersectUpperBounds: Boolean,
): ConeKotlinType = with(typeContext) {
replaceArgumentsDeeply { typeArgument ->
if (typeArgument.isStarProjection())
return@replaceArgumentsDeeply typeArgument
val typeConstructor = typeArgument.getType().typeConstructor().takeIf { it.isTypeParameterTypeConstructor() }
?: return@replaceArgumentsDeeply typeArgument
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
import org.jetbrains.kotlin.types.isDefinitelyEmpty
import org.jetbrains.kotlin.util.OperatorNameConventions
abstract class ResolutionStage {
@@ -579,12 +580,12 @@ internal object CheckLowPriorityInOverloadResolution : CheckerStage() {
internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() {
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) =
with(candidate.system.asConstraintSystemCompleterContext()) {
val typeVariables = candidate.system.notFixedTypeVariables.values
val typeVariables = candidate.system.notFixedTypeVariables.values.takeIf { it.isNotEmpty() } ?: return
for (variableWithConstraints in typeVariables) {
val upperTypes = variableWithConstraints.constraints.extractUpperTypes()
if (upperTypes.isEmptyIntersection()) {
if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) {
sink.yieldDiagnostic(
@Suppress("UNCHECKED_CAST")
InferredEmptyIntersectionDiagnostic(
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.diagnostics
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.Name
class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind = DiagnosticKind.Other) : ConeDiagnostic
@@ -29,6 +30,11 @@ class ConeAmbiguousSuper(val candidateTypes: List<ConeKotlinType>) : ConeDiagnos
get() = "Ambiguous supertype"
}
class ConeRecursiveTypeParameterDuringErasureError(val typeParameterName: Name) : ConeDiagnostic {
override val reason: String
get() = "self-recursive type parameter $typeParameterName"
}
enum class DiagnosticKind {
Syntax,
ExpressionExpected,
@@ -172,6 +172,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
return (this as? IrClassSymbol)?.owner?.isInterface == true
}
override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean = this is IrTypeParameterSymbol
override fun TypeParameterMarker.getVariance() = (this as IrTypeParameterSymbol).owner.variance.convertVariance()
private fun getSuperTypes(typeParameterMarker: TypeParameterMarker) = (typeParameterMarker as IrTypeParameterSymbol).owner.superTypes
@@ -8,11 +8,9 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
import org.jetbrains.kotlin.resolve.calls.inference.model.*
import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType
import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker
import org.jetbrains.kotlin.types.AbstractTypeChecker.isRelatedBySubtypingTo
import org.jetbrains.kotlin.types.model.*
abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Context, ResultTypeResolver.Context {
@@ -37,50 +35,6 @@ abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Contex
abstract fun couldBeResolvedWithUnrestrictedBuilderInference(): Boolean
abstract fun processForkConstraints()
private fun TypeConstructorMarker.isDefinitelyClass() = isClassTypeConstructor() && !isInterface()
private fun KotlinTypeMarker.containsTypeParameter() = contains { it.typeConstructor().isTypeParameterTypeConstructor() }
fun Collection<KotlinTypeMarker>.isEmptyIntersection(constraintSystem: NewConstraintSystem?): Boolean {
val indexedComponents = withIndex()
return indexedComponents.any firstTypes@{ (i, first) ->
val firstTypeConstructor = first.typeConstructor()
indexedComponents.any secondTypes@{ (j, second) ->
if (i >= j) return@secondTypes false
val secondTypeConstructor = second.typeConstructor()
if (!firstTypeConstructor.isDefinitelyClass() && !firstTypeConstructor.isTypeParameterTypeConstructor())
return@secondTypes false
if (!secondTypeConstructor.isDefinitelyClass() && !secondTypeConstructor.isTypeParameterTypeConstructor())
return@secondTypes false
if (!first.containsTypeParameter() && !second.containsTypeParameter()) {
return@secondTypes !isRelatedBySubtypingTo(this@ConstraintSystemCompletionContext, first, second)
}
if (constraintSystem == null) return false
val completerContext = constraintSystem.asConstraintSystemCompleterContext()
val substitutionMap = completerContext.allTypeVariables.entries.associate { (key, value) ->
val typeParameter = (key as TypeVariableTypeConstructorMarker).typeParameter
require(typeParameter != null) {
"Constraint system for checking type parameters for intersection emptiness" +
"should be build with type variables which refer to those type parameters"
}
typeParameter.getTypeConstructor() to value.defaultType()
}
val substitutor = typeSubstitutorByTypeConstructor(substitutionMap)
completerContext.getBuilder().addSubtypeConstraint(
substitutor.safeSubstitute(first), substitutor.safeSubstitute(second), TypeParametersIntersectionEmptyCheckingPosition
)
constraintSystem.hasContradiction
}
}
}
fun <A : PostponedResolvedAtomMarker> analyzeArgumentWithFixedParameterTypes(
languageVersionSettings: LanguageVersionSettings,
postponedArguments: List<A>,
@@ -44,7 +44,6 @@ class ResultTypeResolver(
return createCapturedStarProjectionForSelfType(typeVariableConstructor, typesForRecursiveTypeParameters)
}
@OptIn(ExperimentalStdlibApi::class)
private fun Context.getDefaultType(
direction: ResolveDirection,
constraints: List<Constraint>,
@@ -241,10 +240,13 @@ class ResultTypeResolver(
}
}
private fun Context.findSuperType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? {
val upperConstraints =
variableWithConstraints.constraints.filter { it.kind == ConstraintKind.UPPER && this@findSuperType.isProperTypeForFixation(it.type) }
if (upperConstraints.isNotEmpty()) {
private fun Context.computeUpperType(upperConstraints: List<Constraint>): KotlinTypeMarker {
val isInferringIntoEmptyIntersectionEnabled =
languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
// TODO: Remove this after stopping support of disabling `ForbidInferringTypeVariablesIntoEmptyIntersection`
// If `ForbidInferringTypeVariablesIntoEmptyIntersection` is enabled, we do the corresponding checks during resolution and completion
return if (!isInferringIntoEmptyIntersectionEnabled) {
val intersectionUpperType = intersectTypes(upperConstraints.map { it.type })
val resultIsActuallyIntersection = intersectionUpperType.typeConstructor().isIntersection()
@@ -268,12 +270,25 @@ class ResultTypeResolver(
val filteredUpperConstraints = upperConstraints.filterNot { it.isExpectedTypePosition() }.map { it.type }
if (filteredUpperConstraints.isNotEmpty()) intersectTypes(filteredUpperConstraints) else intersectionUpperType
} else intersectionUpperType
upperType
} else {
intersectTypes(upperConstraints.map { it.type })
}
}
private fun Context.findSuperType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? {
val upperConstraints =
variableWithConstraints.constraints.filter { it.kind == ConstraintKind.UPPER && this@findSuperType.isProperTypeForFixation(it.type) }
if (upperConstraints.isNotEmpty()) {
val upperType = computeUpperType(upperConstraints)
return typeApproximator.approximateToSubType(
upperType,
TypeApproximatorConfiguration.InternalTypesApproximation
) ?: upperType
}
return null
}
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.*
import org.jetbrains.kotlin.types.AbstractTypeApproximator
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
import org.jetbrains.kotlin.types.isDefinitelyEmpty
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.SmartSet
@@ -443,12 +444,14 @@ class NewConstraintSystemImpl(
val intersectionTypeConstructor = resultType.typeConstructor().takeIf { it is IntersectionTypeConstructorMarker } ?: return
val isInferredEmptyIntersectionForbidden =
languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
val intersectionComponents = intersectionTypeConstructor.supertypes()
val upperTypes = intersectionTypeConstructor.supertypes()
if (intersectionComponents.isEmptyIntersection()) {
if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) {
// Remove existing errors from resolution stage because a completion error is more precise
storage.errors.removeIf { it is InferredEmptyIntersectionError || it is InferredEmptyIntersectionWarning }
val errorFactory =
if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning
addError(errorFactory(intersectionComponents, variable))
addError(errorFactory(upperTypes, variable))
}
}
@@ -26,9 +26,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastI
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
import org.jetbrains.kotlin.types.model.typeConstructor
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.typeUtil.*
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addToStdlib.cast
@@ -903,12 +901,12 @@ internal object CheckContextReceiversResolutionPart : ResolutionPart() {
internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
override fun ResolutionCandidate.process(workIndex: Int) = with(getSystem().asConstraintSystemCompleterContext()) {
val typeVariables = getSystem().getBuilder().currentStorage().notFixedTypeVariables.values
val typeVariables = getSystem().getBuilder().currentStorage().notFixedTypeVariables.values.takeIf { it.isNotEmpty() } ?: return
for (variableWithConstraints in typeVariables) {
val upperTypes = variableWithConstraints.constraints.extractUpperTypes()
if (upperTypes.isEmptyIntersection()) {
if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) {
val isInferredEmptyIntersectionForbidden =
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
@@ -38,10 +38,10 @@ fun test() {
build2 {
emit(1)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>intersect(<!TYPE_MISMATCH!>this@build.getIn()<!>, getIn())<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>intersect(<!TYPE_MISMATCH!>getIn()<!>, Test.foo(this@build.getIn()))<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>intersect(<!TYPE_MISMATCH!>Test.foo(this@build.getIn())<!>, Test.foo(getIn()))<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>intersect(<!TYPE_MISMATCH!>Test.foo(getIn())<!>, this@build.getIn())<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>intersect<!>(this@build.getIn(), getIn())<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>intersect<!>(getIn(), Test.foo(this@build.getIn()))<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>intersect<!>(Test.foo(this@build.getIn()), Test.foo(getIn()))<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>intersect<!>(Test.foo(getIn()), this@build.getIn())<!>
""
}
""
@@ -7,6 +7,6 @@ fun <V> genericIn(x: In<V>) {}
/selectFromCovariantAndContravariantTypes.kt:13:20: warning: parameter 'x' is never used
fun <V> genericOut(x: Out<V>) {}
^
/selectFromCovariantAndContravariantTypes.kt:16:5: warning: type argument for a type parameter V can't be inferred because it's upper bounded by incompatible types: A, B. This will become an error in Kotlin 1.8
/selectFromCovariantAndContravariantTypes.kt:16:5: warning: type argument for a type parameter V can't be inferred because it's upper bounded by incompatible types: A, B. This will become an error in Kotlin 1.9
genericIn(select(a, b))
^
@@ -70,7 +70,7 @@ fun main() {
select(id1 { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!>.inv() }, id1 { x: Number -> TODO() }, id1(id2 { x: Int -> x }))
select(id1 { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!>.inv() }, id1 { x: Number -> TODO() }, id1(id2(::takeInt)))
select(id1 { x: Inv<out Number> -> TODO() }, id1 { <!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.Int>")!>it<!>.x.inv() }, id1 { x: Inv<Int> -> TODO() })
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION, INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>select<!>(id1 { <!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.Number> & Inv<kotlin.Int>")!>it<!> }, id1 { x: Inv<Number> -> TODO() }, id1 { x: Inv<Int> -> TODO() })
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>select<!>(id1 { <!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.Number> & Inv<kotlin.Int>")!>it<!> }, id1 { x: Inv<Number> -> TODO() }, id1 { x: Inv<Int> -> TODO() })
select(id(id2 { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!>.inv() }), id(id { x: Int -> x }))
// Disambiguating callable references by other callable references without overloads
@@ -1,6 +1,6 @@
/kt45461.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, Int. This will become an error in Kotlin 1.8
/kt45461.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, Int. This will become an error in Kotlin 1.9
Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,15 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Out<out P>
interface A
fun <K : Out<L>, L : N, N: A> main() {
val foo = Foo<K>()
Bar<Out<Int>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,31 @@
package
public fun </*0*/ K : Out<L>, /*1*/ L : N, /*2*/ N : A> main(): kotlin.Unit
public interface A {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Out</*0*/ out P> {
public constructor Out</*0*/ out P>()
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
}
@@ -0,0 +1,3 @@
/kt45461_11.kt:6:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
@@ -0,0 +1,17 @@
// FIR_IDENTICAL
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Out<out P>
interface A
open class B
fun <K : Out<L>, L : N, N: A> main() {
val foo = Foo<K>()
Bar<Out<B>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,38 @@
package
public fun </*0*/ K : Out<L>, /*1*/ L : N, /*2*/ N : A> main(): kotlin.Unit
public interface A {
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
}
public open class B {
public constructor B()
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Out</*0*/ out P> {
public constructor Out</*0*/ out P>()
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
}
@@ -0,0 +1,7 @@
/kt45461_12.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_12.kt:12:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.8
Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
interface A
fun <K : L, L : N, N> main() where N: A, N: Number {
val foo = Foo<K>()
Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
interface A
fun <K : L, L : N, N> main() where N: A, N: Number {
val foo = Foo<K>()
Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,24 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : A> main(): kotlin.Unit where N : kotlin.Number
public interface A {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
@@ -0,0 +1,15 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
interface A
class Out<out K>
fun <K : L, L : N, N> main() where N: Out<A> {
val foo = Foo<K>()
Bar<Out<String>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,31 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : Out<A>> main(): kotlin.Unit
public interface A {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Out</*0*/ out K> {
public constructor Out</*0*/ out K>()
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
}
@@ -0,0 +1,16 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Out<out P>
interface A
interface B
fun <K : Out<A>> main() {
val foo = Foo<K>()
Bar<Out<B>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,37 @@
package
public fun </*0*/ K : Out<A>> main(): kotlin.Unit
public interface A {
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
}
public interface B {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Out</*0*/ out P> {
public constructor Out</*0*/ out P>()
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
}
@@ -0,0 +1,6 @@
/kt45461_15.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_15.kt:14:21: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv<Int>, K. This will become an error in Kotlin 1.9
Bar<Inv<Int>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,15 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
interface A
fun <K : Inv<T>, T> main() where T: A, T: Number {
val foo = Foo<K>()
Bar<Inv<Int>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,15 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
interface A
fun <K : Inv<T>, T> main() where T: A, T: Number {
val foo = Foo<K>()
Bar<Inv<Int>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,31 @@
package
public fun </*0*/ K : Inv<T>, /*1*/ T : A> main(): kotlin.Unit where T : kotlin.Number
public interface A {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ P> {
public constructor Inv</*0*/ P>()
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
}
@@ -0,0 +1,15 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
interface A
fun <K : Inv<T>, T> main() where T: A, T: Number {
val foo = Foo<K>()
Bar<Inv<out Int>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,31 @@
package
public fun </*0*/ K : Inv<T>, /*1*/ T : A> main(): kotlin.Unit where T : kotlin.Number
public interface A {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ P> {
public constructor Inv</*0*/ P>()
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
}
@@ -0,0 +1,15 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
interface A
fun <K : Inv<T>, T> main() where T: <!FINAL_UPPER_BOUND!>String<!> {
val foo = Foo<K>()
Bar<Inv<out Nothing>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,31 @@
package
public fun </*0*/ K : Inv<T>, /*1*/ T : kotlin.String> main(): kotlin.Unit
public interface A {
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
}
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ P> {
public constructor Inv</*0*/ P>()
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
}
@@ -0,0 +1,13 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Out<out P>
fun <K : Out<L>, L : N, N: Number> main() {
val foo = Foo<K>()
Bar<Out<Int>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Out<L>, /*1*/ L : N, /*2*/ N : kotlin.Number> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Out</*0*/ out P> {
public constructor Out</*0*/ out P>()
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
}
@@ -0,0 +1,6 @@
/kt45461_19.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_19.kt:13:26: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Out<Inv<Int>>, K. This will become an error in Kotlin 1.9
Bar<Out<Inv<Int>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,14 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Out<out P>
class Inv<O>
fun <K : Out<L>, L : N, N: Inv<Number>> main() {
val foo = Foo<K>()
Bar<Out<Inv<Int>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,14 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Out<out P>
class Inv<O>
fun <K : Out<L>, L : N, N: Inv<Number>> main() {
val foo = Foo<K>()
Bar<Out<Inv<Int>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,32 @@
package
public fun </*0*/ K : Out<L>, /*1*/ L : N, /*2*/ N : Inv<kotlin.Number>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
public final class Out</*0*/ out P> {
public constructor Out</*0*/ out P>()
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
}
@@ -4,7 +4,7 @@
/kt45461_2.kt:8:10: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined
fun <K : Int> main() {
^
/kt45461_2.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.8
/kt45461_2.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.9
Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,14 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class In<in P>
class Inv<O>
fun <K : In<L>, L : N, N: Inv<Number>> main() {
val foo = Foo<K>()
Bar<In<Inv<Int>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,32 @@
package
public fun </*0*/ K : In<L>, /*1*/ L : N, /*2*/ N : Inv<kotlin.Number>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class In</*0*/ in P> {
public constructor In</*0*/ in P>()
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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -0,0 +1,6 @@
/kt45461_21.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_21.kt:13:25: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: In<Inv<Int>>, K. This will become an error in Kotlin 1.9
Bar<In<Inv<Int>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,14 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class In<in P>
class Inv<O>
fun <K : In<Inv<Number>>> main() {
val foo = Foo<K>()
Bar<In<Inv<Int>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,14 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class In<in P>
class Inv<O>
fun <K : In<Inv<Number>>> main() {
val foo = Foo<K>()
Bar<In<Inv<Int>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,32 @@
package
public fun </*0*/ K : In<Inv<kotlin.Number>>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class In</*0*/ in P> {
public constructor In</*0*/ in P>()
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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -0,0 +1,13 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : Inv<out Inv<out Number>>> main() {
val foo = Foo<K>()
Bar<Inv<Inv<Int>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<out Inv<out kotlin.Number>>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -0,0 +1,13 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : Inv<out Inv<out Number>>> main() {
val foo = Foo<K>()
Bar<Inv<in Inv<in Int>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<out Inv<out kotlin.Number>>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -0,0 +1,9 @@
/kt45461_24.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_24.kt:10:10: warning: 'Inv<out Inv<out Int>>' is a final type, and thus a value of the type parameter is predetermined
fun <K : Inv<out Inv<out Int>>> main() {
^
/kt45461_24.kt:12:35: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv<in Inv<in Number>>, K. This will become an error in Kotlin 1.9
Bar<Inv<in Inv<in Number>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : <!FINAL_UPPER_BOUND!>Inv<out Inv<out Int>><!>> main() {
val foo = Foo<K>()
Bar<Inv<in Inv<in Number>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : <!FINAL_UPPER_BOUND!>Inv<out Inv<out Int>><!>> main() {
val foo = Foo<K>()
Bar<Inv<in Inv<in Number>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<out Inv<out kotlin.Int>>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -0,0 +1,3 @@
/kt45461_25.kt:11:34: error: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K, Float
val x: Float = Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,12 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>): S = null <!UNCHECKED_CAST!>as S<!>
}
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
val foo = Foo<K>()
val x: Float = Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION("S; kotlin/String, K")!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,12 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>): S = null <!UNCHECKED_CAST!>as S<!>
}
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
val foo = Foo<K>()
val x: Float = Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("S; String, K, Float")!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,18 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : kotlin.Int> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): S
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
@@ -0,0 +1,4 @@
/kt45461_26.kt:13:44: error: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Out<String>, K, Out<Float>
val x: Out<Float> = Bar<Out<String>>().takeFoo(foo)
^
@@ -0,0 +1,14 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>): S = null <!UNCHECKED_CAST!>as S<!>
}
class Out<out K>
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Out<Int><!>> main() {
val foo = Foo<K>()
val x: Out<Float> = Bar<Out<String>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION("S; Out<kotlin/String>, K")!>takeFoo<!>(foo)
}
@@ -0,0 +1,14 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>): S = null <!UNCHECKED_CAST!>as S<!>
}
class Out<out K>
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Out<Int><!>> main() {
val foo = Foo<K>()
val x: Out<Float> = Bar<Out<String>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("S; Out<String>, K, Out<Float>")!>takeFoo<!>(foo)
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : Out<kotlin.Int>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): S
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Out</*0*/ out K> {
public constructor Out</*0*/ out K>()
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
}
@@ -0,0 +1,13 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : Inv<Inv<Number>>> main() {
val foo = Foo<K>()
Bar<Inv<in Inv<in Int>>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<Inv<kotlin.Number>>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -0,0 +1,12 @@
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : Inv<Inv<Number>>> main() {
val foo = Foo<K>()
Bar<Inv<in Inv<Int>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,12 @@
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<O>
fun <K : Inv<Inv<Number>>> main() {
val foo = Foo<K>()
Bar<Inv<in Inv<Int>>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<Inv<kotlin.Number>>> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ O> {
public constructor Inv</*0*/ O>()
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
}
@@ -1,9 +1,6 @@
/kt45461_5.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_5.kt:8:23: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined
fun <K : L, L : N, N: Int> main() {
^
/kt45461_5.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.8
/kt45461_5.kt:10:19: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: String, K. This will become an error in Kotlin 1.9
Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -5,7 +5,7 @@ class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
fun <K : L, L : N, N: Number> main() {
val foo = Foo<K>()
Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
fun <K : L, L : N, N: Number> main() {
val foo = Foo<K>()
Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -1,6 +1,6 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : kotlin.Int> main(): kotlin.Unit
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : kotlin.Number> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ T>()
@@ -0,0 +1,11 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
fun <K : L, L : N, N: Number> main() {
val foo = Foo<K>()
Bar<Int>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,18 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : kotlin.Number> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
@@ -0,0 +1,11 @@
// FIR_IDENTICAL
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
val foo = Foo<K>()
Bar<Number>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,18 @@
package
public fun </*0*/ K : L, /*1*/ L : N, /*2*/ N : kotlin.Int> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
@@ -0,0 +1,9 @@
/kt45461_8.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_8.kt:10:28: warning: 'Int' is a final type, and thus a value of the type parameter is predetermined
fun <K : Inv<L>, L : N, N: Int> main() {
^
/kt45461_8.kt:12:24: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv<Number>, K. This will become an error in Kotlin 1.9
Bar<Inv<Number>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
fun <K : Inv<L>, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
val foo = Foo<K>()
Bar<Inv<Number>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
fun <K : Inv<L>, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
val foo = Foo<K>()
Bar<Inv<Number>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<L>, /*1*/ L : N, /*2*/ N : kotlin.Int> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ P> {
public constructor Inv</*0*/ P>()
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
}
@@ -0,0 +1,7 @@
/kt45461_9.kt:5:25: warning: parameter 'foo' is never used
fun <S : T> takeFoo(foo: Foo<in S>) {}
^
/kt45461_9.kt:12:21: warning: type argument for a type parameter S can't be inferred because it's upper bounded by incompatible types: Inv<Int>, Inv<Number>. This will become an error in Kotlin 1.9
Bar<Inv<Int>>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
fun <K : Inv<L>, L : N, N: Number> main() {
val foo = Foo<Inv<Number>>()
Bar<Inv<Int>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,13 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
class Foo<T>
class Bar<T> {
fun <S : T> takeFoo(foo: Foo<in S>) {}
}
class Inv<P>
fun <K : Inv<L>, L : N, N: Number> main() {
val foo = Foo<Inv<Number>>()
Bar<Inv<Int>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
}
@@ -0,0 +1,25 @@
package
public fun </*0*/ K : Inv<L>, /*1*/ L : N, /*2*/ N : kotlin.Number> main(): kotlin.Unit
public final class Bar</*0*/ T> {
public constructor Bar</*0*/ 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 final fun </*0*/ S : T> takeFoo(/*0*/ foo: Foo<in S>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Foo</*0*/ T> {
public constructor Foo</*0*/ 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
}
public final class Inv</*0*/ P> {
public constructor Inv</*0*/ P>()
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
}
@@ -4,7 +4,7 @@
/kt48765.kt:4:52: warning: parameter 'x2' is never used
fun <T1: Number, T2: A<Float, T1>> foo(x1: T2, x2: T1) {}
^
/kt48765.kt:8:13: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: String, Number. This will become an error in Kotlin 1.8
/kt48765.kt:8:13: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: String, Number. This will become an error in Kotlin 1.9
B().foo(x, foo())
^
/kt48765.kt:12:9: warning: 'String' is a final type, and thus a value of the type parameter is predetermined
@@ -1,7 +1,4 @@
/kt48935.kt:6:35: warning: parameter 'func' is never used
/kt48935.kt:7:35: warning: parameter 'func' is never used
fun <T, V> exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit {
^
/kt48935.kt:12:5: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: Base, DoesNotImplementBase. This will become an error in Kotlin 1.8
exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied
^
@@ -1,4 +1,4 @@
/kt49661.kt:10:5: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: Foo, Int. This will become an error in Kotlin 1.8
/kt49661.kt:10:5: warning: type argument for a type parameter T can't be inferred because it's upper bounded by incompatible types: Foo, Int. This will become an error in Kotlin 1.9
f<Int> { g() }
^
@@ -0,0 +1,7 @@
fun <T : <!FINAL_UPPER_BOUND!>String<!>> g(): T? = null
fun <R> f(block: () -> R?): R? = block()
fun main() {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>f<!><Int> { g() /* OK, g() is inferred into {Int & String}? */ }
}
@@ -0,0 +1,7 @@
fun <T : <!FINAL_UPPER_BOUND!>String<!>> g(): T? = null
fun <R> f(block: () -> R?): R? = block()
fun main() {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>f<!><Int> { g() /* OK, g() is inferred into {Int & String}? */ }
}
@@ -0,0 +1,5 @@
package
public fun </*0*/ R> f(/*0*/ block: () -> R?): R?
public fun </*0*/ T : kotlin.String> g(): T?
public fun main(): kotlin.Unit
@@ -13846,12 +13846,126 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
}
@Test
@TestMetadata("kt45461_10.kt")
public void testKt45461_10() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_10.kt");
}
@Test
@TestMetadata("kt45461_11.kt")
public void testKt45461_11() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_11.kt");
}
@Test
@TestMetadata("kt45461_12.kt")
public void testKt45461_12() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_12.kt");
}
@Test
@TestMetadata("kt45461_13.kt")
public void testKt45461_13() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_13.kt");
}
@Test
@TestMetadata("kt45461_14.kt")
public void testKt45461_14() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_14.kt");
}
@Test
@TestMetadata("kt45461_15.kt")
public void testKt45461_15() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_15.kt");
}
@Test
@TestMetadata("kt45461_16.kt")
public void testKt45461_16() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_16.kt");
}
@Test
@TestMetadata("kt45461_17.kt")
public void testKt45461_17() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_17.kt");
}
@Test
@TestMetadata("kt45461_18.kt")
public void testKt45461_18() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_18.kt");
}
@Test
@TestMetadata("kt45461_19.kt")
public void testKt45461_19() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_19.kt");
}
@Test
@TestMetadata("kt45461_2.kt")
public void testKt45461_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_2.kt");
}
@Test
@TestMetadata("kt45461_20.kt")
public void testKt45461_20() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_20.kt");
}
@Test
@TestMetadata("kt45461_21.kt")
public void testKt45461_21() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_21.kt");
}
@Test
@TestMetadata("kt45461_22.kt")
public void testKt45461_22() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_22.kt");
}
@Test
@TestMetadata("kt45461_23.kt")
public void testKt45461_23() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_23.kt");
}
@Test
@TestMetadata("kt45461_24.kt")
public void testKt45461_24() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_24.kt");
}
@Test
@TestMetadata("kt45461_25.kt")
public void testKt45461_25() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_25.kt");
}
@Test
@TestMetadata("kt45461_26.kt")
public void testKt45461_26() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_26.kt");
}
@Test
@TestMetadata("kt45461_27.kt")
public void testKt45461_27() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_27.kt");
}
@Test
@TestMetadata("kt45461_28.kt")
public void testKt45461_28() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_28.kt");
}
@Test
@TestMetadata("kt45461_3.kt")
public void testKt45461_3() throws Exception {
@@ -13870,6 +13984,30 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_5.kt");
}
@Test
@TestMetadata("kt45461_6.kt")
public void testKt45461_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_6.kt");
}
@Test
@TestMetadata("kt45461_7.kt")
public void testKt45461_7() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_7.kt");
}
@Test
@TestMetadata("kt45461_8.kt")
public void testKt45461_8() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_8.kt");
}
@Test
@TestMetadata("kt45461_9.kt")
public void testKt45461_9() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt45461_9.kt");
}
@Test
@TestMetadata("kt46515.kt")
public void testKt46515() throws Exception {
@@ -13894,6 +14032,36 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
}
@Test
@TestMetadata("kt48935_2.kt")
public void testKt48935_2() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_2.kt");
}
@Test
@TestMetadata("kt48935_3.kt")
public void testKt48935_3() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_3.kt");
}
@Test
@TestMetadata("kt48935_4.kt")
public void testKt48935_4() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_4.kt");
}
@Test
@TestMetadata("kt48935_5.kt")
public void testKt48935_5() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_5.kt");
}
@Test
@TestMetadata("kt48935_6.kt")
public void testKt48935_6() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt48935_6.kt");
}
@Test
@TestMetadata("kt49658.kt")
public void testKt49658() throws Exception {
@@ -16465,6 +16633,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt");
}
@Test
@TestMetadata("nullableEmptyIntersection.kt")
public void testNullableEmptyIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/nullableEmptyIntersection.kt");
}
@Test
@TestMetadata("typeParameterAsUpperBound.kt")
public void testTypeParameterAsUpperBound() throws Exception {
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.types
enum class EmptyIntersectionTypeKind { NOT_EMPTY_INTERSECTION, MULTIPLE_CLASSES, SINGLE_FINAL_CLASS }
fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean = this == EmptyIntersectionTypeKind.MULTIPLE_CLASSES
fun EmptyIntersectionTypeKind.isPossibleEmpty(): Boolean = this == EmptyIntersectionTypeKind.SINGLE_FINAL_CLASS
@@ -5,9 +5,7 @@
package org.jetbrains.kotlin.types.model
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.TypeCheckerState
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.*
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
@@ -158,7 +156,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun TypeConstructorMarker.isCapturedTypeConstructor(): Boolean
fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean
fun KotlinTypeMarker.eraseContainingTypeParameters(): KotlinTypeMarker
fun Collection<KotlinTypeMarker>.singleBestRepresentative(): KotlinTypeMarker?
@@ -176,8 +174,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun createStubTypeForBuilderInference(typeVariable: TypeVariableMarker): StubTypeMarker
fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker
fun KotlinTypeMarker.isFinal(): Boolean
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
@@ -263,7 +259,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
private fun KotlinTypeMarker.extractTypeVariables(to: MutableSet<TypeVariableTypeConstructorMarker>) {
private fun <T> KotlinTypeMarker.extractTypeOf(to: MutableSet<T>, getIfApplicable: (TypeConstructorMarker) -> T?) {
for (i in 0 until argumentsCount()) {
val argument = getArgument(i)
@@ -271,16 +267,26 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
val argumentType = argument.getType()
val argumentTypeConstructor = argumentType.typeConstructor()
if (argumentTypeConstructor is TypeVariableTypeConstructorMarker) {
to.add(argumentTypeConstructor)
val argumentToAdd = getIfApplicable(argumentTypeConstructor)
if (argumentToAdd != null) {
to.add(argumentToAdd)
} else if (argumentType.argumentsCount() != 0) {
argumentType.extractTypeVariables(to)
argumentType.extractTypeOf(to, getIfApplicable)
}
}
}
@OptIn(ExperimentalStdlibApi::class)
fun KotlinTypeMarker.extractTypeVariables() = buildSet { extractTypeVariables(this) }
fun KotlinTypeMarker.extractTypeVariables(): Set<TypeVariableTypeConstructorMarker> =
buildSet {
extractTypeOf(this) { it as? TypeVariableTypeConstructorMarker }
}
fun KotlinTypeMarker.extractTypeParameters(): Set<TypeParameterMarker> =
buildSet {
typeConstructor().getTypeParameterClassifier()?.let(::add)
extractTypeOf(this) { it.getTypeParameterClassifier() }
}
/**
* For case Foo <: (T..T?) return LowerBound for new constraint LowerBound <: T
@@ -310,6 +316,172 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
return createCapturedType(starProjection, listOf(superType), lowerType = null, CaptureStatus.FROM_EXPRESSION)
}
fun Collection<KotlinTypeMarker>.computeEmptyIntersectionTypeKind(): EmptyIntersectionTypeKind {
if (this.isEmpty())
return EmptyIntersectionTypeKind.NOT_EMPTY_INTERSECTION
val types = this.withIndex()
for ((i, firstType) in types) {
if (!firstType.typeConstructor().mayCauseEmptyIntersection())
continue
val doesFirstTypeContainTypeParameters by lazy { firstType.contains { it.typeConstructor().isTypeParameterTypeConstructor() } }
val firstSubstitutedType by lazy { firstType.eraseContainingTypeParameters() }
for ((j, secondType) in types) {
if (i >= j || !secondType.typeConstructor().mayCauseEmptyIntersection()) continue
val doesSecondTypeContainTypeParameters = secondType.contains { it.typeConstructor().isTypeParameterTypeConstructor() }
val secondSubstitutedType by lazy { secondType.eraseContainingTypeParameters() }
val anyContainingTypeParameter = doesFirstTypeContainTypeParameters || doesSecondTypeContainTypeParameters
when {
!anyContainingTypeParameter && !canHaveSubtype(listOf(firstType, secondType)) ->
return EmptyIntersectionTypeKind.MULTIPLE_CLASSES
anyContainingTypeParameter && !canHaveSubtype(listOf(firstSubstitutedType, secondSubstitutedType)) ->
return EmptyIntersectionTypeKind.MULTIPLE_CLASSES
}
}
}
return EmptyIntersectionTypeKind.NOT_EMPTY_INTERSECTION
}
private fun canHaveSubtype(types: List<KotlinTypeMarker>): Boolean {
val expandedTypes = types.map {
if (it.typeConstructor() is IntersectionTypeConstructorMarker) {
it.typeConstructor().supertypes().toList()
} else listOf(it)
}.flatten().withIndex()
val typeCheckerState = newTypeCheckerState(errorTypesEqualToAnything = true, stubTypesEqualToAnything = true)
for ((i, firstType) in expandedTypes) {
val firstTypeConstructor = firstType.typeConstructor()
if (!firstTypeConstructor.mayCauseEmptyIntersection())
continue
for ((j, secondType) in expandedTypes) {
if (i >= j) continue
val secondTypeConstructor = secondType.typeConstructor()
if (!secondTypeConstructor.mayCauseEmptyIntersection())
continue
if (areEqualTypeConstructors(firstTypeConstructor, secondTypeConstructor) && secondTypeConstructor.parametersCount() == 0)
continue
// Below is determining having subtypes for two classes
// A class type may have only one supertype of class-based type constructor
val superTypeByFirstConstructor = AbstractTypeChecker.findCorrespondingSupertypes(
typeCheckerState, firstType.lowerBoundIfFlexible(), secondTypeConstructor
).takeIf { it.isNotEmpty() }?.single()
val superTypeBySecondConstructor = AbstractTypeChecker.findCorrespondingSupertypes(
typeCheckerState, secondType.lowerBoundIfFlexible(), firstTypeConstructor
).takeIf { it.isNotEmpty() }?.single()
if (superTypeByFirstConstructor == null && superTypeBySecondConstructor == null)
return false
if (superTypeByFirstConstructor == null || superTypeBySecondConstructor == null)
continue // first or second is actually subtype of another
if (!areTypeArgumentsCompatibleToHaveSubtypes(superTypeByFirstConstructor, superTypeBySecondConstructor)) {
return false
}
}
}
return true
}
private fun TypeArgumentMarker.uncaptureIfNeeded(): TypeArgumentMarker {
val type = getType()
return if (type is CapturedTypeMarker) type.typeConstructorProjection() else this
}
private fun computeEffectiveVariance(parameter: TypeParameterMarker, argument: TypeArgumentMarker): TypeVariance? =
AbstractTypeChecker.effectiveVariance(parameter.getVariance(), argument.getVariance())
private fun TypeConstructorMarker.mayCauseEmptyIntersection(): Boolean =
(isClassTypeConstructor() || isTypeParameterTypeConstructor()) && !isInterface() && !isAnyConstructor() && !isNothingConstructor()
private fun areArgumentsOfSpecifiedVariances(
firstType: KotlinTypeMarker,
secondType: KotlinTypeMarker,
argumentIndex: Int,
variance1: TypeVariance,
variance2: TypeVariance,
): Boolean {
val argumentOfFirst = firstType.getArgument(argumentIndex).uncaptureIfNeeded()
val parameterOfFirst = firstType.typeConstructor().getParameter(argumentIndex)
val argumentOfSecond = secondType.getArgument(argumentIndex).uncaptureIfNeeded()
val parameterOfSecond = secondType.typeConstructor().getParameter(argumentIndex)
val effectiveVariance1 = AbstractTypeChecker.effectiveVariance(parameterOfFirst.getVariance(), argumentOfFirst.getVariance())
val effectiveVariance2 = AbstractTypeChecker.effectiveVariance(parameterOfSecond.getVariance(), argumentOfSecond.getVariance())
return (effectiveVariance1 == variance1 && effectiveVariance2 == variance2)
|| (effectiveVariance1 == variance2 && effectiveVariance2 == variance1)
}
private fun areTypeArgumentsCompatibleToHaveSubtypes(firstType: KotlinTypeMarker, secondType: KotlinTypeMarker): Boolean {
require(firstType.typeConstructor() == secondType.typeConstructor()) {
"Type constructors of the passed types should be the same to compare their arguments"
}
fun isSubtypeOf(firstType: KotlinTypeMarker, secondType: KotlinTypeMarker) =
AbstractTypeChecker.isSubtypeOf(this, firstType, secondType)
for ((i, argumentOfFirst) in firstType.getArguments().withIndex()) {
@Suppress("NAME_SHADOWING")
val argumentOfFirst = argumentOfFirst.uncaptureIfNeeded()
val argumentOfSecond = secondType.getArgument(i).uncaptureIfNeeded()
if (argumentOfFirst == argumentOfSecond || argumentOfFirst.isStarProjection() || argumentOfSecond.isStarProjection())
continue
val argumentTypeOfFirst = argumentOfFirst.getType()
val argumentTypeOfSecond = argumentOfSecond.getType()
when {
areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.INV, TypeVariance.INV) ->
return false
areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.INV, TypeVariance.OUT) -> {
if (!isSubtypeOf(argumentTypeOfFirst, argumentTypeOfSecond)) {
return false
}
}
areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.INV, TypeVariance.IN) -> {
if (!isSubtypeOf(argumentTypeOfSecond, argumentTypeOfFirst)) {
return false
}
}
areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.IN, TypeVariance.OUT) -> {
if (argumentTypeOfFirst.argumentsCount() == 0 && argumentTypeOfSecond.argumentsCount() == 0) {
if (!isSubtypeOf(argumentTypeOfFirst, argumentTypeOfSecond)) {
return false
}
} else if (!canHaveSubtype(listOf(argumentTypeOfFirst, argumentTypeOfSecond))) {
return false
}
}
areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.OUT, TypeVariance.OUT)
|| areArgumentsOfSpecifiedVariances(firstType, secondType, i, TypeVariance.IN, TypeVariance.IN) -> {
if (!canHaveSubtype(listOf(argumentTypeOfFirst, argumentTypeOfSecond))) {
return false
}
}
}
}
return true
}
}
@@ -389,6 +561,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun TypeConstructorMarker.isLocalType(): Boolean
fun TypeConstructorMarker.isAnonymous(): Boolean
fun TypeConstructorMarker.getTypeParameterClassifier(): TypeParameterMarker?
fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean
val TypeVariableTypeConstructorMarker.typeParameter: TypeParameterMarker?
@@ -460,11 +460,6 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
return makeSimpleTypeDefinitelyNotNullOrNotNullInternal(this)
}
override fun KotlinTypeMarker.isFinal(): Boolean {
require(this is KotlinType, this::errorMessage)
return !TypeUtils.canHaveSubtypes(KotlinTypeChecker.DEFAULT, this)
}
override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker {
require(this is UnwrappedType, this::errorMessage)
return this.replaceAnnotations(Annotations.EMPTY)
@@ -714,6 +709,17 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
return this is NewCapturedTypeConstructor
}
override fun KotlinTypeMarker.eraseContainingTypeParameters(): KotlinTypeMarker {
val eraser = TypeParameterUpperBoundEraser(
ErasureProjectionComputer(),
TypeParameterErasureOptions(leaveNonTypeParameterTypes = true, intersectUpperBounds = true)
)
val typeParameters = this.extractTypeParameters()
.map { it as TypeParameterDescriptor }
.associateWith { TypeProjectionImpl(eraser.getErasedUpperBound(it, ErasureTypeAttributes(TypeUsage.COMMON))) }
return TypeConstructorSubstitution.createByParametersMap(typeParameters).buildSubstitutor().safeSubstitute(this)
}
override fun TypeConstructorMarker.isTypeParameterTypeConstructor(): Boolean {
return this is ClassifierBasedTypeConstructor && this.declarationDescriptor is AbstractTypeParameterDescriptor
}