Remove obsolete assertion about expressions on LHS of '::'
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.psi
|
|||||||
|
|
||||||
import com.intellij.lang.ASTNode
|
import com.intellij.lang.ASTNode
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
|
||||||
abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
|
abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
|
||||||
@@ -36,9 +35,6 @@ abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
|
|||||||
error("Double colon expression must have '::': $text")
|
error("Double colon expression must have '::': $text")
|
||||||
}
|
}
|
||||||
|
|
||||||
val typeReference: KtTypeReference?
|
|
||||||
get() = findChildByType(KtNodeTypes.TYPE_REFERENCE)
|
|
||||||
|
|
||||||
val doubleColonTokenReference: PsiElement
|
val doubleColonTokenReference: PsiElement
|
||||||
get() = findChildByType(KtTokens.COLONCOLON)!!
|
get() = findChildByType(KtTokens.COLONCOLON)!!
|
||||||
|
|
||||||
|
|||||||
+2
-47
@@ -23,20 +23,16 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||||
import org.jetbrains.kotlin.diagnostics.Severity
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
||||||
import org.jetbrains.kotlin.resolve.*
|
import org.jetbrains.kotlin.resolve.*
|
||||||
import org.jetbrains.kotlin.resolve.callableReferences.createReflectionTypeForResolvedCallableReference
|
import org.jetbrains.kotlin.resolve.callableReferences.createReflectionTypeForResolvedCallableReference
|
||||||
import org.jetbrains.kotlin.resolve.callableReferences.resolvePossiblyAmbiguousCallableReference
|
import org.jetbrains.kotlin.resolve.callableReferences.resolvePossiblyAmbiguousCallableReference
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
|
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache
|
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
|
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil
|
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||||
@@ -59,7 +55,6 @@ internal val KtCallExpression.isWithoutValueArguments: Boolean
|
|||||||
|
|
||||||
class DoubleColonExpressionResolver(
|
class DoubleColonExpressionResolver(
|
||||||
val callResolver: CallResolver,
|
val callResolver: CallResolver,
|
||||||
val callExpressionResolver: CallExpressionResolver,
|
|
||||||
val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
||||||
val dataFlowAnalyzer: DataFlowAnalyzer,
|
val dataFlowAnalyzer: DataFlowAnalyzer,
|
||||||
val reflectionTypes: ReflectionTypes,
|
val reflectionTypes: ReflectionTypes,
|
||||||
@@ -213,51 +208,11 @@ class DoubleColonExpressionResolver(
|
|||||||
return dataFlowAnalyzer.createCheckedTypeInfo(errorType, c, expression)
|
return dataFlowAnalyzer.createCheckedTypeInfo(errorType, c, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
val trace = TemporaryBindingTrace.create(c.trace, "Callable reference type")
|
val (lhs, resolutionResults) = resolveCallableReference(expression, c, ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS)
|
||||||
val context = c.replaceBindingTrace(trace)
|
val result = getCallableReferenceType(expression, lhs, resolutionResults, c)
|
||||||
val (lhs, resolutionResults) = resolveCallableReference(expression, context, ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS)
|
|
||||||
val result = getCallableReferenceType(expression, lhs, resolutionResults, context)
|
|
||||||
val hasErrors = hasErrors(trace) // Do not inline this local variable (execution order is important)
|
|
||||||
trace.commit()
|
|
||||||
if (!hasErrors && result != null) {
|
|
||||||
checkNoExpressionOnLHS(expression, c)
|
|
||||||
}
|
|
||||||
return dataFlowAnalyzer.createCheckedTypeInfo(result, c, expression)
|
return dataFlowAnalyzer.createCheckedTypeInfo(result, c, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasErrors(trace: TemporaryBindingTrace): Boolean =
|
|
||||||
trace.bindingContext.diagnostics.all().any { diagnostic -> diagnostic.severity == Severity.ERROR }
|
|
||||||
|
|
||||||
private fun checkNoExpressionOnLHS(expression: KtCallableReferenceExpression, c: ExpressionTypingContext) {
|
|
||||||
val typeReference = expression.typeReference ?: return
|
|
||||||
var typeElement = typeReference.typeElement as? KtUserType ?: return
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (typeElement.typeArgumentList != null) return
|
|
||||||
typeElement = typeElement.qualifier ?: break
|
|
||||||
}
|
|
||||||
|
|
||||||
val simpleNameExpression = typeElement.referenceExpression ?: return
|
|
||||||
|
|
||||||
val traceAndCache = TemporaryTraceAndCache.create(c, "Resolve expression on LHS of callable reference", simpleNameExpression)
|
|
||||||
val resolutionResult = callExpressionResolver.resolveSimpleName(c.replaceTraceAndCache(traceAndCache), simpleNameExpression)
|
|
||||||
|
|
||||||
val resultingCalls = resolutionResult.resultingCalls.filter { call ->
|
|
||||||
call.status.possibleTransformToSuccess() && !ErrorUtils.isError(call.resultingDescriptor)
|
|
||||||
}
|
|
||||||
if (resultingCalls.isEmpty()) return
|
|
||||||
|
|
||||||
if (resultingCalls.singleOrNull()?.resultingDescriptor is FakeCallableDescriptorForObject) return
|
|
||||||
|
|
||||||
throw AssertionError(String.format(
|
|
||||||
"Expressions on left-hand side of callable reference are not supported yet.\n" +
|
|
||||||
"Resolution result: %s\n" +
|
|
||||||
"Original result: %s",
|
|
||||||
resultingCalls.map { call -> call.resultingDescriptor },
|
|
||||||
expression.callableReference.getResolvedCall(c.trace.bindingContext)?.resultingDescriptor
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getCallableReferenceType(
|
private fun getCallableReferenceType(
|
||||||
expression: KtCallableReferenceExpression,
|
expression: KtCallableReferenceExpression,
|
||||||
lhs: DoubleColonLHS?,
|
lhs: DoubleColonLHS?,
|
||||||
|
|||||||
Reference in New Issue
Block a user