[NI] Propagate known type substitutor to resolution part
This commit fixes 'functionNtoStringGeneric' and 'superConstructor'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,6 +73,7 @@ class KotlinCallResolver(
|
||||
it.dispatchReceiver?.let { ReceiverExpressionKotlinCallArgument(it) },
|
||||
null,
|
||||
it.descriptor,
|
||||
it.knownTypeParametersResultingSubstitutor,
|
||||
listOf()
|
||||
)
|
||||
}
|
||||
|
||||
+11
-2
@@ -22,13 +22,15 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ExplicitTypeParameterConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.KnownTypeParameterConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.RUNTIME_ERROR
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
@@ -119,7 +121,7 @@ internal object CreateDescriptorWithFreshTypeVariables : ResolutionPart {
|
||||
}
|
||||
|
||||
// optimization
|
||||
if (typeArgumentMappingByOriginal == NoExplicitArguments) {
|
||||
if (typeArgumentMappingByOriginal == NoExplicitArguments && knownTypeParametersResultingSubstitutor == null) {
|
||||
descriptorWithFreshTypes = candidateDescriptor.substitute(toFreshVariables)
|
||||
csBuilder.simplify().let { assert(it.isEmpty) { "Substitutor should be empty: $it, call: $kotlinCall" } }
|
||||
return emptyList()
|
||||
@@ -128,6 +130,13 @@ internal object CreateDescriptorWithFreshTypeVariables : ResolutionPart {
|
||||
val typeParameters = candidateDescriptor.typeParameters
|
||||
for (index in typeParameters.indices) {
|
||||
val typeParameter = typeParameters[index]
|
||||
val knownTypeArgument = knownTypeParametersResultingSubstitutor?.substitute(typeParameter.defaultType)
|
||||
if (knownTypeArgument != null) {
|
||||
val freshVariable = toFreshVariables.freshVariables[index]
|
||||
csBuilder.addEqualityConstraint(freshVariable.defaultType, knownTypeArgument.unwrap(), KnownTypeParameterConstraintPosition(knownTypeArgument))
|
||||
continue
|
||||
}
|
||||
|
||||
val typeArgument = typeArgumentMappingByOriginal.getTypeArgument(typeParameter)
|
||||
|
||||
if (typeArgument is SimpleTypeArgument) {
|
||||
|
||||
+5
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
|
||||
@@ -39,6 +40,9 @@ class ArgumentConstraintPosition(val argument: KotlinCallArgument) : ConstraintP
|
||||
class FixVariableConstraintPosition(val variable: NewTypeVariable) : ConstraintPosition() {
|
||||
override fun toString() = "Fix variable $variable"
|
||||
}
|
||||
class KnownTypeParameterConstraintPosition(val typeArgument: KotlinType) : ConstraintPosition() {
|
||||
override fun toString() = "TypeArgument $typeArgument"
|
||||
}
|
||||
|
||||
class IncorporationConstraintPosition(val from: ConstraintPosition, val initialConstraint: InitialConstraint) : ConstraintPosition() {
|
||||
override fun toString() = "Incorporate $initialConstraint from position $from"
|
||||
|
||||
+1
-3
@@ -18,8 +18,6 @@ package org.jetbrains.kotlin.resolve.calls.model
|
||||
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckArguments
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
|
||||
@@ -78,7 +76,7 @@ class SimpleCandidateFactory(val callContext: KotlinCallContext, val kotlinCall:
|
||||
}
|
||||
|
||||
return SimpleKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver,
|
||||
towerCandidate.descriptor, towerCandidate.diagnostics)
|
||||
towerCandidate.descriptor, null, towerCandidate.diagnostics)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.Candidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateStatus
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import java.util.*
|
||||
|
||||
@@ -111,6 +112,7 @@ open class SimpleKotlinResolutionCandidate(
|
||||
val dispatchReceiverArgument: SimpleKotlinCallArgument?,
|
||||
val extensionReceiver: SimpleKotlinCallArgument?,
|
||||
val candidateDescriptor: CallableDescriptor,
|
||||
val knownTypeParametersResultingSubstitutor: TypeSubstitutor?,
|
||||
initialDiagnostics: Collection<KotlinCallDiagnostic>
|
||||
) : AbstractSimpleKotlinResolutionCandidate(NewConstraintSystemImpl(callContext.constraintInjector, callContext.resultTypeResolver), initialDiagnostics) {
|
||||
val csBuilder: ConstraintSystemBuilder get() = constraintSystem.getBuilder()
|
||||
@@ -139,7 +141,7 @@ class ErrorKotlinResolutionCandidate(
|
||||
dispatchReceiverArgument: SimpleKotlinCallArgument?,
|
||||
extensionReceiver: SimpleKotlinCallArgument?,
|
||||
candidateDescriptor: CallableDescriptor
|
||||
) : SimpleKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchReceiverArgument, extensionReceiver, candidateDescriptor, listOf()) {
|
||||
) : SimpleKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchReceiverArgument, extensionReceiver, candidateDescriptor, null, listOf()) {
|
||||
override val resolutionSequence: List<ResolutionPart> get() = emptyList()
|
||||
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user