diff --git a/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.fir.txt b/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.fir.txt index eda23012129..3fe6693c865 100644 --- a/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.fir.txt @@ -7,7 +7,7 @@ FILE: typeAliasWithNotNullBound.kt } public final typealias MyAlias = R|Inv| public final fun foo(p: R|MyAlias|): R|kotlin/Unit| { - R|/bar|(R|/p|).R|kotlin/CharSequence.length| + R|/bar|(R|/p|).R|kotlin/CharSequence.length| } public final fun bar(x: R|Inv|): R|T| { ^bar R|kotlin/TODO|() diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/capturedTypeForJavaTypeParameter.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/capturedTypeForJavaTypeParameter.fir.txt index 32d1c65669b..05d95fd8eca 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/capturedTypeForJavaTypeParameter.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/capturedTypeForJavaTypeParameter.fir.txt @@ -4,5 +4,5 @@ FILE: main.kt public final fun foo(b: R|B|): R|kotlin/Unit| { } public final fun main(b: R|B<*>|): R|kotlin/Unit| { - R|/foo||>(R|/b|) + R|/foo|(R|/b|) } diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.fir.txt index 2b8a279d102..9b72c3d8dfc 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.fir.txt @@ -5,7 +5,7 @@ FILE: kt40131.kt } public final val |> R|T|.myJava1: R|java/lang/Class<*>| public get(): R|java/lang/Class<*>| { - ^ this@R|/myJava1|.R|/javaImpl| + ^ this@R|/myJava1|.R|/javaImpl| } public final val |> R|T|.myJava2: R|java/lang/Class| public get(): R|java/lang/Class| { diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/receiverWithCapturedType.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/receiverWithCapturedType.fir.txt index 462119edaac..ada3dba49ae 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/receiverWithCapturedType.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/receiverWithCapturedType.fir.txt @@ -15,19 +15,19 @@ FILE: receiverWithCapturedType.kt ^updateD R|/d| } public final fun test_1_1(resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { - R|/resolvedCall|.R|/getParameterForArgument|() + R|/resolvedCall|.R|/getParameterForArgument|() } public final fun test_1_2(resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { - R|/resolvedCall|.R|/getParameterForArgument|() + R|/resolvedCall|.R|/getParameterForArgument|() } public final fun test_1_3(resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { R|/resolvedCall|.R|/getParameterForArgument|() } public final fun test_2_1(resolvedCall: R|ResolvedCall|, d: R|CallableDescriptor|): R|kotlin/Unit| { - lval x: R|CallableDescriptor| = R|/resolvedCall|.#(R|/d|) + lval x: R|CallableDescriptor| = R|/resolvedCall|.#(R|/d|) } public final fun test_2_2(resolvedCall: R|ResolvedCall|, d: R|CallableDescriptor|): R|kotlin/Unit| { - lval x: R|CallableDescriptor| = R|/resolvedCall|.R|/updateD|(R|/d|) + lval x: R|CallableDescriptor| = R|/resolvedCall|.R|/updateD|(R|/d|) } public final fun test_2_3(resolvedCall: R|ResolvedCall|, d: R|CallableDescriptor|): R|kotlin/Unit| { lval x: R|CallableDescriptor| = R|/resolvedCall|.R|/updateD|(R|/d|) diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/simpleCapturedTypes.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/simpleCapturedTypes.fir.txt index ecf5def9bd4..a795f099ae1 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/simpleCapturedTypes.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/simpleCapturedTypes.fir.txt @@ -19,10 +19,10 @@ FILE: simpleCapturedTypes.kt ^ this@R|/idP| } private final fun getSetterInfos(kc: R|KC|): R|kotlin/Unit| { - R|/id|(R|/kc|).R|SubstitutionOverride|.R|/Ann.foo|() - R|/kc|.R|/idR|().R|SubstitutionOverride|.R|/Ann.foo|() - R|/kc|.R|/idP|.R|SubstitutionOverride|.R|/Ann.foo|() - lval x1: R|KC| = R|/id|(R|/kc|) - lval x2: R|KC| = R|/kc|.R|/idR|() - lval x3: R|KC| = R|/kc|.R|/idP| + R|/id|(R|/kc|).R|SubstitutionOverride|.R|/Ann.foo|() + R|/kc|.R|/idR|().R|SubstitutionOverride|.R|/Ann.foo|() + R|/kc|.R|/idP|.R|SubstitutionOverride|.R|/Ann.foo|() + lval x1: R|KC| = R|/id|(R|/kc|) + lval x2: R|KC| = R|/kc|.R|/idR|() + lval x3: R|KC| = R|/kc|.R|/idP| } diff --git a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt index 3210aeec2a9..22176c0501c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.fir.txt @@ -40,8 +40,8 @@ FILE: referenceToExtension.kt } public final fun test_2(): R|kotlin/Unit| { - lval extensionValRef: R|kotlin/reflect/KProperty1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionVal| - lval extensionFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionFun| + lval extensionValRef: R|kotlin/reflect/KProperty1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionVal| + lval extensionFunRef: R|@ExtensionFunctionType kotlin/reflect/KFunction1, GenericTest.A>| = Q|GenericTest.B|::R|/GenericTest.extensionFun| } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/LoggerInstance.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/LoggerInstance.fir.txt index 6725333eb56..7420d1f5c54 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/LoggerInstance.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/LoggerInstance.fir.txt @@ -7,7 +7,7 @@ FILE: test.kt super() } - private final val klass: R|java/lang/Class| = (this@R|/MyTest|).R|kotlin/jvm/java| + private final val klass: R|java/lang/Class| = (this@R|/MyTest|).R|kotlin/jvm/java| private get(): R|java/lang/Class| private final val logger: R|ft| = Q|Logger|.R|/Logger.getInstance|(this@R|/MyTest|.R|/MyTest.klass|) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/capturedFlexible.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/capturedFlexible.fir.txt index ca4b6e46110..0a76ccf0668 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/capturedFlexible.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/capturedFlexible.fir.txt @@ -1,4 +1,4 @@ FILE: capturedFlexible.kt public final fun foo(z: R|java/util/zip/ZipFile|): R|kotlin/Unit| { - R|/z|.R|java/util/zip/ZipFile.entries|().R|kotlin/sequences/asSequence||>() + R|/z|.R|java/util/zip/ZipFile.entries|().R|kotlin/sequences/asSequence|)|>() } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt index fa41aca2f26..e53a5f2bfb7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt @@ -135,14 +135,12 @@ class Fir2IrTypeConverter( is ConeCapturedType -> { val cached = capturedTypeCache[this] if (cached == null) { - val irType = lowerType?.toIrType(typeContext) ?: run { - capturedTypeCache[this] = errorTypeForCapturedTypeStub - val supertypes = constructor.supertypes!! - val approximation = supertypes.find { - it == (constructor.projection as? ConeKotlinTypeProjection)?.type - } ?: supertypes.first() - approximation.toIrType(typeContext) - } + capturedTypeCache[this] = errorTypeForCapturedTypeStub + val supertypes = constructor.supertypes!! + val approximation = supertypes.find { + it == (constructor.projection as? ConeKotlinTypeProjection)?.type + } ?: supertypes.first() + val irType = approximation.toIrType(typeContext) capturedTypeCache[this] = irType irType } else { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 2efe77f427c..8557148fa1c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -504,7 +504,7 @@ class FirCallCompletionResultsWriterTransformer( .map { finalSubstitutor.substituteOrSelf(it).let { substitutedType -> typeApproximator.approximateToSuperType( - substitutedType, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference, + substitutedType, TypeApproximatorConfiguration.TypeArgumentApproximation, ) ?: substitutedType } } diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt index 4887991b41c..9622c559f02 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt @@ -53,14 +53,14 @@ open class TypeApproximatorConfiguration { override val intersectionTypesInContravariantPositions: Boolean get() = true } - abstract class AbstractCapturedTypesApproximation(val approximatedCapturedStatus: CaptureStatus) : + sealed class AbstractCapturedTypesApproximation(val approximatedCapturedStatus: CaptureStatus?) : AllFlexibleSameValue() { override val allFlexible: Boolean get() = true override val errorType: Boolean get() = true // i.e. will be approximated only approximatedCapturedStatus captured types override fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean = - type.captureStatus(ctx) == approximatedCapturedStatus + approximatedCapturedStatus != null && type.captureStatus(ctx) == approximatedCapturedStatus override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED override val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean get() = { true } @@ -79,6 +79,11 @@ open class TypeApproximatorConfiguration { override val intersectionTypesInContravariantPositions: Boolean get() = true } + object TypeArgumentApproximation : AbstractCapturedTypesApproximation(null) { + override val integerLiteralType: Boolean get() = true + override val intersectionTypesInContravariantPositions: Boolean get() = true + } + object IntegerLiteralsTypesApproximation : AllFlexibleSameValue() { override val integerLiteralType: Boolean get() = true override val allFlexible: Boolean get() = true diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt deleted file mode 100644 index 8921ee1031c..00000000000 --- a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -class A - -inline fun foo(x: A) {} - -fun test(x: A) { - foo(x) -} diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt index 97b84e5fdb2..c2af0d81742 100644 --- a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER class A