Put the type inference on calls with self types under the compiler flag
This commit is contained in:
+51
-13
@@ -14185,22 +14185,60 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class DisabledInferenceOnSelfTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInDisabledInferenceOnSelfTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/writerAppenderExampleRecursive.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class EnabledInferenceOnSelfTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInEnabledInferenceOnSelfTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/writerAppenderExampleRecursive.kt");
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+51
-13
@@ -14185,22 +14185,60 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class DisabledInferenceOnSelfTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInDisabledInferenceOnSelfTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/writerAppenderExampleRecursive.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class EnabledInferenceOnSelfTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInEnabledInferenceOnSelfTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/writerAppenderExampleRecursive.kt");
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
||||
approximator,
|
||||
session.languageVersionSettings,
|
||||
)
|
||||
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
|
||||
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle, session.languageVersionSettings)
|
||||
val variableFixationFinder = VariableFixationFinder(trivialConstraintTypeInferenceOracle, session.languageVersionSettings)
|
||||
val postponedArgumentInputTypesResolver =
|
||||
PostponedArgumentInputTypesResolver(resultTypeResolver, variableFixationFinder, ConeConstraintSystemUtilContext)
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import kotlin.math.max
|
||||
class ConstraintInjector(
|
||||
val constraintIncorporator: ConstraintIncorporator,
|
||||
val typeApproximator: AbstractTypeApproximator,
|
||||
private val languageVersionSettings: LanguageVersionSettings,
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
) {
|
||||
private val ALLOWED_DEPTH_DELTA_FOR_INCORPORATION = 1
|
||||
|
||||
|
||||
+8
-2
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.TypeVariableDirectionCalculator.ResolveDirection
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.hasDeclaredUpperBoundSelfTypes
|
||||
@@ -16,7 +18,8 @@ import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
class ResultTypeResolver(
|
||||
val typeApproximator: AbstractTypeApproximator,
|
||||
val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle
|
||||
val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
interface Context : TypeSystemInferenceExtensionContext {
|
||||
fun isProperType(type: KotlinTypeMarker): Boolean
|
||||
@@ -211,8 +214,11 @@ class ResultTypeResolver(
|
||||
}
|
||||
|
||||
private fun Context.findSuperType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? {
|
||||
val isTypeInferenceForSelfTypesSupported =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.TypeInferenceOnCallsWithSelfTypes)
|
||||
val upperConstraints = variableWithConstraints.constraints.filter {
|
||||
it.kind == ConstraintKind.UPPER && (hasDeclaredUpperBoundSelfTypes(it) || isProperTypeForFixation(it.type))
|
||||
it.kind == ConstraintKind.UPPER
|
||||
&& ((isTypeInferenceForSelfTypesSupported && hasDeclaredUpperBoundSelfTypes(it)) || isProperTypeForFixation(it.type))
|
||||
}
|
||||
if (upperConstraints.isNotEmpty()) {
|
||||
val intersectionUpperType = intersectTypes(upperConstraints.map { it.type })
|
||||
|
||||
+5
-1
@@ -57,13 +57,17 @@ class VariableFixationFinder(
|
||||
private val inferenceCompatibilityModeEnabled: Boolean
|
||||
get() = languageVersionSettings.supportsFeature(LanguageFeature.InferenceCompatibility)
|
||||
|
||||
private val isTypeInferenceForSelfTypesSupported: Boolean
|
||||
get() = languageVersionSettings.supportsFeature(LanguageFeature.TypeInferenceOnCallsWithSelfTypes)
|
||||
|
||||
private fun Context.getTypeVariableReadiness(
|
||||
variable: TypeConstructorMarker,
|
||||
dependencyProvider: TypeVariableDependencyInformationProvider,
|
||||
): TypeVariableFixationReadiness = when {
|
||||
!notFixedTypeVariables.contains(variable) ||
|
||||
dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN
|
||||
hasDeclaredUpperBoundSelfTypes(variable) -> TypeVariableFixationReadiness.READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES
|
||||
isTypeInferenceForSelfTypesSupported && hasDeclaredUpperBoundSelfTypes(variable) ->
|
||||
TypeVariableFixationReadiness.READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES
|
||||
!variableHasProperArgumentConstraints(variable) -> TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT
|
||||
hasDependencyToOtherTypeVariables(variable) -> TypeVariableFixationReadiness.WITH_COMPLEX_DEPENDENCY
|
||||
variableHasTrivialOrNonProperConstraints(variable) -> TypeVariableFixationReadiness.WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS
|
||||
|
||||
+3
-1
@@ -406,7 +406,9 @@ abstract class AbstractTypeApproximator(
|
||||
|
||||
val argumentTypeConstructor = argument.getType().typeConstructor()
|
||||
|
||||
if (argumentTypeConstructor is TypeVariableTypeConstructorMarker && conf.selfTypesWithTypeVariablesToCapturedStarProjection) {
|
||||
val isTypeInferenceForSelfTypesSupported =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.TypeInferenceOnCallsWithSelfTypes)
|
||||
if (isTypeInferenceForSelfTypesSupported && argumentTypeConstructor is TypeVariableTypeConstructorMarker && conf.selfTypesWithTypeVariablesToCapturedStarProjection) {
|
||||
// If we have Self<TypeVariable(T)> where T is bounded by Self<T>, we approximate it to CapturedType(*) to satisfy constraints
|
||||
if (argumentTypeConstructor.typeParameter?.hasRecursiveBounds(type.typeConstructor()) == true) {
|
||||
return createCapturedStarProjectionForSelfType(argumentTypeConstructor, type)
|
||||
|
||||
+11
-3
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.EmptySubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
@@ -20,7 +22,10 @@ import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : TypeSystemInferenceExtensionContextDelegate,
|
||||
class ClassicTypeSystemContextForCS(
|
||||
override val builtIns: KotlinBuiltIns,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
) : TypeSystemInferenceExtensionContextDelegate,
|
||||
ClassicTypeSystemContext,
|
||||
BuiltInsProvider {
|
||||
|
||||
@@ -43,13 +48,16 @@ class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : Typ
|
||||
require(lowerType is UnwrappedType?, lowerType::errorMessage)
|
||||
require(constructorProjection is TypeProjectionBase, constructorProjection::errorMessage)
|
||||
|
||||
val isTypeInferenceForSelfTypesSupported =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.TypeInferenceOnCallsWithSelfTypes)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val newCapturedTypeConstructor = NewCapturedTypeConstructor(
|
||||
constructorProjection,
|
||||
constructorSupertypes as List<UnwrappedType>
|
||||
)
|
||||
return NewCapturedType(
|
||||
captureStatus,
|
||||
if (isTypeInferenceForSelfTypesSupported) captureStatus else CaptureStatus.FOR_INCORPORATION,
|
||||
newCapturedTypeConstructor,
|
||||
lowerType = lowerType
|
||||
)
|
||||
@@ -109,5 +117,5 @@ fun NewConstraintSystemImpl(
|
||||
constraintInjector: ConstraintInjector,
|
||||
builtIns: KotlinBuiltIns
|
||||
): NewConstraintSystemImpl {
|
||||
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns))
|
||||
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, constraintInjector.languageVersionSettings))
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
|
||||
class SimpleConstraintSystemImpl(constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns) : SimpleConstraintSystem {
|
||||
val system = NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns))
|
||||
val system = NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, constraintInjector.languageVersionSettings))
|
||||
val csBuilder: ConstraintSystemBuilder =
|
||||
system.getBuilder()
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextFor
|
||||
class TypeApproximator(
|
||||
builtIns: KotlinBuiltIns,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns), languageVersionSettings) {
|
||||
) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns, languageVersionSettings), languageVersionSettings) {
|
||||
fun approximateDeclarationType(baseType: KotlinType, local: Boolean): UnwrappedType {
|
||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return baseType.unwrap()
|
||||
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: -TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
class Builder<B : Builder<B>> {
|
||||
fun <T : B> test(): T = TODO()
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: -TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
class Builder<B : Builder<B>> {
|
||||
fun <T : B> test(): T = TODO()
|
||||
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun testStar(builder: Builder<*>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>builder.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test<!>()<!>
|
||||
|
||||
builder
|
||||
.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test<!>()
|
||||
.<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!>()
|
||||
}
|
||||
|
||||
fun <K : Builder<K>> testTypeParam(builder: Builder<K>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>builder.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test<!>()<!>
|
||||
|
||||
builder
|
||||
.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test<!>()
|
||||
.<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!>()
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: -TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
interface BodySpec<B, S : BodySpec<B, S>> {
|
||||
fun <T : S> isEqualTo(expected: B): T
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: -TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
interface BodySpec<B, S : BodySpec<B, S>> {
|
||||
fun <T : S> isEqualTo(expected: B): T
|
||||
}
|
||||
|
||||
fun test(b: BodySpec<String, *>) {
|
||||
val x = b.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>isEqualTo<!>("")
|
||||
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, DEBUG_INFO_EXPRESSION_TYPE("[ERROR : Type for b.isEqualTo("")]")!>x<!>
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: -TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
fun test() {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("WriterAppender.Builder1<*>")!>WriterAppender.newBuilder()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("WriterAppender.Builder1<out WriterAppender.Builder1<*>>")!>WriterAppender.Builder1()<!>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !LANGUAGE: -TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
fun test() {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>WriterAppender.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>newBuilder<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>WriterAppender.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Builder1<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>WriterAppender.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>intersectTwoSelfTypes<!>()<!>
|
||||
}
|
||||
|
||||
object WriterAppender {
|
||||
interface Builder2<K : Builder2<K>>
|
||||
|
||||
class Builder1<B : Builder1<B>> {
|
||||
fun asBuilder(): B {
|
||||
return this <!UNCHECKED_CAST!>as B<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun <B : Builder1<B>> newBuilder(): B {
|
||||
return Builder1<B>().asBuilder()
|
||||
}
|
||||
|
||||
fun <B> intersectTwoSelfTypes(): B where B : Builder1<B>, B: Builder2<B> {
|
||||
return Builder1<B>().asBuilder()
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
class Builder<B : Builder<B>> {
|
||||
fun <T : B> test(): T = TODO()
|
||||
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun testStar(builder: Builder<*>) {
|
||||
builder.test()
|
||||
|
||||
builder
|
||||
.test()
|
||||
.foo()
|
||||
}
|
||||
|
||||
fun <K : Builder<K>> testTypeParam(builder: Builder<K>) {
|
||||
builder.test()
|
||||
|
||||
builder
|
||||
.test()
|
||||
.foo()
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
class Builder<B : Builder<B>> {
|
||||
fun <T : B> test(): T = TODO()
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
public fun testStar(/*0*/ builder: Builder<*>): kotlin.Unit
|
||||
public fun </*0*/ K : Builder<K>> testTypeParam(/*0*/ builder: Builder<K>): kotlin.Unit
|
||||
|
||||
public final class Builder</*0*/ B : Builder<B>> {
|
||||
public constructor Builder</*0*/ B : Builder<B>>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun </*0*/ T : B> test(): T
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
interface BodySpec<B, S : BodySpec<B, S>> {
|
||||
fun <T : S> isEqualTo(expected: B): T
|
||||
}
|
||||
|
||||
fun test(b: BodySpec<String, *>) {
|
||||
val x = b.isEqualTo("")
|
||||
x
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
interface BodySpec<B, S : BodySpec<B, S>> {
|
||||
fun <T : S> isEqualTo(expected: B): T
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ b: BodySpec<kotlin.String, *>): kotlin.Unit
|
||||
|
||||
public interface BodySpec</*0*/ B, /*1*/ S : BodySpec<B, S>> {
|
||||
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 abstract fun </*0*/ T : S> isEqualTo(/*0*/ expected: B): T
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
fun test() {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("WriterAppender.Builder1<*>")!>WriterAppender.newBuilder()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("WriterAppender.Builder1<out WriterAppender.Builder1<*>>")!>WriterAppender.Builder1()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("{Builder1<*> & Builder2<*>}")!>WriterAppender.intersectTwoSelfTypes()<!>
|
||||
}
|
||||
|
||||
object WriterAppender {
|
||||
interface Builder2<K : Builder2<K>>
|
||||
|
||||
class Builder1<B : Builder1<B>> {
|
||||
fun asBuilder(): B {
|
||||
return this <!UNCHECKED_CAST!>as B<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun <B : Builder1<B>> newBuilder(): B {
|
||||
return Builder1<B>().asBuilder()
|
||||
}
|
||||
|
||||
fun <B> intersectTwoSelfTypes(): B where B : Builder1<B>, B: Builder2<B> {
|
||||
return Builder1<B>().asBuilder()
|
||||
}
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: +TypeInferenceOnCallsWithSelfTypes
|
||||
|
||||
fun test() {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("WriterAppender.Builder1<*>")!>WriterAppender.newBuilder()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("WriterAppender.Builder1<out WriterAppender.Builder1<*>>")!>WriterAppender.Builder1()<!>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public object WriterAppender {
|
||||
private constructor WriterAppender()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun </*0*/ B : WriterAppender.Builder1<B>> intersectTwoSelfTypes(): B where B : WriterAppender.Builder2<B>
|
||||
public final fun </*0*/ B : WriterAppender.Builder1<B>> newBuilder(): B
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public final class Builder1</*0*/ B : WriterAppender.Builder1<B>> {
|
||||
public constructor Builder1</*0*/ B : WriterAppender.Builder1<B>>()
|
||||
public final fun asBuilder(): B
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Builder2</*0*/ K : WriterAppender.Builder2<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
|
||||
}
|
||||
}
|
||||
Generated
+51
-13
@@ -14191,22 +14191,60 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class DisabledInferenceOnSelfTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInDisabledInferenceOnSelfTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/disabledInferenceOnSelfTypes/writerAppenderExampleRecursive.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class EnabledInferenceOnSelfTypes {
|
||||
@Test
|
||||
public void testAllFilesPresentInEnabledInferenceOnSelfTypes() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/writerAppenderExampleRecursive.kt");
|
||||
@Test
|
||||
@TestMetadata("basicInferenceForImplicitSelfType.kt")
|
||||
public void testBasicInferenceForImplicitSelfType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/basicInferenceForImplicitSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("recursiveTypeWithTwoTypeParams.kt")
|
||||
public void testRecursiveTypeWithTwoTypeParams() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/recursiveTypeWithTwoTypeParams.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("writerAppenderExampleRecursive.kt")
|
||||
public void testWriterAppenderExampleRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +213,7 @@ enum class LanguageFeature(
|
||||
ClassTypeParameterAnnotations(KOTLIN_1_6),
|
||||
SafeCallsAreAlwaysNullable(KOTLIN_1_6),
|
||||
ProhibitSimplificationOfNonTrivialConstBooleanExpressions(KOTLIN_1_6),
|
||||
TypeInferenceOnCallsWithSelfTypes(KOTLIN_1_6),
|
||||
|
||||
// Temporarily disabled, see KT-27084/KT-22379
|
||||
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
|
||||
|
||||
Reference in New Issue
Block a user