Minor, add KtDoubleColonExpression#isEmptyLHS utility
This commit is contained in:
@@ -38,6 +38,9 @@ abstract class KtDoubleColonExpression(node: ASTNode) : KtExpressionImpl(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isEmptyLHS: Boolean
|
||||||
|
get() = doubleColonTokenReference.prevSibling == null
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D): R {
|
||||||
return visitor.visitDoubleColonExpression(this, data)
|
return visitor.visitDoubleColonExpression(this, data)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -270,7 +270,7 @@ fun createReflectionTypeForResolvedCallableReference(
|
|||||||
reflectionTypes: ReflectionTypes
|
reflectionTypes: ReflectionTypes
|
||||||
): KotlinType? {
|
): KotlinType? {
|
||||||
val type = createReflectionTypeForCallableDescriptor(
|
val type = createReflectionTypeForCallableDescriptor(
|
||||||
descriptor, lhsType, reflectionTypes, context.trace, reference.callableReference, reference.typeReference == null
|
descriptor, lhsType, reflectionTypes, context.trace, reference.callableReference, reference.isEmptyLHS
|
||||||
) ?: return null
|
) ?: return null
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is FunctionDescriptor -> {
|
is FunctionDescriptor -> {
|
||||||
@@ -298,8 +298,9 @@ fun getResolvedCallableReferenceShapeType(
|
|||||||
null
|
null
|
||||||
overloadResolutionResults.isSingleResult ->
|
overloadResolutionResults.isSingleResult ->
|
||||||
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency)?.let { call ->
|
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency)?.let { call ->
|
||||||
createReflectionTypeForCallableDescriptor(call.resultingDescriptor, lhsType, reflectionTypes, context.trace, reference,
|
createReflectionTypeForCallableDescriptor(
|
||||||
reference.typeReference == null)
|
call.resultingDescriptor, lhsType, reflectionTypes, context.trace, reference, reference.isEmptyLHS
|
||||||
|
)
|
||||||
}
|
}
|
||||||
expectedTypeUnknown /* && overload resolution was ambiguous */ ->
|
expectedTypeUnknown /* && overload resolution was ambiguous */ ->
|
||||||
functionPlaceholders.createFunctionPlaceholderType(emptyList(), false)
|
functionPlaceholders.createFunctionPlaceholderType(emptyList(), false)
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ class CandidateResolver(
|
|||||||
val candidate = candidateCall.candidateDescriptor
|
val candidate = candidateCall.candidateDescriptor
|
||||||
val candidateReflectionType = getReflectionTypeForCandidateDescriptor(
|
val candidateReflectionType = getReflectionTypeForCandidateDescriptor(
|
||||||
candidate, reflectionTypes,
|
candidate, reflectionTypes,
|
||||||
call.callElement.parent.let { it is KtCallableReferenceExpression && it.typeReference == null }
|
call.callElement.parent.let { it is KtCallableReferenceExpression && it.isEmptyLHS }
|
||||||
);
|
);
|
||||||
if (candidateReflectionType != null) {
|
if (candidateReflectionType != null) {
|
||||||
if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(candidateReflectionType, expectedType)) {
|
if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(candidateReflectionType, expectedType)) {
|
||||||
|
|||||||
+3
-5
@@ -61,9 +61,7 @@ class DoubleColonExpressionResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveClassLiteral(expression: KtClassLiteralExpression, c: ExpressionTypingContext): KotlinType? {
|
private fun resolveClassLiteral(expression: KtClassLiteralExpression, c: ExpressionTypingContext): KotlinType? {
|
||||||
val typeReference = expression.typeReference
|
if (expression.isEmptyLHS) {
|
||||||
|
|
||||||
if (typeReference == null) {
|
|
||||||
// "::class" will maybe mean "this::class", a class of "this" instance
|
// "::class" will maybe mean "this::class", a class of "this" instance
|
||||||
c.trace.report(UNSUPPORTED.on(expression, "Class literals with empty left hand side are not yet supported"))
|
c.trace.report(UNSUPPORTED.on(expression, "Class literals with empty left hand side are not yet supported"))
|
||||||
return null
|
return null
|
||||||
@@ -72,7 +70,7 @@ class DoubleColonExpressionResolver(
|
|||||||
val context = TypeResolutionContext(
|
val context = TypeResolutionContext(
|
||||||
c.scope, c.trace, /* checkBounds = */ false, /* allowBareTypes = */ true, /* isDebuggerContext = */ false
|
c.scope, c.trace, /* checkBounds = */ false, /* allowBareTypes = */ true, /* isDebuggerContext = */ false
|
||||||
)
|
)
|
||||||
val possiblyBareType = typeResolver.resolvePossiblyBareType(context, typeReference)
|
val possiblyBareType = typeResolver.resolvePossiblyBareType(context, expression.typeReference!!)
|
||||||
|
|
||||||
var type: KotlinType? = null
|
var type: KotlinType? = null
|
||||||
if (possiblyBareType.isBare) {
|
if (possiblyBareType.isBare) {
|
||||||
@@ -208,7 +206,7 @@ class DoubleColonExpressionResolver(
|
|||||||
}
|
}
|
||||||
if (descriptor == null) return null
|
if (descriptor == null) return null
|
||||||
|
|
||||||
if (expression.typeReference == null &&
|
if (expression.isEmptyLHS &&
|
||||||
(descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null)) {
|
(descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null)) {
|
||||||
context.trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(reference))
|
context.trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(reference))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user