Do subtyping with stub types properly
1) Return stub type if we are calculating super type between two same stub types 2) Return nullable Any if those stub types are different
This commit is contained in:
+58
-6
@@ -12638,12 +12638,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("renderingStubTypes.kt")
|
||||
public void testRenderingStubTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/renderingStubTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
@@ -12691,6 +12685,64 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
public void testSpecialCallsWithLambdas() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class StubTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInStubTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedTypes.kt")
|
||||
public void testCapturedTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperType.kt")
|
||||
public void testCommonSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeContravariant.kt")
|
||||
public void testCommonSuperTypeContravariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeCovariant.kt")
|
||||
public void testCommonSuperTypeCovariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeInvariant.kt")
|
||||
public void testCommonSuperTypeInvariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeNullable.kt")
|
||||
public void testCommonSuperTypeNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersect.kt")
|
||||
public void testIntersect() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("renderingStubTypes.kt")
|
||||
public void testRenderingStubTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+58
-6
@@ -12638,12 +12638,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("renderingStubTypes.kt")
|
||||
public void testRenderingStubTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/renderingStubTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
@@ -12691,6 +12685,64 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
public void testSpecialCallsWithLambdas() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class StubTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInStubTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedTypes.kt")
|
||||
public void testCapturedTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperType.kt")
|
||||
public void testCommonSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeContravariant.kt")
|
||||
public void testCommonSuperTypeContravariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeCovariant.kt")
|
||||
public void testCommonSuperTypeCovariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeInvariant.kt")
|
||||
public void testCommonSuperTypeInvariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeNullable.kt")
|
||||
public void testCommonSuperTypeNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersect.kt")
|
||||
public void testIntersect() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("renderingStubTypes.kt")
|
||||
public void testRenderingStubTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
@@ -256,6 +256,9 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
return ConeStubType(typeVariable, ConeNullability.create(typeVariable.defaultType().isMarkedNullable()))
|
||||
}
|
||||
|
||||
// TODO
|
||||
override fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker) = createStubType(typeVariable)
|
||||
|
||||
override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
return withAttributes(ConeAttributes.Empty, this@ConeInferenceContext)
|
||||
|
||||
@@ -380,7 +380,11 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.isStubType(): Boolean {
|
||||
return this is StubTypeMarker
|
||||
return this is ConeStubType // TODO: distinguish stub types for builder inference and for subtyping
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.isStubTypeForVariableInSubtyping(): Boolean {
|
||||
return this is ConeStubType // TODO: distinguish stub types for builder inference and for subtyping
|
||||
}
|
||||
|
||||
override fun intersectTypes(types: List<SimpleTypeMarker>): SimpleTypeMarker {
|
||||
|
||||
+53
-2
@@ -29,8 +29,10 @@ import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasBuilderInferenceAnnotation
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
@@ -146,6 +148,16 @@ class BuilderInferenceSession(
|
||||
return null
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
private fun findAllParentBuildInferenceSessions() = buildList {
|
||||
var currentSession: BuilderInferenceSession? = findParentBuildInferenceSession()
|
||||
|
||||
while (currentSession != null) {
|
||||
add(currentSession)
|
||||
currentSession = currentSession.findParentBuildInferenceSession()
|
||||
}
|
||||
}
|
||||
|
||||
fun hasInapplicableCall(): Boolean = hasInapplicableCall
|
||||
|
||||
override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean {
|
||||
@@ -257,6 +269,10 @@ class BuilderInferenceSession(
|
||||
): Boolean {
|
||||
storage.notFixedTypeVariables.values.forEach { commonSystem.registerVariable(it.typeVariable) }
|
||||
|
||||
for (parentSession in findAllParentBuildInferenceSessions()) {
|
||||
parentSession.stubsForPostponedVariables.keys.forEach { commonSystem.registerVariable(it) }
|
||||
}
|
||||
|
||||
/*
|
||||
* storage can contain the following substitutions:
|
||||
* TypeVariable(A) -> ProperType
|
||||
@@ -269,8 +285,10 @@ class BuilderInferenceSession(
|
||||
var introducedConstraint = false
|
||||
|
||||
for (initialConstraint in storage.initialConstraints) {
|
||||
val lower = nonFixedToVariablesSubstitutor.safeSubstitute(callSubstitutor.safeSubstitute(initialConstraint.a as UnwrappedType)) // TODO: SUB
|
||||
val upper = nonFixedToVariablesSubstitutor.safeSubstitute(callSubstitutor.safeSubstitute(initialConstraint.b as UnwrappedType)) // TODO: SUB
|
||||
val lowerCallSubstituted = callSubstitutor.safeSubstitute(initialConstraint.a as UnwrappedType)
|
||||
val upperCallSubstituted = callSubstitutor.safeSubstitute(initialConstraint.b as UnwrappedType)
|
||||
|
||||
val (lower, upper) = substituteNotFixedVariables(lowerCallSubstituted, upperCallSubstituted, nonFixedToVariablesSubstitutor)
|
||||
|
||||
if (commonSystem.isProperType(lower) && commonSystem.isProperType(upper)) continue
|
||||
|
||||
@@ -301,6 +319,39 @@ class BuilderInferenceSession(
|
||||
return introducedConstraint
|
||||
}
|
||||
|
||||
private fun substituteNotFixedVariables(
|
||||
lowerType: KotlinType,
|
||||
upperType: KotlinType,
|
||||
nonFixedToVariablesSubstitutor: NewTypeSubstitutor
|
||||
): Pair<KotlinType, KotlinType> {
|
||||
val commonCapTypes = extractCommonCapturedTypes(lowerType, upperType)
|
||||
val substitutedCommonCapType = commonCapTypes.associate {
|
||||
it.constructor as TypeConstructor to nonFixedToVariablesSubstitutor.safeSubstitute(it).asTypeProjection()
|
||||
}
|
||||
|
||||
val capTypesSubstitutor = TypeConstructorSubstitution.createByConstructorsMap(substitutedCommonCapType).buildSubstitutor()
|
||||
|
||||
val substitutedLowerType = nonFixedToVariablesSubstitutor.safeSubstitute(capTypesSubstitutor.substitute(lowerType.unwrap()))
|
||||
val substitutedUpperType = nonFixedToVariablesSubstitutor.safeSubstitute(capTypesSubstitutor.substitute(upperType.unwrap()))
|
||||
|
||||
return substitutedLowerType to substitutedUpperType
|
||||
}
|
||||
|
||||
private fun extractCommonCapturedTypes(a: KotlinType, b: KotlinType): List<NewCapturedType> {
|
||||
val extractedCapturedTypes = mutableSetOf<NewCapturedType>().also { extractCapturedTypes(a, it) }
|
||||
return extractedCapturedTypes.filter { capturedType -> b.contains { it.constructor === capturedType.constructor } }
|
||||
}
|
||||
|
||||
private fun extractCapturedTypes(type: KotlinType, capturedTypes: MutableSet<NewCapturedType>) {
|
||||
if (type is NewCapturedType) {
|
||||
capturedTypes.add(type)
|
||||
}
|
||||
for (typeArgument in type.arguments) {
|
||||
if (typeArgument.isStarProjection) continue
|
||||
extractCapturedTypes(typeArgument.type, capturedTypes)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildCommonSystem(initialStorage: ConstraintStorage): Pair<NewConstraintSystemImpl, Boolean> {
|
||||
val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns)
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
|
||||
override fun SimpleTypeMarker.isStubType() = false
|
||||
|
||||
override fun SimpleTypeMarker.isStubTypeForVariableInSubtyping() = false
|
||||
|
||||
override fun FlexibleTypeMarker.asDynamicType() = this as? IrDynamicType
|
||||
|
||||
override fun FlexibleTypeMarker.asRawType(): RawTypeMarker? = null
|
||||
@@ -394,8 +396,13 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker =
|
||||
TODO("IrTypeSystemContext doesn't support constraint system resolution")
|
||||
|
||||
override fun nullableAnyType(): SimpleTypeMarker =
|
||||
irBuiltIns.anyNType as IrSimpleType
|
||||
override fun nullableAnyType() = irBuiltIns.anyNType as IrSimpleType
|
||||
|
||||
override fun nullableNothingType() = irBuiltIns.nothingNType as IrSimpleType
|
||||
|
||||
override fun nothingType() = irBuiltIns.nothingType as IrSimpleType
|
||||
|
||||
override fun anyType() = irBuiltIns.anyType as IrSimpleType
|
||||
|
||||
override fun arrayType(componentType: KotlinTypeMarker): SimpleTypeMarker =
|
||||
irBuiltIns.arrayClass.typeWith(componentType as IrType)
|
||||
|
||||
+29
-10
@@ -59,7 +59,7 @@ object NewCommonSuperTypeCalculator {
|
||||
|
||||
if (!isTopLevelType) {
|
||||
val nonStubTypes =
|
||||
types.filter { !isStubRelatedType(it.lowerBoundIfFlexible()) && !isStubRelatedType(it.upperBoundIfFlexible()) }
|
||||
types.filter { !isTypeVariable(it.lowerBoundIfFlexible()) && !isTypeVariable(it.upperBoundIfFlexible()) }
|
||||
val equalToEachOtherTypes = nonStubTypes.filter { potentialCommonSuperType ->
|
||||
nonStubTypes.all {
|
||||
AbstractTypeChecker.equalTypes(this, it, potentialCommonSuperType)
|
||||
@@ -87,7 +87,7 @@ object NewCommonSuperTypeCalculator {
|
||||
|
||||
// i.e. result type also should be marked nullable
|
||||
val notAllNotNull =
|
||||
types.any { !isStubRelatedType(it) && !AbstractNullabilityChecker.isSubtypeOfAny(contextStubTypesEqualToAnything, it) }
|
||||
types.any { !isTypeVariable(it) && !AbstractNullabilityChecker.isSubtypeOfAny(contextStubTypesEqualToAnything, it) }
|
||||
val notNullTypes = if (notAllNotNull) types.map { it.withNullability(false) } else types
|
||||
|
||||
val commonSuperType = commonSuperTypeForNotNullTypes(notNullTypes, depth, contextStubTypesEqualToAnything, contextStubTypesNotEqual)
|
||||
@@ -164,14 +164,23 @@ object NewCommonSuperTypeCalculator {
|
||||
): SimpleTypeMarker {
|
||||
if (types.size == 1) return types.single()
|
||||
|
||||
val nonStubTypes = types.filter { !isStubRelatedType(it) }
|
||||
if (nonStubTypes.size == 1) return nonStubTypes.single()
|
||||
val nonTypeVariables = types.filter { !isTypeVariable(it) }
|
||||
if (nonTypeVariables.size == 1) return nonTypeVariables.single()
|
||||
|
||||
assert(nonStubTypes.isNotEmpty()) {
|
||||
assert(nonTypeVariables.isNotEmpty()) {
|
||||
"There should be at least one non-stub type to compute common supertype but there are: $types"
|
||||
}
|
||||
|
||||
val uniqueTypes = uniquify(nonStubTypes, contextStubTypesNotEqual)
|
||||
val stubTypeVariables = types.filter { isStubTypeVariable(it) }
|
||||
val nonStubTypeVariables = types.filter { !isStubTypeVariable(it) }
|
||||
val areAllNonStubTypesNothing = nonStubTypeVariables.isNotEmpty() && nonStubTypeVariables.all { it.isNothing() }
|
||||
if (nonStubTypeVariables.size == 1 && !areAllNonStubTypesNothing) return nonStubTypeVariables.single()
|
||||
|
||||
if (nonStubTypeVariables.isEmpty() || areAllNonStubTypesNothing) {
|
||||
return uniquify(stubTypeVariables, contextStubTypesNotEqual).singleOrNull() ?: nullableAnyType()
|
||||
}
|
||||
|
||||
val uniqueTypes = uniquify(nonTypeVariables, contextStubTypesNotEqual)
|
||||
if (uniqueTypes.size == 1) return uniqueTypes.single()
|
||||
|
||||
val explicitSupertypes = filterSupertypes(uniqueTypes, contextStubTypesNotEqual)
|
||||
@@ -183,16 +192,26 @@ object NewCommonSuperTypeCalculator {
|
||||
return findSuperTypeConstructorsAndIntersectResult(explicitSupertypes, depth, contextStubTypesEqualToAnything)
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.isStubRelatedType(type: SimpleTypeMarker): Boolean {
|
||||
return type.isStubType() || isCapturedStubType(type)
|
||||
private fun TypeSystemCommonSuperTypesContext.isStubTypeVariable(type: SimpleTypeMarker): Boolean {
|
||||
return type.isStubType() || isStubCapturedTypeVariable(type)
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.isCapturedStubType(type: SimpleTypeMarker): Boolean {
|
||||
private fun TypeSystemCommonSuperTypesContext.isStubCapturedTypeVariable(type: SimpleTypeMarker): Boolean {
|
||||
val projectedType =
|
||||
type.asCapturedType()?.typeConstructor()?.projection()?.takeUnless { it.isStarProjection() }?.getType() ?: return false
|
||||
return projectedType.asSimpleType()?.isStubType() == true
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.isTypeVariable(type: SimpleTypeMarker): Boolean {
|
||||
return type.isStubTypeForVariableInSubtyping() || isCapturedTypeVariable(type)
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.isCapturedTypeVariable(type: SimpleTypeMarker): Boolean {
|
||||
val projectedType =
|
||||
type.asCapturedType()?.typeConstructor()?.projection()?.takeUnless { it.isStarProjection() }?.getType() ?: return false
|
||||
return projectedType.asSimpleType()?.isStubTypeForVariableInSubtyping() == true
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.findErrorTypeInSupertypes(
|
||||
types: List<SimpleTypeMarker>,
|
||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext
|
||||
@@ -288,7 +307,7 @@ object NewCommonSuperTypeCalculator {
|
||||
null
|
||||
}
|
||||
|
||||
typeArgument.getType().lowerBoundIfFlexible().isStubType() -> null
|
||||
typeArgument.getType().lowerBoundIfFlexible().isStubTypeForVariableInSubtyping() -> null
|
||||
|
||||
else -> typeArgument
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,6 +43,6 @@ fun ConstraintStorage.buildNotFixedVariablesToNonSubtypableTypesSubstitutor(
|
||||
context: TypeSystemInferenceExtensionContext
|
||||
): TypeSubstitutorMarker {
|
||||
return context.typeSubstitutorByTypeConstructor(
|
||||
notFixedTypeVariables.mapValues { context.createStubType(it.value.typeVariable) }
|
||||
notFixedTypeVariables.mapValues { context.createStubTypeForTypeVariablesInSubtyping(it.value.typeVariable) }
|
||||
)
|
||||
}
|
||||
|
||||
+2
-4
@@ -134,15 +134,13 @@ class ResultTypeResolver(
|
||||
val types = sinkIntegerLiteralTypes(lowerConstraintTypes)
|
||||
var commonSuperType = computeCommonSuperType(types)
|
||||
|
||||
if (commonSuperType.contains { it is StubTypeMarker }) {
|
||||
if (commonSuperType.contains { it.asSimpleType()?.isStubTypeForVariableInSubtyping() == true }) {
|
||||
val typesWithoutStubs = types.filter { lowerType ->
|
||||
!lowerType.contains { it is StubTypeMarker }
|
||||
!lowerType.contains { it.asSimpleType()?.isStubTypeForVariableInSubtyping() == true }
|
||||
}
|
||||
|
||||
if (typesWithoutStubs.isNotEmpty()) {
|
||||
commonSuperType = computeCommonSuperType(typesWithoutStubs)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -77,6 +77,13 @@ class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : Typ
|
||||
return StubType(typeVariable.freshTypeConstructor() as TypeConstructor, typeVariable.defaultType().isMarkedNullable())
|
||||
}
|
||||
|
||||
override fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker {
|
||||
return StubTypeForTypeVariablesInSubtyping(
|
||||
typeVariable.freshTypeConstructor() as TypeConstructor,
|
||||
typeVariable.defaultType().isMarkedNullable()
|
||||
)
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.isTypeVariable(): Boolean {
|
||||
return this is TypeVariableTypeConstructor
|
||||
}
|
||||
|
||||
compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt
Vendored
+3
-3
@@ -39,7 +39,7 @@ fun <R> select(vararg x: R) = x[0]
|
||||
fun poll0(): Flow<String> {
|
||||
return flow {
|
||||
val inv = select(<!TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE!>::<!DEBUG_INFO_MISSING_UNRESOLVED!>bar<!><!>, <!TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE!>::<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!><!>)
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>inv<!>()
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ fun poll17(flag: Boolean): Flow<String> {
|
||||
fun poll2(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = when (flag) { true -> <!TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE!>::<!DEBUG_INFO_MISSING_UNRESOLVED!>bar<!><!> else -> <!TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE!>::<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!><!> }
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>inv<!>()
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ fun poll26(flag: Boolean): Flow<String> {
|
||||
fun poll3(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = when (flag) { true -> <!TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE!>::<!DEBUG_INFO_MISSING_UNRESOLVED!>bar<!><!> false -> <!TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE!>::<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!><!> }
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>inv<!>()
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -UNCHECKED_CAST -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build2(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
fun getOut(): Inv<out R>
|
||||
fun getIn(): Inv<in R>
|
||||
}
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <K> captureOut(x: Inv<out K>): K = null as K
|
||||
fun <K> captureIn(x: Inv<out K>): K = null as K
|
||||
fun <K> capture(x: Inv<K>): K = null as K
|
||||
|
||||
fun main() {
|
||||
build {
|
||||
emit("")
|
||||
getInv()
|
||||
captureOut(getInv())
|
||||
captureIn(getInv())
|
||||
|
||||
// K is fixed into CapturedType(out NotFixed: TypeVariable(R))
|
||||
capture(getOut())
|
||||
""
|
||||
}
|
||||
build {
|
||||
emit("")
|
||||
// K is fixed into CapturedType(in NotFixed: TypeVariable(R))
|
||||
capture(getIn())
|
||||
""
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -UNCHECKED_CAST -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build2(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
fun getOut(): Inv<out R>
|
||||
fun getIn(): Inv<in R>
|
||||
}
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <K> captureOut(x: Inv<out K>): K = null as K
|
||||
fun <K> captureIn(x: Inv<out K>): K = null as K
|
||||
fun <K> capture(x: Inv<K>): K = null as K
|
||||
|
||||
fun main() {
|
||||
build {
|
||||
emit("")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>")!>getInv()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)")!>captureOut(<!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.String>")!>getInv()<!>)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)")!>captureIn(<!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.String>")!>getInv()<!>)<!>
|
||||
|
||||
// K is fixed into CapturedType(out NotFixed: TypeVariable(R))
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)")!>capture(<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.String>")!>getOut()<!>)<!>
|
||||
""
|
||||
}
|
||||
build {
|
||||
emit("")
|
||||
// K is fixed into CapturedType(in NotFixed: TypeVariable(R))
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>capture(<!DEBUG_INFO_EXPRESSION_TYPE("Inv<in kotlin.Any?>")!>getIn()<!>)<!>
|
||||
""
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
public fun </*0*/ K> capture(/*0*/ x: Inv<K>): K
|
||||
public fun </*0*/ K> captureIn(/*0*/ x: Inv<out K>): K
|
||||
public fun </*0*/ K> captureOut(/*0*/ x: Inv<out K>): K
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ T> {
|
||||
public constructor Inv</*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 interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getIn(): Inv<in R>
|
||||
public abstract fun getInv(): Inv<R>
|
||||
public abstract fun getOut(): Inv<out R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build2(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
class Inv<K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U) = x
|
||||
fun <E> select(vararg x: E) = x[0]
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
Test.foo(get())
|
||||
Test.foo(getInv())
|
||||
id(get())
|
||||
select(get(), get())
|
||||
select(Test.foo(get()), Test.foo(get()))
|
||||
select(Test.foo(get()), get())
|
||||
select(getInv(), getInv())
|
||||
select(Test.foo(getInv()), Test.foo(getInv()))
|
||||
select(Test.foo(getInv()), getInv())
|
||||
select(getInv(), Test.foo(getInv()))
|
||||
select(id(get()), id(get()))
|
||||
build2 {
|
||||
emit(1)
|
||||
select(this@build.get(), get())
|
||||
select(Test.foo(this@build.get()), Test.foo(get()))
|
||||
select(this@build.getInv(), getInv())
|
||||
select(Test.foo(this@build.getInv()), Test.foo(getInv()))
|
||||
select(Test.foo(this@build.getInv()), getInv())
|
||||
select(id(this@build.get()), id(get()))
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build2(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
class Inv<K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U) = x
|
||||
fun <E> select(vararg x: E) = x[0]
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R)..TypeVariable(R)?)")!>Test.foo(get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<TypeVariable(R)>..Inv<TypeVariable(R)>?)")!>Test.foo(getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)")!>id(get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)")!>select(get(), get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R)..TypeVariable(R)?)")!>select(Test.foo(get()), Test.foo(get()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R)..TypeVariable(R)?)")!>select(Test.foo(get()), get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>")!>select(getInv(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<TypeVariable(R)>..Inv<TypeVariable(R)>?)")!>select(Test.foo(getInv()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<TypeVariable(R)>..Inv<TypeVariable(R)>?)")!>select(Test.foo(getInv()), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<TypeVariable(R)>..Inv<TypeVariable(R)>?)")!>select(getInv(), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)")!>select(id(get()), id(get()))<!>
|
||||
build2 {
|
||||
emit(1)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(this@build.get(), get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(Test.foo(this@build.get()), Test.foo(get()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>")!>select(this@build.getInv(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<out kotlin.Any?>..Inv<out kotlin.Any?>?)")!>select(Test.foo(this@build.getInv()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(Inv<out kotlin.Any?>..Inv<out kotlin.Any?>?)")!>select(Test.foo(this@build.getInv()), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(id(this@build.get()), id(get()))<!>
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
public fun </*0*/ U> id(/*0*/ x: U): U
|
||||
public fun </*0*/ E> select(/*0*/ vararg x: E /*kotlin.Array<out E>*/): E
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ K> {
|
||||
public constructor Inv</*0*/ 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
|
||||
}
|
||||
|
||||
public/*package*/ open class Test {
|
||||
public/*package*/ constructor Test()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public/*package*/ open fun </*0*/ T : kotlin.Any!> foo(/*0*/ x: T!): T!
|
||||
}
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getInv(): Inv<R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class In<in K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getIn(): In<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select1(x: E, y: In<E>): E? = x
|
||||
fun <E> select2(x: E, y: In<E?>): E = x
|
||||
fun <E> select3(x: E?, y: In<E?>): E = x!!
|
||||
fun <E> select4(x: E?, y: In<E>): E = x!!
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
select1(get(), getIn())
|
||||
select1(get(), Test.foo(getIn()))
|
||||
select1(Test.foo(get()), Test.foo(getIn()))
|
||||
select1(Test.foo(get()), getIn())
|
||||
select4(get(), getIn())
|
||||
select4(get(), Test.foo(getIn()))
|
||||
select4(Test.foo(get()), Test.foo(getIn()))
|
||||
select4(Test.foo(get()), getIn())
|
||||
|
||||
select4(id(Test.foo(get())), getIn())
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select1(this@build.get(), getIn())
|
||||
select1(get(), Test.foo(this@build.getIn()))
|
||||
select1(Test.foo(this@build.get()), Test.foo(getIn()))
|
||||
select1(Test.foo(get()), this@build.getIn())
|
||||
select2(this@build.get(), getIn())
|
||||
select2(get(), Test.foo(this@build.getIn()))
|
||||
select2(Test.foo(this@build.get()), Test.foo(getIn()))
|
||||
select2(Test.foo(get()), this@build.getIn())
|
||||
select3(this@build.get(), getIn())
|
||||
select3(get(), Test.foo(this@build.getIn()))
|
||||
select3(Test.foo(this@build.get()), Test.foo(getIn()))
|
||||
select3(Test.foo(get()), this@build.getIn())
|
||||
select4(this@build.get(), getIn())
|
||||
select4(get(), Test.foo(this@build.getIn()))
|
||||
select4(Test.foo(this@build.get()), Test.foo(getIn()))
|
||||
select4(Test.foo(get()), this@build.getIn())
|
||||
|
||||
select4(id(Test.foo(this@build.get())), getIn())
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
val ret2 = build {
|
||||
emit(if (true) "" else null)
|
||||
select2(get(), getIn())
|
||||
select2(get(), Test.foo(getIn()))
|
||||
select2(Test.foo(get()), Test.foo(getIn()))
|
||||
select2(Test.foo(get()), getIn())
|
||||
select3(get(), getIn())
|
||||
select3(get(), Test.foo(getIn()))
|
||||
select3(Test.foo(get()), Test.foo(getIn()))
|
||||
select3(Test.foo(get()), getIn())
|
||||
""
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class In<in K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getIn(): In<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select1(x: E, y: In<E>): E? = x
|
||||
fun <E> select2(x: E, y: In<E?>): E = x
|
||||
fun <E> select3(x: E?, y: In<E?>): E = x!!
|
||||
fun <E> select4(x: E?, y: In<E>): E = x!!
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(get(), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(get(), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(Test.foo(get()), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(Test.foo(get()), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(get(), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(get(), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(Test.foo(get()), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(Test.foo(get()), getIn())<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(id(Test.foo(get())), getIn())<!>
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select1(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getIn()<!>)
|
||||
select1(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getIn())<!>)
|
||||
select1(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)!")!>Test.foo(getIn())<!>)
|
||||
select1(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)!")!>this@build.getIn()<!>)
|
||||
select2(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getIn()<!>)
|
||||
select2(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getIn())<!>)
|
||||
select2(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)!")!>Test.foo(getIn())<!>)
|
||||
select2(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)!")!>this@build.getIn()<!>)
|
||||
select3(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getIn()<!>)
|
||||
select3(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getIn())<!>)
|
||||
select3(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>Test.foo(getIn())<!>)
|
||||
select3(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>this@build.getIn()<!>)
|
||||
select4(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getIn()<!>)
|
||||
select4(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getIn())<!>)
|
||||
select4(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>Test.foo(getIn())<!>)
|
||||
select4(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>this@build.getIn()<!>)
|
||||
|
||||
select4(id(Test.foo(this@build.get())), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getIn()<!>)
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
val ret2 = build {
|
||||
emit(if (true) "" else null)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(get(), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(get(), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R1)..TypeVariable(R1)?)")!>select2(Test.foo(get()), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R1)..TypeVariable(R1)?)")!>select2(Test.foo(get()), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(get(), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(get(), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(Test.foo(get()), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(Test.foo(get()), getIn())<!>
|
||||
""
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R1> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R1>.() -> kotlin.Unit): R1
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R2> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R2>.() -> kotlin.Unit): R2
|
||||
public fun </*0*/ U> id(/*0*/ x: U): U?
|
||||
public fun </*0*/ E> select1(/*0*/ x: E, /*1*/ y: In<E>): E?
|
||||
public fun </*0*/ E> select2(/*0*/ x: E, /*1*/ y: In<E?>): E
|
||||
public fun </*0*/ E> select3(/*0*/ x: E?, /*1*/ y: In<E?>): E
|
||||
public fun </*0*/ E> select4(/*0*/ x: E?, /*1*/ y: In<E>): E
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class In</*0*/ in K> {
|
||||
public constructor In</*0*/ in 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
|
||||
}
|
||||
|
||||
public/*package*/ open class Test {
|
||||
public/*package*/ constructor Test()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public/*package*/ open fun </*0*/ T : kotlin.Any!> foo(/*0*/ x: T!): T!
|
||||
}
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getIn(): In<R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class Out<out K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getOut(): Out<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select1(x: E, y: Out<E>): E? = x
|
||||
fun <E> select2(x: E, y: Out<E?>): E = x
|
||||
fun <E> select3(x: E?, y: Out<E?>): E = x!!
|
||||
fun <E> select4(x: E?, y: Out<E>): E = x!!
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
select1(get(), getOut())
|
||||
select1(get(), Test.foo(getOut()))
|
||||
select1(Test.foo(get()), Test.foo(getOut()))
|
||||
select1(Test.foo(get()), getOut())
|
||||
select2(get(), getOut())
|
||||
select2(get(), Test.foo(getOut()))
|
||||
select2(Test.foo(get()), Test.foo(getOut()))
|
||||
select2(Test.foo(get()), getOut())
|
||||
select3(get(), getOut())
|
||||
select3(get(), Test.foo(getOut()))
|
||||
select3(Test.foo(get()), Test.foo(getOut()))
|
||||
select3(Test.foo(get()), getOut())
|
||||
select4(get(), getOut())
|
||||
select4(get(), Test.foo(getOut()))
|
||||
select4(Test.foo(get()), Test.foo(getOut()))
|
||||
select4(Test.foo(get()), getOut())
|
||||
|
||||
select4(id(Test.foo(get())), getOut())
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select1(this@build.get(), getOut())
|
||||
select1(get(), Test.foo(this@build.getOut()))
|
||||
select1(Test.foo(this@build.get()), Test.foo(getOut()))
|
||||
select1(Test.foo(get()), this@build.getOut())
|
||||
select2(this@build.get(), getOut())
|
||||
select2(get(), Test.foo(this@build.getOut()))
|
||||
select2(Test.foo(this@build.get()), Test.foo(getOut()))
|
||||
select2(Test.foo(get()), this@build.getOut())
|
||||
select3(this@build.get(), getOut())
|
||||
select3(get(), Test.foo(this@build.getOut()))
|
||||
select3(Test.foo(this@build.get()), Test.foo(getOut()))
|
||||
select3(Test.foo(get()), this@build.getOut())
|
||||
select4(this@build.get(), getOut())
|
||||
select4(get(), Test.foo(this@build.getOut()))
|
||||
select4(Test.foo(this@build.get()), Test.foo(getOut()))
|
||||
select4(Test.foo(get()), this@build.getOut())
|
||||
|
||||
select4(id(Test.foo(this@build.get())), getOut())
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class Out<out K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getOut(): Out<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select1(x: E, y: Out<E>): E? = x
|
||||
fun <E> select2(x: E, y: Out<E?>): E = x
|
||||
fun <E> select3(x: E?, y: Out<E?>): E = x!!
|
||||
fun <E> select4(x: E?, y: Out<E>): E = x!!
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(get(), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(Test.foo(get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(Test.foo(get()), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(get(), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R1)..TypeVariable(R1)?)")!>select2(Test.foo(get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(TypeVariable(R1)..TypeVariable(R1)?)")!>select2(Test.foo(get()), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(get(), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(Test.foo(get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(Test.foo(get()), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(get(), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(Test.foo(get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(Test.foo(get()), getOut())<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(id(Test.foo(get())), getOut())<!>
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select1(this@build.get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select1(get(), Test.foo(this@build.getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select1(Test.foo(this@build.get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select1(Test.foo(get()), this@build.getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select2(this@build.get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select2(get(), Test.foo(this@build.getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select2(Test.foo(this@build.get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select2(Test.foo(get()), this@build.getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select3(this@build.get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select3(get(), Test.foo(this@build.getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select3(Test.foo(this@build.get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select3(Test.foo(get()), this@build.getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select4(this@build.get(), getOut())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select4(get(), Test.foo(this@build.getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select4(Test.foo(this@build.get()), Test.foo(getOut()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select4(Test.foo(get()), this@build.getOut())<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select4(id(Test.foo(this@build.get())), getOut())<!>
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R1> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R1>.() -> kotlin.Unit): R1
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R2> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R2>.() -> kotlin.Unit): R2
|
||||
public fun </*0*/ U> id(/*0*/ x: U): U?
|
||||
public fun </*0*/ E> select1(/*0*/ x: E, /*1*/ y: Out<E>): E?
|
||||
public fun </*0*/ E> select2(/*0*/ x: E, /*1*/ y: Out<E?>): E
|
||||
public fun </*0*/ E> select3(/*0*/ x: E?, /*1*/ y: Out<E?>): E
|
||||
public fun </*0*/ E> select4(/*0*/ x: E?, /*1*/ y: Out<E>): E
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
public/*package*/ open class Test {
|
||||
public/*package*/ constructor Test()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public/*package*/ open fun </*0*/ T : kotlin.Any!> foo(/*0*/ x: T!): T!
|
||||
}
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getOut(): Out<R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class Inv<K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select1(x: E, y: Inv<E>): E? = x
|
||||
fun <E> select2(x: E, y: Inv<E?>): E = x
|
||||
fun <E> select3(x: E?, y: Inv<E?>): E = x!!
|
||||
fun <E> select4(x: E?, y: Inv<E>): E = x!!
|
||||
|
||||
fun test() {
|
||||
val ret1 = build {
|
||||
emit("1")
|
||||
select1(get(), getInv())
|
||||
select1(get(), Test.foo(getInv()))
|
||||
select1(Test.foo(get()), Test.foo(getInv()))
|
||||
select1(Test.foo(get()), getInv())
|
||||
select4(get(), getInv())
|
||||
select4(get(), Test.foo(getInv()))
|
||||
select4(Test.foo(get()), Test.foo(getInv()))
|
||||
select4(Test.foo(get()), getInv())
|
||||
|
||||
select4(id(Test.foo(get())), getInv())
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select1(this@build.get(), getInv())
|
||||
select1(get(), Test.foo(this@build.getInv()))
|
||||
select1(Test.foo(this@build.get()), Test.foo(getInv()))
|
||||
select1(Test.foo(get()), this@build.getInv())
|
||||
select4(this@build.get(), getInv())
|
||||
select4(get(), Test.foo(this@build.getInv()))
|
||||
select4(Test.foo(this@build.get()), Test.foo(getInv()))
|
||||
select4(Test.foo(get()), this@build.getInv())
|
||||
|
||||
select4(id(Test.foo(this@build.get())), getInv())
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
val ret2 = build {
|
||||
emit(if (true) "1" else null)
|
||||
select2(get(), getInv())
|
||||
select2(get(), Test.foo(getInv()))
|
||||
select2(Test.foo(get()), Test.foo(getInv()))
|
||||
select2(Test.foo(get()), getInv())
|
||||
select3(get(), getInv())
|
||||
select3(get(), Test.foo(getInv()))
|
||||
select3(Test.foo(get()), Test.foo(getInv()))
|
||||
select3(Test.foo(get()), getInv())
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select2(this@build.get(), getInv())
|
||||
select2(get(), Test.foo(this@build.getInv()))
|
||||
select2(Test.foo(this@build.get()), Test.foo(getInv()))
|
||||
select2(Test.foo(get()), this@build.getInv())
|
||||
select3(this@build.get(), getInv())
|
||||
select3(get(), Test.foo(this@build.getInv()))
|
||||
select3(Test.foo(this@build.get()), Test.foo(getInv()))
|
||||
select3(Test.foo(get()), this@build.getInv())
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class Inv<K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select1(x: E, y: Inv<E>): E? = x
|
||||
fun <E> select2(x: E, y: Inv<E?>): E = x
|
||||
fun <E> select3(x: E?, y: Inv<E?>): E = x!!
|
||||
fun <E> select4(x: E?, y: Inv<E>): E = x!!
|
||||
|
||||
fun test() {
|
||||
val ret1 = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(get(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(get(), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(Test.foo(get()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)?")!>select1(Test.foo(get()), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(get(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(get(), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(Test.foo(get()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(Test.foo(get()), getInv())<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select4(id(Test.foo(get())), getInv())<!>
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select1(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getInv()<!>)
|
||||
select1(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getInv())<!>)
|
||||
select1(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)!")!>Test.foo(getInv())<!>)
|
||||
select1(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)!")!>this@build.getInv()<!>)
|
||||
select4(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getInv()<!>)
|
||||
select4(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getInv())<!>)
|
||||
select4(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>Test.foo(getInv())<!>)
|
||||
select4(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>this@build.getInv()<!>)
|
||||
|
||||
select4(id(Test.foo(this@build.get())), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getInv()<!>)
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
val ret2 = build {
|
||||
emit(if (true) "1" else null)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(get(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(get(), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(Test.foo(get()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select2(Test.foo(get()), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(get(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(get(), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(Test.foo(get()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>select3(Test.foo(get()), getInv())<!>
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
select2(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getInv()<!>)
|
||||
select2(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getInv())<!>)
|
||||
select2(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)!")!>Test.foo(getInv())<!>)
|
||||
select2(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)!")!>this@build.getInv()<!>)
|
||||
select3(this@build.get(), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>getInv()<!>)
|
||||
select3(get(), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>Test.foo(this@build.getInv())<!>)
|
||||
select3(Test.foo(this@build.get()), <!TYPE_MISMATCH("TypeVariable(R2); TypeVariable(R1)")!>Test.foo(getInv())<!>)
|
||||
select3(Test.foo(get()), <!TYPE_MISMATCH("TypeVariable(R1); TypeVariable(R2)")!>this@build.getInv()<!>)
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R1> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R1>.() -> kotlin.Unit): R1
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R2> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R2>.() -> kotlin.Unit): R2
|
||||
public fun </*0*/ U> id(/*0*/ x: U): U?
|
||||
public fun </*0*/ E> select1(/*0*/ x: E, /*1*/ y: Inv<E>): E?
|
||||
public fun </*0*/ E> select2(/*0*/ x: E, /*1*/ y: Inv<E?>): E
|
||||
public fun </*0*/ E> select3(/*0*/ x: E?, /*1*/ y: Inv<E?>): E
|
||||
public fun </*0*/ E> select4(/*0*/ x: E?, /*1*/ y: Inv<E>): E
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ K> {
|
||||
public constructor Inv</*0*/ 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
|
||||
}
|
||||
|
||||
public/*package*/ open class Test {
|
||||
public/*package*/ constructor Test()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public/*package*/ open fun </*0*/ T : kotlin.Any!> foo(/*0*/ x: T!): T!
|
||||
}
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getInv(): Inv<R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
import org.jetbrains.annotations.*
|
||||
|
||||
class Test {
|
||||
@Nullable
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build2(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
class Inv<K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select(vararg x: E): E? = x[0]
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
Test.foo(get())
|
||||
Test.foo(getInv())
|
||||
id(get())
|
||||
select(get(), get())
|
||||
select(Test.foo(get()), Test.foo(get()))
|
||||
select(Test.foo(get()), get())
|
||||
select(getInv(), getInv())
|
||||
select(Test.foo(getInv()), Test.foo(getInv()))
|
||||
select(Test.foo(getInv()), getInv())
|
||||
select(getInv(), Test.foo(getInv()))
|
||||
select(id(get()), id(get()))
|
||||
build2 {
|
||||
emit(1)
|
||||
select(this@build.get(), get())
|
||||
select(Test.foo(this@build.get()), Test.foo(get()))
|
||||
select(this@build.getInv(), getInv())
|
||||
select(Test.foo(this@build.getInv()), Test.foo(getInv()))
|
||||
select(Test.foo(this@build.getInv()), getInv())
|
||||
select(id(this@build.get()), id(get()))
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
val ret2 = build {
|
||||
emit("1")
|
||||
select(get(), null)
|
||||
select(Test.foo(null), Test.foo(get()))
|
||||
select(Test.foo(get()), null)
|
||||
select(null, getInv())
|
||||
select(Test.foo(getInv()), Test.foo(null))
|
||||
select(Test.foo(null), getInv())
|
||||
select(getInv(), Test.foo(null))
|
||||
select(id(null), id(get()))
|
||||
build2 {
|
||||
emit(1)
|
||||
select(this@build.get(), get(), null)
|
||||
select(Test.foo(this@build.get()), Test.foo(get()), null)
|
||||
select(this@build.getInv(), getInv(), null)
|
||||
select(Test.foo(this@build.getInv()), Test.foo(getInv()), null)
|
||||
select(Test.foo(this@build.getInv()), getInv(), null)
|
||||
select(id(this@build.get()), id(get()), null)
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
Vendored
+81
@@ -0,0 +1,81 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
import org.jetbrains.annotations.*
|
||||
|
||||
class Test {
|
||||
@Nullable
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> build2(@BuilderInference block: TestInterface<R>.() -> Unit): R = TODO()
|
||||
|
||||
class Inv<K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U): U? = x
|
||||
fun <E> select(vararg x: E): E? = x[0]
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>Test.foo(get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>Test.foo(getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>id(get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(get(), get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(Test.foo(get()), Test.foo(get()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(Test.foo(get()), get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(getInv(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(Test.foo(getInv()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(Test.foo(getInv()), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(getInv(), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(id(get()), id(get()))<!>
|
||||
build2 {
|
||||
emit(1)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(this@build.get(), get())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(Test.foo(this@build.get()), Test.foo(get()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>?")!>select(this@build.getInv(), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>?")!>select(Test.foo(this@build.getInv()), Test.foo(getInv()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>?")!>select(Test.foo(this@build.getInv()), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(id(this@build.get()), id(get()))<!>
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
val ret2 = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(get(), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(Test.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION!>foo<!>(null), Test.foo(get()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(Test.foo(get()), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(null, getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(Test.foo(getInv()), Test.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION!>foo<!>(null))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(Test.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION!>foo<!>(null), getInv())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<TypeVariable(R)>?")!>select(getInv(), Test.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION!>foo<!>(null))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R)?")!>select(<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION!>id<!>(null), id(get()))<!>
|
||||
build2 {
|
||||
emit(1)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(this@build.get(), get(), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(Test.foo(this@build.get()), Test.foo(get()), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>?")!>select(this@build.getInv(), getInv(), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>?")!>select(Test.foo(this@build.getInv()), Test.foo(getInv()), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out kotlin.Any?>?")!>select(Test.foo(this@build.getInv()), getInv(), null)<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>select(id(this@build.get()), id(get()), null)<!>
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.txt
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
public fun </*0*/ U> id(/*0*/ x: U): U?
|
||||
public fun </*0*/ E> select(/*0*/ vararg x: E /*kotlin.Array<out E>*/): E?
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ K> {
|
||||
public constructor Inv</*0*/ 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
|
||||
}
|
||||
|
||||
public/*package*/ open class Test {
|
||||
public/*package*/ constructor Test()
|
||||
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
|
||||
|
||||
// Static members
|
||||
@org.jetbrains.annotations.Nullable public/*package*/ open fun </*0*/ T : kotlin.Any!> foo(/*0*/ x: T!): T?
|
||||
}
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getInv(): Inv<R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class In<in K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getIn(): In<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U) = x
|
||||
fun <E> intersect(vararg x: In<E>): E = null as E
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
intersect(getIn(), getIn())
|
||||
intersect(getIn(), Test.foo(getIn()))
|
||||
intersect(Test.foo(getIn()), Test.foo(getIn()))
|
||||
intersect(Test.foo(getIn()), getIn())
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
intersect(this@build.getIn(), getIn())
|
||||
intersect(getIn(), Test.foo(this@build.getIn()))
|
||||
intersect(Test.foo(this@build.getIn()), Test.foo(getIn()))
|
||||
intersect(Test.foo(getIn()), this@build.getIn())
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
static <T> T foo(T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R1> build(@BuilderInference block: TestInterface<R1>.() -> Unit): R1 = TODO()
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R2> build2(@BuilderInference block: TestInterface<R2>.() -> Unit): R2 = TODO()
|
||||
|
||||
class In<in K>
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
fun get(): R
|
||||
fun getIn(): In<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U) = x
|
||||
fun <E> intersect(vararg x: In<E>): E = null as E
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit("1")
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>intersect(getIn(), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>intersect(getIn(), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>intersect(Test.foo(getIn()), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("TypeVariable(R1)")!>intersect(Test.foo(getIn()), getIn())<!>
|
||||
|
||||
build2 {
|
||||
emit(1)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("{TypeVariable(R1) & TypeVariable(R2)}")!>intersect(this@build.getIn(), getIn())<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("{TypeVariable(R1) & TypeVariable(R2)}")!>intersect(getIn(), Test.foo(this@build.getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("{TypeVariable(R1) & TypeVariable(R2)}")!>intersect(Test.foo(this@build.getIn()), Test.foo(getIn()))<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("{TypeVariable(R1) & TypeVariable(R2)}")!>intersect(Test.foo(getIn()), this@build.getIn())<!>
|
||||
""
|
||||
}
|
||||
""
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R1> build(/*0*/ @kotlin.BuilderInference block: TestInterface<R1>.() -> kotlin.Unit): R1
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R2> build2(/*0*/ @kotlin.BuilderInference block: TestInterface<R2>.() -> kotlin.Unit): R2
|
||||
public fun </*0*/ U> id(/*0*/ x: U): U
|
||||
public fun </*0*/ E> intersect(/*0*/ vararg x: In<E> /*kotlin.Array<out In<E>>*/): E
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class In</*0*/ in K> {
|
||||
public constructor In</*0*/ in 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
|
||||
}
|
||||
|
||||
public/*package*/ open class Test {
|
||||
public/*package*/ constructor Test()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public/*package*/ open fun </*0*/ T : kotlin.Any!> foo(/*0*/ x: T!): T!
|
||||
}
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun get(): R
|
||||
public abstract fun getIn(): In<R>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+4
-1
@@ -16,10 +16,13 @@ interface TestInterface<R> {
|
||||
fun getInv(): Inv<R>
|
||||
}
|
||||
|
||||
fun <U> id(x: U) = x
|
||||
|
||||
fun test() {
|
||||
val ret = build {
|
||||
emit(1)
|
||||
emit("1")
|
||||
get()
|
||||
getInv()
|
||||
""
|
||||
}
|
||||
}
|
||||
+2
-8
@@ -2,14 +2,8 @@ package
|
||||
|
||||
public val test1: kotlin.collections.List<kotlin.Int>
|
||||
public val test2: kotlin.collections.List<kotlin.Int>
|
||||
public val test3: [ERROR : Type for generate {
|
||||
yield(3)
|
||||
yieldBarReturnType(3)
|
||||
}]
|
||||
public val test4: [ERROR : Type for generate {
|
||||
yield(3)
|
||||
barReturnType()
|
||||
}]
|
||||
public val test3: kotlin.collections.List<kotlin.Int>
|
||||
public val test4: kotlin.collections.List<kotlin.Int>
|
||||
public fun </*0*/ S> generate(/*0*/ @kotlin.BuilderInference g: suspend GenericController<S>.() -> kotlin.Unit): kotlin.collections.List<S>
|
||||
|
||||
public final class GenericController</*0*/ T> {
|
||||
|
||||
+1
-3
@@ -1,8 +1,6 @@
|
||||
package
|
||||
|
||||
public val extension: [ERROR : Type for build {
|
||||
extensionAdd("foo")
|
||||
}]
|
||||
public val extension: kotlin.collections.List<kotlin.String>
|
||||
public val member: kotlin.collections.List<kotlin.Int>
|
||||
public val memberWithoutAnn: [ERROR : Type for wrongBuild {
|
||||
add(42)
|
||||
|
||||
+1
-3
@@ -1,8 +1,6 @@
|
||||
package
|
||||
|
||||
public val extension: [ERROR : Type for build {
|
||||
extensionAdd("foo")
|
||||
}]
|
||||
public val extension: kotlin.collections.List<kotlin.String>
|
||||
public val member: kotlin.collections.List<kotlin.Int>
|
||||
public val memberWithoutAnn: [ERROR : Type for wrongBuild {
|
||||
add(42)
|
||||
|
||||
+1
-3
@@ -1,8 +1,6 @@
|
||||
package
|
||||
|
||||
public val extension: [ERROR : Type for generate {
|
||||
extensionYield("foo")
|
||||
}]
|
||||
public val extension: kotlin.collections.List<kotlin.String>
|
||||
public val normal: kotlin.collections.List<kotlin.Int>
|
||||
public val safeExtension: kotlin.collections.List<kotlin.String>
|
||||
public fun </*0*/ S> generate(/*0*/ @kotlin.BuilderInference g: suspend GenericController<S>.() -> kotlin.Unit): kotlin.collections.List<S>
|
||||
|
||||
Vendored
+4
-4
@@ -83,11 +83,11 @@ fun test() {
|
||||
this@a.<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>yield2<!>(1)
|
||||
|
||||
with(this) {
|
||||
yield("")
|
||||
this@with.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>yield<!>("")
|
||||
<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>yield<!>("")
|
||||
this@with.<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>yield<!>("")
|
||||
|
||||
yield2("")
|
||||
this@with.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>yield2<!>("")
|
||||
<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>yield2<!>("")
|
||||
this@with.<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>yield2<!>("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -75,5 +75,5 @@ fun test() {
|
||||
}
|
||||
// TODO: FIR
|
||||
// {AbstractAssert<*, out Any!>! & EnumerableAssert<*, {Comparable<*> & java.io.Serializable!}>!} with unfolded flexible nullability
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("({AbstractAssert<*, out (kotlin.Any..kotlin.Any?)> & EnumerableAssert<*, out ({Comparable<*> & java.io.Serializable}..{Comparable<*>? & java.io.Serializable?})>}..{AbstractAssert<*, out (kotlin.Any..kotlin.Any?)>? & EnumerableAssert<*, out ({Comparable<*> & java.io.Serializable}..{Comparable<*>? & java.io.Serializable?})>?})")!>assertion<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("({AbstractAssert<*, out (Any..Any?)> & EnumerableAssert<*, out ({Comparable<*> & java.io.Serializable}..{Comparable<*>? & java.io.Serializable?})>}..{AbstractAssert<*, out (Any..Any?)>? & EnumerableAssert<*, out ({Comparable<*> & java.io.Serializable}..{Comparable<*>? & java.io.Serializable?})>?})")!>assertion<!>
|
||||
}
|
||||
|
||||
Generated
+58
-6
@@ -12644,12 +12644,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("renderingStubTypes.kt")
|
||||
public void testRenderingStubTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/renderingStubTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
@@ -12697,6 +12691,64 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
public void testSpecialCallsWithLambdas() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class StubTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInStubTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedTypes.kt")
|
||||
public void testCapturedTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperType.kt")
|
||||
public void testCommonSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeContravariant.kt")
|
||||
public void testCommonSuperTypeContravariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeCovariant.kt")
|
||||
public void testCommonSuperTypeCovariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeInvariant.kt")
|
||||
public void testCommonSuperTypeInvariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commonSuperTypeNullable.kt")
|
||||
public void testCommonSuperTypeNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersect.kt")
|
||||
public void testIntersect() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("renderingStubTypes.kt")
|
||||
public void testRenderingStubTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
@@ -478,7 +478,11 @@ object AbstractTypeChecker {
|
||||
)
|
||||
}
|
||||
|
||||
if (subType.isStubType() || superType.isStubType()) return context.isStubTypeEqualsToAnything
|
||||
if (subType.isStubType() && superType.isStubType())
|
||||
return subType.typeConstructor() === superType.typeConstructor()
|
||||
|
||||
if (subType.isStubType() || superType.isStubType() || subType.isStubTypeForVariableInSubtyping() || superType.isStubTypeForVariableInSubtyping())
|
||||
return context.isStubTypeEqualsToAnything
|
||||
|
||||
// superType might be a definitely notNull type (see KT-42824)
|
||||
val superOriginalType = superType.asDefinitelyNotNullType()?.original() ?: superType
|
||||
@@ -742,7 +746,7 @@ object AbstractNullabilityChecker {
|
||||
if (type.isNothing()) return true
|
||||
if (type.isMarkedNullable()) return false
|
||||
|
||||
if (context.isStubTypeEqualsToAnything && type.isStubType()) return true
|
||||
if (context.isStubTypeEqualsToAnything && (type.isStubTypeForVariableInSubtyping() || type.isStubType())) return true
|
||||
|
||||
return areEqualTypeConstructors(type.typeConstructor(), end)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ interface TypeSystemBuiltInsContext {
|
||||
/**
|
||||
* Context that allow construction of types
|
||||
*/
|
||||
interface TypeSystemTypeFactoryContext {
|
||||
interface TypeSystemTypeFactoryContext: TypeSystemBuiltInsContext {
|
||||
fun createFlexibleType(lowerBound: SimpleTypeMarker, upperBound: SimpleTypeMarker): KotlinTypeMarker
|
||||
fun createSimpleType(
|
||||
constructor: TypeConstructorMarker,
|
||||
@@ -169,7 +169,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
): CapturedTypeMarker
|
||||
|
||||
fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker
|
||||
|
||||
fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker
|
||||
|
||||
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
|
||||
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
|
||||
@@ -299,6 +299,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
}
|
||||
|
||||
fun SimpleTypeMarker.isStubType(): Boolean
|
||||
fun SimpleTypeMarker.isStubTypeForVariableInSubtyping(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.asTypeArgument(): TypeArgumentMarker
|
||||
|
||||
|
||||
@@ -288,7 +288,11 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
override fun renderTypeConstructor(typeConstructor: TypeConstructor): String = when (val cd = typeConstructor.declarationDescriptor) {
|
||||
is TypeParameterDescriptor, is ClassDescriptor, is TypeAliasDescriptor -> renderClassifierName(cd)
|
||||
null -> typeConstructor.toString()
|
||||
null -> {
|
||||
if (typeConstructor is IntersectionTypeConstructor) {
|
||||
typeConstructor.makeDebugNameForIntersectionType { if (it is StubType) it.originalTypeVariable else it }
|
||||
} else typeConstructor.toString()
|
||||
}
|
||||
else -> error("Unexpected classifier: " + cd::class.java)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,12 @@ class IntersectionTypeConstructor(typesToIntersect: Collection<KotlinType>) : Ty
|
||||
override fun getBuiltIns(): KotlinBuiltIns =
|
||||
intersectedTypes.iterator().next().constructor.builtIns
|
||||
|
||||
override fun toString(): String =
|
||||
makeDebugNameForIntersectionType(intersectedTypes)
|
||||
override fun toString(): String = makeDebugNameForIntersectionType()
|
||||
|
||||
private fun makeDebugNameForIntersectionType(resultingTypes: Iterable<KotlinType>): String =
|
||||
resultingTypes.sortedBy { it.toString() }.joinToString(separator = " & ", prefix = "{", postfix = "}")
|
||||
fun makeDebugNameForIntersectionType(getProperTypeRelatedToStringify: (KotlinType) -> Any = { it.toString() }): String {
|
||||
return intersectedTypes.sortedBy { getProperTypeRelatedToStringify(it).toString() }
|
||||
.joinToString(separator = " & ", prefix = "{", postfix = "}") { getProperTypeRelatedToStringify(it).toString() }
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
@@ -23,6 +23,17 @@ class StubType(
|
||||
}
|
||||
}
|
||||
|
||||
class StubTypeForTypeVariablesInSubtyping(
|
||||
originalTypeVariable: TypeConstructor,
|
||||
isMarkedNullable: Boolean,
|
||||
constructor: TypeConstructor = ErrorUtils.createErrorTypeConstructor("Constructor for non fixed type: $originalTypeVariable"),
|
||||
memberScope: MemberScope = ErrorUtils.createErrorScope("Scope for non fixed type: $originalTypeVariable")
|
||||
) : AbstractStubType(originalTypeVariable, isMarkedNullable, constructor, memberScope), StubTypeMarker {
|
||||
override fun materialize(newNullability: Boolean): AbstractStubType {
|
||||
return StubTypeForTypeVariablesInSubtyping(originalTypeVariable, newNullability, constructor, memberScope)
|
||||
}
|
||||
}
|
||||
|
||||
// This type is used as a replacement of type variables for provideDelegate resolve
|
||||
class StubTypeForProvideDelegateReceiver(
|
||||
originalTypeVariable: TypeConstructor,
|
||||
@@ -54,7 +65,7 @@ abstract class AbstractStubType(
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "NonFixed: $originalTypeVariable"
|
||||
return "NonFixed: $originalTypeVariable${if (isMarkedNullable) "?" else ""}"
|
||||
}
|
||||
|
||||
@TypeRefinement
|
||||
|
||||
+10
-1
@@ -81,7 +81,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
|
||||
override fun SimpleTypeMarker.isStubType(): Boolean {
|
||||
require(this is SimpleType, this::errorMessage)
|
||||
return this is AbstractStubType
|
||||
return this is StubType || this is StubTypeForProvideDelegateReceiver
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.isStubTypeForVariableInSubtyping(): Boolean {
|
||||
require(this is SimpleType, this::errorMessage)
|
||||
return this is StubTypeForTypeVariablesInSubtyping
|
||||
}
|
||||
|
||||
override fun CapturedTypeMarker.lowerType(): KotlinTypeMarker? {
|
||||
@@ -543,6 +548,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
errorSupportedOnlyInTypeInference()
|
||||
}
|
||||
|
||||
override fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker {
|
||||
errorSupportedOnlyInTypeInference()
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.isSpecial(): Boolean {
|
||||
require(this is KotlinType)
|
||||
return this is TypeUtils.SpecialType
|
||||
|
||||
@@ -136,6 +136,8 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
||||
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound), builtIns)
|
||||
}
|
||||
|
||||
override fun toString() = "($lowerBound..$upperBound)"
|
||||
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType = KotlinTypeFactory.flexibleType(
|
||||
lowerBound.makeNullableAsSpecified(newNullability),
|
||||
upperBound.makeNullableAsSpecified(newNullability)
|
||||
|
||||
Reference in New Issue
Block a user