From 65380f4eb43b9832070f9c8697a0319ed7742d4a Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 23 Apr 2019 13:46:49 +0300 Subject: [PATCH] [NI] Remove captured type approximation in type arguments of resolved call --- .../resolve/calls/tower/KotlinToResolvedCallTransformer.kt | 2 +- .../src/org/jetbrains/kotlin/types/TypeApproximator.kt | 7 +++++++ .../tests/generics/tpAsReified/CapturedAsReified.kt | 2 +- .../intentions/InsertExplicitTypeArgumentsIntention.kt | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 96fdfbfdb16..0780cba13b0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -674,7 +674,7 @@ class NewResolvedCallImpl( typeArguments = resolvedCallAtom.substitutor.freshVariables.map { val substituted = (substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType) TypeApproximator(substituted.constructor.builtIns) - .approximateToSuperType(substituted, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation) + .approximateToSuperType(substituted, TypeApproximatorConfiguration.IntegerLiteralsTypesApproximation) ?: substituted } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt index 7f85dc0fb01..606e7cf7534 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt @@ -90,6 +90,13 @@ open class TypeApproximatorConfiguration { object CapturedAndIntegerLiteralsTypesApproximation : TypeApproximatorConfiguration.AbstractCapturedTypesApproximation(FROM_EXPRESSION) { override val integerLiteralType: Boolean get() = true } + object IntegerLiteralsTypesApproximation : TypeApproximatorConfiguration.AllFlexibleSameValue() { + override val integerLiteralType: Boolean get() = true + override val allFlexible: Boolean get() = true + override val intersection get() = ALLOWED + override val typeVariable: (TypeVariableTypeConstructor) -> Boolean get() = { true } + override val capturedType: (NewCapturedType) -> Boolean get() = { true } + } } diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt index 71199d31867..7df95fbe8ed 100644 --- a/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/CapturedAsReified.kt @@ -5,5 +5,5 @@ class A inline fun foo(x: A) {} fun test(x: A) { - foo(x) + foo(x) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt index 541554f9e07..1655e351050 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InsertExplicitTypeArgumentsIntention.kt @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.inference.CapturedType import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.checker.NewCapturedType class InsertExplicitTypeArgumentsIntention : SelfTargetingRangeIntention(KtCallExpression::class.java, "Add explicit type arguments"), LowPriorityAction { @@ -47,7 +48,7 @@ class InsertExplicitTypeArgumentsIntention : val resolvedCall = element.getResolvedCall(bindingContext) ?: return false val typeArgs = resolvedCall.typeArguments - return typeArgs.isNotEmpty() && typeArgs.values.none { ErrorUtils.containsErrorType(it) || it is CapturedType } + return typeArgs.isNotEmpty() && typeArgs.values.none { ErrorUtils.containsErrorType(it) || it is CapturedType || it is NewCapturedType } } fun applyTo(element: KtCallElement, shortenReferences: Boolean = true) {