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 {
|
||||
return visitor.visitDoubleColonExpression(this, data)
|
||||
}
|
||||
|
||||
+4
-3
@@ -270,7 +270,7 @@ fun createReflectionTypeForResolvedCallableReference(
|
||||
reflectionTypes: ReflectionTypes
|
||||
): KotlinType? {
|
||||
val type = createReflectionTypeForCallableDescriptor(
|
||||
descriptor, lhsType, reflectionTypes, context.trace, reference.callableReference, reference.typeReference == null
|
||||
descriptor, lhsType, reflectionTypes, context.trace, reference.callableReference, reference.isEmptyLHS
|
||||
) ?: return null
|
||||
when (descriptor) {
|
||||
is FunctionDescriptor -> {
|
||||
@@ -298,8 +298,9 @@ fun getResolvedCallableReferenceShapeType(
|
||||
null
|
||||
overloadResolutionResults.isSingleResult ->
|
||||
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency)?.let { call ->
|
||||
createReflectionTypeForCallableDescriptor(call.resultingDescriptor, lhsType, reflectionTypes, context.trace, reference,
|
||||
reference.typeReference == null)
|
||||
createReflectionTypeForCallableDescriptor(
|
||||
call.resultingDescriptor, lhsType, reflectionTypes, context.trace, reference, reference.isEmptyLHS
|
||||
)
|
||||
}
|
||||
expectedTypeUnknown /* && overload resolution was ambiguous */ ->
|
||||
functionPlaceholders.createFunctionPlaceholderType(emptyList(), false)
|
||||
|
||||
@@ -160,7 +160,7 @@ class CandidateResolver(
|
||||
val candidate = candidateCall.candidateDescriptor
|
||||
val candidateReflectionType = getReflectionTypeForCandidateDescriptor(
|
||||
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 (!KotlinTypeChecker.DEFAULT.isSubtypeOf(candidateReflectionType, expectedType)) {
|
||||
|
||||
+3
-5
@@ -61,9 +61,7 @@ class DoubleColonExpressionResolver(
|
||||
}
|
||||
|
||||
private fun resolveClassLiteral(expression: KtClassLiteralExpression, c: ExpressionTypingContext): KotlinType? {
|
||||
val typeReference = expression.typeReference
|
||||
|
||||
if (typeReference == null) {
|
||||
if (expression.isEmptyLHS) {
|
||||
// "::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"))
|
||||
return null
|
||||
@@ -72,7 +70,7 @@ class DoubleColonExpressionResolver(
|
||||
val context = TypeResolutionContext(
|
||||
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
|
||||
if (possiblyBareType.isBare) {
|
||||
@@ -208,7 +206,7 @@ class DoubleColonExpressionResolver(
|
||||
}
|
||||
if (descriptor == null) return null
|
||||
|
||||
if (expression.typeReference == null &&
|
||||
if (expression.isEmptyLHS &&
|
||||
(descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null)) {
|
||||
context.trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(reference))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user