[NI] Resolve collection literals arguments as postponed ones
This commit is contained in:
+12
@@ -194,4 +194,16 @@ class KotlinResolutionCallbacksImpl(
|
|||||||
|
|
||||||
doubleColonExpressionResolver.checkReferenceIsToAllowedMember(callableCandidate.candidate, topLevelCallContext.trace, callableReferenceExpression)
|
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
|
override val rhsName: Name
|
||||||
) : CallableReferenceKotlinCallArgument, PSIKotlinCallArgument()
|
) : 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(
|
class SubKotlinCallArgumentImpl(
|
||||||
override val valueArgument: ValueArgument,
|
override val valueArgument: ValueArgument,
|
||||||
override val dataFlowInfoBeforeThisArgument: DataFlowInfo,
|
override val dataFlowInfoBeforeThisArgument: DataFlowInfo,
|
||||||
|
|||||||
@@ -510,6 +510,11 @@ class PSICallResolver(
|
|||||||
return lambdaArgument
|
return lambdaArgument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ktExpression is KtCollectionLiteralExpression) {
|
||||||
|
return CollectionLiteralKotlinCallArgumentImpl(
|
||||||
|
valueArgument, argumentName, startDataFlowInfo, startDataFlowInfo, ktExpression, outerCallContext)
|
||||||
|
}
|
||||||
|
|
||||||
val context = outerCallContext.replaceContextDependency(ContextDependency.DEPENDENT)
|
val context = outerCallContext.replaceContextDependency(ContextDependency.DEPENDENT)
|
||||||
.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceDataFlowInfo(startDataFlowInfo)
|
.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceDataFlowInfo(startDataFlowInfo)
|
||||||
|
|
||||||
|
|||||||
+11
@@ -78,6 +78,7 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
checkCallableExpectedType(csBuilder, argument, expectedType)
|
checkCallableExpectedType(csBuilder, argument, expectedType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
is CollectionLiteralKotlinCallArgument -> processCollectionLiteralArgument(kotlinCall, csBuilder, argument, expectedType)
|
||||||
else -> error("Incorrect argument type: $argument, ${argument.javaClass.canonicalName}.")
|
else -> error("Incorrect argument type: $argument, ${argument.javaClass.canonicalName}.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,6 +181,16 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun processCollectionLiteralArgument(
|
||||||
|
kotlinCall: KotlinCall,
|
||||||
|
csBuilder: ConstraintSystemBuilder,
|
||||||
|
collectionLiteralArgument: CollectionLiteralKotlinCallArgument,
|
||||||
|
expectedType: UnwrappedType
|
||||||
|
): KotlinCallDiagnostic? {
|
||||||
|
csBuilder.addCollectionLiteralArgument(ResolvedCollectionLiteralArgument(kotlinCall, collectionLiteralArgument, expectedType))
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun checkExpressionArgument(
|
internal fun checkExpressionArgument(
|
||||||
|
|||||||
+1
@@ -39,4 +39,5 @@ interface KotlinResolutionCallbacks {
|
|||||||
fun completeCallableReference(callableReferenceArgument: ResolvedCallableReferenceArgument,
|
fun completeCallableReference(callableReferenceArgument: ResolvedCallableReferenceArgument,
|
||||||
resultTypeParameters: List<UnwrappedType>)
|
resultTypeParameters: List<UnwrappedType>)
|
||||||
|
|
||||||
|
fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralArgument)
|
||||||
}
|
}
|
||||||
+4
@@ -52,6 +52,7 @@ class KotlinCallCompleter(
|
|||||||
fun buildResultingSubstitutor(): NewTypeSubstitutor
|
fun buildResultingSubstitutor(): NewTypeSubstitutor
|
||||||
val lambdaArguments: List<ResolvedLambdaArgument>
|
val lambdaArguments: List<ResolvedLambdaArgument>
|
||||||
val callableReferenceArguments: List<ResolvedCallableReferenceArgument>
|
val callableReferenceArguments: List<ResolvedCallableReferenceArgument>
|
||||||
|
val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument>
|
||||||
|
|
||||||
// type can be proper if it not contains not fixed type variables
|
// type can be proper if it not contains not fixed type variables
|
||||||
fun canBeProper(type: UnwrappedType): Boolean
|
fun canBeProper(type: UnwrappedType): Boolean
|
||||||
@@ -121,6 +122,9 @@ class KotlinCallCompleter(
|
|||||||
c.callableReferenceArguments.forEach {
|
c.callableReferenceArguments.forEach {
|
||||||
resolutionCallbacks.completeCallableReference(it, it.myTypeVariables.map { currentSubstitutor.safeSubstitute(it.defaultType) })
|
resolutionCallbacks.completeCallableReference(it, it.myTypeVariables.map { currentSubstitutor.safeSubstitute(it.defaultType) })
|
||||||
}
|
}
|
||||||
|
c.collectionLiteralArguments.forEach {
|
||||||
|
resolutionCallbacks.completeCollectionLiteralCalls(it)
|
||||||
|
}
|
||||||
return ResolvedKotlinCall.CompletedResolvedKotlinCall(completedCall, competedCalls, c.lambdaArguments)
|
return ResolvedKotlinCall.CompletedResolvedKotlinCall(completedCall, competedCalls, c.lambdaArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.ConstraintPosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallableReferenceArgument
|
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.ResolvedKotlinCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaArgument
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaArgument
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
@@ -41,6 +42,7 @@ interface ConstraintSystemBuilder : ConstraintSystemOperation {
|
|||||||
fun addInnerCall(innerCall: ResolvedKotlinCall.OnlyResolvedKotlinCall)
|
fun addInnerCall(innerCall: ResolvedKotlinCall.OnlyResolvedKotlinCall)
|
||||||
fun addLambdaArgument(resolvedLambdaArgument: ResolvedLambdaArgument)
|
fun addLambdaArgument(resolvedLambdaArgument: ResolvedLambdaArgument)
|
||||||
fun addCallableReferenceArgument(resolvedCallableReferenceArgument: ResolvedCallableReferenceArgument)
|
fun addCallableReferenceArgument(resolvedCallableReferenceArgument: ResolvedCallableReferenceArgument)
|
||||||
|
fun addCollectionLiteralArgument(collectionLiteralArgument: ResolvedCollectionLiteralArgument)
|
||||||
|
|
||||||
// if runOperations return true, then this operation will be applied, and function return true
|
// if runOperations return true, then this operation will be applied, and function return true
|
||||||
fun runTransaction(runOperations: ConstraintSystemOperation.() -> Boolean): Boolean
|
fun runTransaction(runOperations: ConstraintSystemOperation.() -> Boolean): Boolean
|
||||||
|
|||||||
+4
-5
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedKotlinCall
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
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.types.TypeConstructor
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
@@ -57,6 +54,7 @@ interface ConstraintStorage {
|
|||||||
val fixedTypeVariables: Map<TypeConstructor, UnwrappedType>
|
val fixedTypeVariables: Map<TypeConstructor, UnwrappedType>
|
||||||
val lambdaArguments: List<ResolvedLambdaArgument>
|
val lambdaArguments: List<ResolvedLambdaArgument>
|
||||||
val callableReferenceArguments: List<ResolvedCallableReferenceArgument>
|
val callableReferenceArguments: List<ResolvedCallableReferenceArgument>
|
||||||
|
val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument>
|
||||||
val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall>
|
val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall>
|
||||||
|
|
||||||
object Empty : ConstraintStorage {
|
object Empty : ConstraintStorage {
|
||||||
@@ -68,6 +66,7 @@ interface ConstraintStorage {
|
|||||||
override val fixedTypeVariables: Map<TypeConstructor, UnwrappedType> get() = emptyMap()
|
override val fixedTypeVariables: Map<TypeConstructor, UnwrappedType> get() = emptyMap()
|
||||||
override val lambdaArguments: List<ResolvedLambdaArgument> get() = emptyList()
|
override val lambdaArguments: List<ResolvedLambdaArgument> get() = emptyList()
|
||||||
override val callableReferenceArguments: List<ResolvedCallableReferenceArgument> get() = emptyList()
|
override val callableReferenceArguments: List<ResolvedCallableReferenceArgument> get() = emptyList()
|
||||||
|
override val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument> get() = emptyList()
|
||||||
override val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall> get() = emptyList()
|
override val innerCalls: List<ResolvedKotlinCall.OnlyResolvedKotlinCall> get() = emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.trimToSize
|
import org.jetbrains.kotlin.resolve.calls.inference.trimToSize
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedKotlinCall
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
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.types.TypeConstructor
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -86,5 +83,6 @@ internal class MutableConstraintStorage : ConstraintStorage {
|
|||||||
override val fixedTypeVariables: MutableMap<TypeConstructor, UnwrappedType> = LinkedHashMap()
|
override val fixedTypeVariables: MutableMap<TypeConstructor, UnwrappedType> = LinkedHashMap()
|
||||||
override val lambdaArguments: MutableList<ResolvedLambdaArgument> = ArrayList()
|
override val lambdaArguments: MutableList<ResolvedLambdaArgument> = ArrayList()
|
||||||
override val callableReferenceArguments: MutableList<ResolvedCallableReferenceArgument> = ArrayList()
|
override val callableReferenceArguments: MutableList<ResolvedCallableReferenceArgument> = ArrayList()
|
||||||
|
override val collectionLiteralArguments: MutableList<ResolvedCollectionLiteralArgument> = ArrayList()
|
||||||
override val innerCalls: MutableList<ResolvedKotlinCall.OnlyResolvedKotlinCall> = ArrayList()
|
override val innerCalls: MutableList<ResolvedKotlinCall.OnlyResolvedKotlinCall> = ArrayList()
|
||||||
}
|
}
|
||||||
+13
-5
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.components.KotlinCallCompleter
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.*
|
import org.jetbrains.kotlin.resolve.calls.inference.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
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.tower.isSuccess
|
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
@@ -156,6 +153,11 @@ class NewConstraintSystemImpl(val constraintInjector: ConstraintInjector, val re
|
|||||||
storage.callableReferenceArguments.add(resolvedCallableReferenceArgument)
|
storage.callableReferenceArguments.add(resolvedCallableReferenceArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun addCollectionLiteralArgument(collectionLiteralArgument: ResolvedCollectionLiteralArgument) {
|
||||||
|
checkState(State.BUILDING, State.COMPLETION)
|
||||||
|
storage.collectionLiteralArguments.add(collectionLiteralArgument)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getVariablesForFixation(): Map<NewTypeVariable, UnwrappedType> {
|
private fun getVariablesForFixation(): Map<NewTypeVariable, UnwrappedType> {
|
||||||
val fixedVariables = LinkedHashMap<NewTypeVariable, UnwrappedType>()
|
val fixedVariables = LinkedHashMap<NewTypeVariable, UnwrappedType>()
|
||||||
|
|
||||||
@@ -256,6 +258,12 @@ class NewConstraintSystemImpl(val constraintInjector: ConstraintInjector, val re
|
|||||||
return storage.callableReferenceArguments
|
return storage.callableReferenceArguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val collectionLiteralArguments: List<ResolvedCollectionLiteralArgument>
|
||||||
|
get() {
|
||||||
|
checkState(State.COMPLETION)
|
||||||
|
return storage.collectionLiteralArguments
|
||||||
|
}
|
||||||
|
|
||||||
// KotlinCallCompleter.Context
|
// KotlinCallCompleter.Context
|
||||||
override fun asResultTypeResolverContext() = apply { checkState(State.COMPLETION) }
|
override fun asResultTypeResolverContext() = apply { checkState(State.COMPLETION) }
|
||||||
|
|
||||||
|
|||||||
+1
@@ -119,6 +119,7 @@ interface CallableReferenceKotlinCallArgument : KotlinCallArgument {
|
|||||||
val rhsName: Name
|
val rhsName: Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CollectionLiteralKotlinCallArgument : KotlinCallArgument
|
||||||
|
|
||||||
interface TypeArgument
|
interface TypeArgument
|
||||||
|
|
||||||
|
|||||||
+10
-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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -59,4 +59,13 @@ class ResolvedCallableReferenceArgument(
|
|||||||
) : ArgumentWithPostponeResolution() {
|
) : ArgumentWithPostponeResolution() {
|
||||||
override val inputTypes: Collection<UnwrappedType> get() = emptyList()
|
override val inputTypes: Collection<UnwrappedType> get() = emptyList()
|
||||||
override val outputType: UnwrappedType? = null
|
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
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user