Rename DoubleColonLHS.Expression.isObject -> isObjectQualifier
This commit is contained in:
@@ -3393,7 +3393,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
@Override
|
@Override
|
||||||
public Unit invoke(InstructionAdapter v) {
|
public Unit invoke(InstructionAdapter v) {
|
||||||
KotlinType type = lhs.getType();
|
KotlinType type = lhs.getType();
|
||||||
if (lhs instanceof DoubleColonLHS.Expression && !((DoubleColonLHS.Expression) lhs).isObject()) {
|
if (lhs instanceof DoubleColonLHS.Expression && !((DoubleColonLHS.Expression) lhs).isObjectQualifier()) {
|
||||||
JavaClassProperty.INSTANCE.generateImpl(v, gen(receiverExpression));
|
JavaClassProperty.INSTANCE.generateImpl(v, gen(receiverExpression));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+1
-1
@@ -140,7 +140,7 @@ class ConstantExpressionEvaluator(
|
|||||||
val lhsExpression = argumentExpression.receiverExpression
|
val lhsExpression = argumentExpression.receiverExpression
|
||||||
if (lhsExpression != null) {
|
if (lhsExpression != null) {
|
||||||
val doubleColonLhs = trace.bindingContext.get(BindingContext.DOUBLE_COLON_LHS, lhsExpression)
|
val doubleColonLhs = trace.bindingContext.get(BindingContext.DOUBLE_COLON_LHS, lhsExpression)
|
||||||
if (doubleColonLhs is DoubleColonLHS.Expression && !doubleColonLhs.isObject) {
|
if (doubleColonLhs is DoubleColonLHS.Expression && !doubleColonLhs.isObjectQualifier) {
|
||||||
trace.report(Errors.ANNOTATION_PARAMETER_MUST_BE_KCLASS_LITERAL.on(argumentExpression))
|
trace.report(Errors.ANNOTATION_PARAMETER_MUST_BE_KCLASS_LITERAL.on(argumentExpression))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-7
@@ -60,7 +60,18 @@ import java.util.*
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
sealed class DoubleColonLHS(val type: KotlinType) {
|
sealed class DoubleColonLHS(val type: KotlinType) {
|
||||||
class Expression(typeInfo: KotlinTypeInfo, val isObject: Boolean) : DoubleColonLHS(typeInfo.type!!) {
|
/**
|
||||||
|
* [isObjectQualifier] is true iff the LHS of a callable reference is a qualified expression which references a named object.
|
||||||
|
* Note that such LHS can be treated both as a type and as an expression, so special handling may be required.
|
||||||
|
*
|
||||||
|
* For example, if `Obj` is an object:
|
||||||
|
*
|
||||||
|
* Obj::class // object qualifier
|
||||||
|
* test.Obj::class // object qualifier
|
||||||
|
* (Obj)::class // not an object qualifier (can only be treated as an expression, not as a type)
|
||||||
|
* { Obj }()::class // not an object qualifier
|
||||||
|
*/
|
||||||
|
class Expression(typeInfo: KotlinTypeInfo, val isObjectQualifier: Boolean) : DoubleColonLHS(typeInfo.type!!) {
|
||||||
val dataFlowInfo: DataFlowInfo = typeInfo.dataFlowInfo
|
val dataFlowInfo: DataFlowInfo = typeInfo.dataFlowInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +109,8 @@ class DoubleColonExpressionResolver(
|
|||||||
val type = result?.type
|
val type = result?.type
|
||||||
if (type != null && !type.isError) {
|
if (type != null && !type.isError) {
|
||||||
checkClassLiteral(c, expression, result)
|
checkClassLiteral(c, expression, result)
|
||||||
val variance = if (result is DoubleColonLHS.Expression && !result.isObject) Variance.OUT_VARIANCE else Variance.INVARIANT
|
val variance =
|
||||||
|
if (result is DoubleColonLHS.Expression && !result.isObjectQualifier) Variance.OUT_VARIANCE else Variance.INVARIANT
|
||||||
val kClassType = reflectionTypes.getKClassType(Annotations.EMPTY, type, variance)
|
val kClassType = reflectionTypes.getKClassType(Annotations.EMPTY, type, variance)
|
||||||
if (kClassType.isError) {
|
if (kClassType.isError) {
|
||||||
c.trace.report(MISSING_DEPENDENCY_CLASS.on(expression.receiverExpression!!, KotlinBuiltIns.FQ_NAMES.kClass.toSafe()))
|
c.trace.report(MISSING_DEPENDENCY_CLASS.on(expression.receiverExpression!!, KotlinBuiltIns.FQ_NAMES.kClass.toSafe()))
|
||||||
@@ -115,7 +127,7 @@ class DoubleColonExpressionResolver(
|
|||||||
val type = result.type
|
val type = result.type
|
||||||
|
|
||||||
if (result is DoubleColonLHS.Expression) {
|
if (result is DoubleColonLHS.Expression) {
|
||||||
if (!result.isObject) {
|
if (!result.isObjectQualifier) {
|
||||||
if (!type.isSubtypeOf(type.builtIns.anyType)) {
|
if (!type.isSubtypeOf(type.builtIns.anyType)) {
|
||||||
c.trace.report(EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS.on(expression.receiverExpression!!, type))
|
c.trace.report(EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS.on(expression.receiverExpression!!, type))
|
||||||
}
|
}
|
||||||
@@ -316,7 +328,7 @@ class DoubleColonExpressionResolver(
|
|||||||
val lhs = resultForExpr.lhs
|
val lhs = resultForExpr.lhs
|
||||||
// If expression result is an object, we remember this and skip it here, because there are valid situations where
|
// If expression result is an object, we remember this and skip it here, because there are valid situations where
|
||||||
// another type (representing another classifier) should win
|
// another type (representing another classifier) should win
|
||||||
if (lhs != null && !lhs.isObject) {
|
if (lhs != null && !lhs.isObjectQualifier) {
|
||||||
return resultForExpr.commit()
|
return resultForExpr.commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,7 +416,7 @@ class DoubleColonExpressionResolver(
|
|||||||
if (classDescriptor.companionObjectDescriptor != null) return null
|
if (classDescriptor.companionObjectDescriptor != null) return null
|
||||||
|
|
||||||
if (DescriptorUtils.isObject(classDescriptor)) {
|
if (DescriptorUtils.isObject(classDescriptor)) {
|
||||||
return DoubleColonLHS.Expression(typeInfo, isObject = true)
|
return DoubleColonLHS.Expression(typeInfo, isObjectQualifier = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +424,7 @@ class DoubleColonExpressionResolver(
|
|||||||
if (expression.canBeConsideredProperType() && resultingDescriptor !is VariableDescriptor) return null
|
if (expression.canBeConsideredProperType() && resultingDescriptor !is VariableDescriptor) return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return DoubleColonLHS.Expression(typeInfo, isObject = false)
|
return DoubleColonLHS.Expression(typeInfo, isObjectQualifier = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveTypeOnLHS(
|
private fun resolveTypeOnLHS(
|
||||||
@@ -684,7 +696,7 @@ class DoubleColonExpressionResolver(
|
|||||||
)
|
)
|
||||||
if (result != null) return result
|
if (result != null) return result
|
||||||
|
|
||||||
if (lhs.isObject) {
|
if (lhs.isObjectQualifier) {
|
||||||
val classifier = lhsType.constructor.declarationDescriptor
|
val classifier = lhsType.constructor.declarationDescriptor
|
||||||
val calleeExpression = expression.receiverExpression?.getCalleeExpressionIfAny()
|
val calleeExpression = expression.receiverExpression?.getCalleeExpressionIfAny()
|
||||||
if (calleeExpression is KtSimpleNameExpression && classifier is ClassDescriptor) {
|
if (calleeExpression is KtSimpleNameExpression && classifier is ClassDescriptor) {
|
||||||
|
|||||||
+1
-1
@@ -839,7 +839,7 @@ class ExpressionCodegen(
|
|||||||
wrapIntoKClass: Boolean,
|
wrapIntoKClass: Boolean,
|
||||||
data: BlockInfo
|
data: BlockInfo
|
||||||
) {
|
) {
|
||||||
if (receiverExpression !is IrClassReference /* && DescriptorUtils.isObject(receiverExpression.descriptor)*/) {
|
if (receiverExpression !is IrClassReference /* && DescriptorUtils.isObjectQualifier(receiverExpression.descriptor)*/) {
|
||||||
JavaClassProperty.generateImpl(mv, gen(receiverExpression, data))
|
JavaClassProperty.generateImpl(mv, gen(receiverExpression, data))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+2
-2
@@ -35,9 +35,9 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
|||||||
val lhs = getOrFail(BindingContext.DOUBLE_COLON_LHS, ktArgument)
|
val lhs = getOrFail(BindingContext.DOUBLE_COLON_LHS, ktArgument)
|
||||||
val resultType = getInferredTypeWithImplicitCastsOrFail(ktClassLiteral)
|
val resultType = getInferredTypeWithImplicitCastsOrFail(ktClassLiteral)
|
||||||
|
|
||||||
return if (lhs is DoubleColonLHS.Expression && !lhs.isObject) {
|
return if (lhs is DoubleColonLHS.Expression && !lhs.isObjectQualifier) {
|
||||||
IrGetClassImpl(ktClassLiteral.startOffset, ktClassLiteral.endOffset, resultType,
|
IrGetClassImpl(ktClassLiteral.startOffset, ktClassLiteral.endOffset, resultType,
|
||||||
statementGenerator.generateExpression(ktArgument))
|
statementGenerator.generateExpression(ktArgument))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor
|
val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor
|
||||||
|
|||||||
+1
-1
@@ -236,7 +236,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
|||||||
DoubleColonLHS lhs = context.bindingContext().get(DOUBLE_COLON_LHS, receiverExpression);
|
DoubleColonLHS lhs = context.bindingContext().get(DOUBLE_COLON_LHS, receiverExpression);
|
||||||
assert lhs != null : "Class literal expression should have LHS resolved";
|
assert lhs != null : "Class literal expression should have LHS resolved";
|
||||||
|
|
||||||
if (lhs instanceof DoubleColonLHS.Expression && !((DoubleColonLHS.Expression) lhs).isObject()) {
|
if (lhs instanceof DoubleColonLHS.Expression && !((DoubleColonLHS.Expression) lhs).isObjectQualifier()) {
|
||||||
JsExpression receiver = translateAsExpression(receiverExpression, context);
|
JsExpression receiver = translateAsExpression(receiverExpression, context);
|
||||||
return new JsInvocation(context.namer().kotlin(GET_KCLASS_FROM_EXPRESSION), receiver);
|
return new JsInvocation(context.namer().kotlin(GET_KCLASS_FROM_EXPRESSION), receiver);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user