[NI] Fix trace manipulations for builder inference and ::-expressions

For a class literal Type::class we are resolving Type as a constructor,
 getting all diagnostics (about missing arguments, for example) and then
 just not committing this trace with errors

 #KT-37626 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-03-24 02:44:00 +03:00
parent 6213680604
commit 38a719cb22
13 changed files with 181 additions and 4 deletions
@@ -9,7 +9,13 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.MissingSupertypesResolver
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
@@ -25,7 +31,10 @@ import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.StubType
import org.jetbrains.kotlin.types.TypeApproximator
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.typeUtil.contains
@@ -110,10 +119,24 @@ class CoroutineInferenceSession(
}
private fun skipCall(callInfo: SingleCallResolutionResult): Boolean {
val descriptor = callInfo.resultCallAtom.candidateDescriptor
// FakeCallableDescriptorForObject can't introduce new information for inference,
// so it's safe to complete it fully
val descriptor = callInfo.resultCallAtom.candidateDescriptor
return descriptor is FakeCallableDescriptorForObject
if (descriptor is FakeCallableDescriptorForObject) return true
// In this case temporary trace isn't committed during resolve of expressions like A::class, see resolveDoubleColonLHS
if (!DescriptorUtils.isObject(descriptor) && isInLHSOfDoubleColonExpression(callInfo)) return true
return false
}
private fun isInLHSOfDoubleColonExpression(callInfo: SingleCallResolutionResult): Boolean {
val callElement = callInfo.resultCallAtom.atom.psiKotlinCall.psiCall.callElement
val lhs = callElement.getParentOfType<KtDoubleColonExpression>(strict = false)?.lhs
if (lhs !is KtReferenceExpression && lhs !is KtDotQualifiedExpression) return false
return lhs.isAncestor(callElement)
}
override fun currentConstraintSystem(): ConstraintStorage {