[NI] Resolve collection literals arguments as postponed ones

This commit is contained in:
Mikhail Zarechenskiy
2017-06-07 16:17:29 +03:00
parent c0c94910e2
commit bc2a8555a3
12 changed files with 78 additions and 17 deletions
@@ -194,4 +194,16 @@ class KotlinResolutionCallbacksImpl(
doubleColonExpressionResolver.checkReferenceIsToAllowedMember(callableCandidate.candidate, topLevelCallContext.trace, callableReferenceExpression)
}
override fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralArgument) {
val psiCallArgument = collectionLiteralArgument.argument.psiCallArgument as CollectionLiteralKotlinCallArgumentImpl
val context = psiCallArgument.outerCallContext
val actualContext = context
.replaceBindingTrace(trace)
.replaceExpectedType(collectionLiteralArgument.expectedType)
.replaceContextDependency(ContextDependency.INDEPENDENT)
expressionTypingServices.getTypeInfo(psiCallArgument.collectionLiteralExpression, actualContext)
}
}
@@ -115,6 +115,17 @@ class CallableReferenceKotlinCallArgumentImpl(
override val rhsName: Name
) : CallableReferenceKotlinCallArgument, PSIKotlinCallArgument()
class CollectionLiteralKotlinCallArgumentImpl(
override val valueArgument: ValueArgument,
override val argumentName: Name?,
override val dataFlowInfoBeforeThisArgument: DataFlowInfo,
override val dataFlowInfoAfterThisArgument: DataFlowInfo,
val collectionLiteralExpression: KtCollectionLiteralExpression,
val outerCallContext: BasicCallResolutionContext
) : CollectionLiteralKotlinCallArgument, PSIKotlinCallArgument() {
override val isSpread: Boolean get() = valueArgument.getSpreadElement() != null
}
class SubKotlinCallArgumentImpl(
override val valueArgument: ValueArgument,
override val dataFlowInfoBeforeThisArgument: DataFlowInfo,
@@ -510,6 +510,11 @@ class PSICallResolver(
return lambdaArgument
}
if (ktExpression is KtCollectionLiteralExpression) {
return CollectionLiteralKotlinCallArgumentImpl(
valueArgument, argumentName, startDataFlowInfo, startDataFlowInfo, ktExpression, outerCallContext)
}
val context = outerCallContext.replaceContextDependency(ContextDependency.DEPENDENT)
.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceDataFlowInfo(startDataFlowInfo)
@@ -78,6 +78,7 @@ internal object CheckArguments : ResolutionPart {
checkCallableExpectedType(csBuilder, argument, expectedType)
}
}
is CollectionLiteralKotlinCallArgument -> processCollectionLiteralArgument(kotlinCall, csBuilder, argument, expectedType)
else -> error("Incorrect argument type: $argument, ${argument.javaClass.canonicalName}.")
}
}
@@ -180,6 +181,16 @@ internal object CheckArguments : ResolutionPart {
return null
}
fun processCollectionLiteralArgument(
kotlinCall: KotlinCall,
csBuilder: ConstraintSystemBuilder,
collectionLiteralArgument: CollectionLiteralKotlinCallArgument,
expectedType: UnwrappedType
): KotlinCallDiagnostic? {
csBuilder.addCollectionLiteralArgument(ResolvedCollectionLiteralArgument(kotlinCall, collectionLiteralArgument, expectedType))
return null
}
}
internal fun checkExpressionArgument(
@@ -39,4 +39,5 @@ interface KotlinResolutionCallbacks {
fun completeCallableReference(callableReferenceArgument: ResolvedCallableReferenceArgument,
resultTypeParameters: List<UnwrappedType>)
fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralArgument)
}
@@ -52,6 +52,7 @@ class KotlinCallCompleter(
fun buildResultingSubstitutor(): NewTypeSubstitutor
val lambdaArguments: List<ResolvedLambdaArgument>
val callableReferenceArguments: List<ResolvedCallableReferenceArgument>
val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument>
// type can be proper if it not contains not fixed type variables
fun canBeProper(type: UnwrappedType): Boolean
@@ -121,6 +122,9 @@ class KotlinCallCompleter(
c.callableReferenceArguments.forEach {
resolutionCallbacks.completeCallableReference(it, it.myTypeVariables.map { currentSubstitutor.safeSubstitute(it.defaultType) })
}
c.collectionLiteralArguments.forEach {
resolutionCallbacks.completeCollectionLiteralCalls(it)
}
return ResolvedKotlinCall.CompletedResolvedKotlinCall(completedCall, competedCalls, c.lambdaArguments)
}
@@ -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.
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstituto
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallableReferenceArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCollectionLiteralArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedKotlinCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaArgument
import org.jetbrains.kotlin.types.TypeConstructor
@@ -41,6 +42,7 @@ interface ConstraintSystemBuilder : ConstraintSystemOperation {
fun addInnerCall(innerCall: ResolvedKotlinCall.OnlyResolvedKotlinCall)
fun addLambdaArgument(resolvedLambdaArgument: ResolvedLambdaArgument)
fun addCallableReferenceArgument(resolvedCallableReferenceArgument: ResolvedCallableReferenceArgument)
fun addCollectionLiteralArgument(collectionLiteralArgument: ResolvedCollectionLiteralArgument)
// if runOperations return true, then this operation will be applied, and function return true
fun runTransaction(runOperations: ConstraintSystemOperation.() -> Boolean): Boolean
@@ -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.
@@ -17,10 +17,7 @@
package org.jetbrains.kotlin.resolve.calls.inference.model
import org.jetbrains.kotlin.resolve.calls.inference.substitute
import org.jetbrains.kotlin.resolve.calls.model.ResolvedKotlinCall
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallableReferenceArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaArgument
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.UnwrappedType
@@ -57,6 +54,7 @@ interface ConstraintStorage {
val fixedTypeVariables: Map<TypeConstructor, UnwrappedType>
val lambdaArguments: List<ResolvedLambdaArgument>
val callableReferenceArguments: List<ResolvedCallableReferenceArgument>
val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument>
val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall>
object Empty : ConstraintStorage {
@@ -68,6 +66,7 @@ interface ConstraintStorage {
override val fixedTypeVariables: Map<TypeConstructor, UnwrappedType> get() = emptyMap()
override val lambdaArguments: List<ResolvedLambdaArgument> get() = emptyList()
override val callableReferenceArguments: List<ResolvedCallableReferenceArgument> get() = emptyList()
override val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument> get() = emptyList()
override val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall> get() = emptyList()
}
}
@@ -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.
@@ -17,10 +17,7 @@
package org.jetbrains.kotlin.resolve.calls.inference.model
import org.jetbrains.kotlin.resolve.calls.inference.trimToSize
import org.jetbrains.kotlin.resolve.calls.model.ResolvedKotlinCall
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallableReferenceArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaArgument
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType
import java.util.*
@@ -86,5 +83,6 @@ internal class MutableConstraintStorage : ConstraintStorage {
override val fixedTypeVariables: MutableMap<TypeConstructor, UnwrappedType> = LinkedHashMap()
override val lambdaArguments: MutableList<ResolvedLambdaArgument> = ArrayList()
override val callableReferenceArguments: MutableList<ResolvedCallableReferenceArgument> = ArrayList()
override val collectionLiteralArguments: MutableList<ResolvedCollectionLiteralArgument> = ArrayList()
override val innerCalls: MutableList<ResolvedKotlinCall.OnlyResolvedKotlinCall> = ArrayList()
}
@@ -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,10 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.model
import org.jetbrains.kotlin.resolve.calls.components.KotlinCallCompleter
import org.jetbrains.kotlin.resolve.calls.inference.*
import org.jetbrains.kotlin.resolve.calls.inference.components.*
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallableReferenceArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedKotlinCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaArgument
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.TypeConstructor
@@ -156,6 +153,11 @@ class NewConstraintSystemImpl(val constraintInjector: ConstraintInjector, val re
storage.callableReferenceArguments.add(resolvedCallableReferenceArgument)
}
override fun addCollectionLiteralArgument(collectionLiteralArgument: ResolvedCollectionLiteralArgument) {
checkState(State.BUILDING, State.COMPLETION)
storage.collectionLiteralArguments.add(collectionLiteralArgument)
}
private fun getVariablesForFixation(): Map<NewTypeVariable, UnwrappedType> {
val fixedVariables = LinkedHashMap<NewTypeVariable, UnwrappedType>()
@@ -256,6 +258,12 @@ class NewConstraintSystemImpl(val constraintInjector: ConstraintInjector, val re
return storage.callableReferenceArguments
}
override val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument>
get() {
checkState(State.COMPLETION)
return storage.collectionLiteralArguments
}
// KotlinCallCompleter.Context
override fun asResultTypeResolverContext() = apply { checkState(State.COMPLETION) }
@@ -119,6 +119,7 @@ interface CallableReferenceKotlinCallArgument : KotlinCallArgument {
val rhsName: Name
}
interface CollectionLiteralKotlinCallArgument : KotlinCallArgument
interface TypeArgument
@@ -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.
@@ -59,4 +59,13 @@ class ResolvedCallableReferenceArgument(
) : ArgumentWithPostponeResolution() {
override val inputTypes: Collection<UnwrappedType> get() = emptyList()
override val outputType: UnwrappedType? = null
}
class ResolvedCollectionLiteralArgument(
override val outerCall: KotlinCall,
override val argument: CollectionLiteralKotlinCallArgument,
val expectedType: UnwrappedType
) : ArgumentWithPostponeResolution() {
override val inputTypes: Collection<UnwrappedType> get() = emptyList()
override val outputType: UnwrappedType? = null
}