Debugger: Fix lvalue evaluation (KT-11663, KT-19980)
This commit is contained in:
@@ -36,6 +36,7 @@ class CodeFragmentCodegenInfo(
|
||||
interface IParameter {
|
||||
val targetDescriptor: DeclarationDescriptor
|
||||
val targetType: KotlinType
|
||||
val isLValue: Boolean
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +211,7 @@ class CodeFragmentCodegen private constructor(
|
||||
val asmType: Type
|
||||
val stackValue: StackValue
|
||||
|
||||
val sharedAsmType = getSharedTypeIfApplicable(parameter.targetDescriptor, typeMapper)
|
||||
val sharedAsmType = getSharedTypeIfApplicable(parameter, typeMapper)
|
||||
if (sharedAsmType != null) {
|
||||
asmType = sharedAsmType
|
||||
val unwrappedType = typeMapper.mapType(parameter.targetType)
|
||||
@@ -229,9 +230,15 @@ class CodeFragmentCodegen private constructor(
|
||||
return CalculatedCodeFragmentCodegenInfo(parameters, methodSignature.returnType)
|
||||
}
|
||||
|
||||
fun getSharedTypeIfApplicable(descriptor: DeclarationDescriptor, typeMapper: KotlinTypeMapper): Type? {
|
||||
return when (descriptor) {
|
||||
is LocalVariableDescriptor -> typeMapper.getSharedVarType(descriptor)
|
||||
fun getSharedTypeIfApplicable(parameter: IParameter, typeMapper: KotlinTypeMapper): Type? {
|
||||
return when (val descriptor = parameter.targetDescriptor) {
|
||||
is LocalVariableDescriptor -> {
|
||||
var result = typeMapper.getSharedVarType(descriptor)
|
||||
if (result == null && parameter.isLValue) {
|
||||
result = StackValue.sharedTypeForType(typeMapper.mapType(descriptor.type))
|
||||
}
|
||||
result
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+17
-9
@@ -110,15 +110,21 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
return qualifiedExpression.getOperationSign() == KtTokens.DOT &&
|
||||
qualifiedExpression.getReceiverExpression() == KtPsiUtil.deparenthesize(expression);
|
||||
}
|
||||
if (parent instanceof KtBinaryExpression) {
|
||||
KtBinaryExpression binaryExpression = (KtBinaryExpression) parent;
|
||||
if (!OperatorConventions.BINARY_OPERATION_NAMES.containsKey(binaryExpression.getOperationToken()) &&
|
||||
!KtTokens.ALL_ASSIGNMENTS.contains(binaryExpression.getOperationToken())) {
|
||||
return false;
|
||||
}
|
||||
return PsiTreeUtil.isAncestor(binaryExpression.getLeft(), expression, false);
|
||||
|
||||
return isLValue(expression, parent);
|
||||
}
|
||||
|
||||
public static boolean isLValue(@NotNull KtSimpleNameExpression expression, @Nullable PsiElement parent) {
|
||||
if (!(parent instanceof KtBinaryExpression)) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
KtBinaryExpression binaryExpression = (KtBinaryExpression) parent;
|
||||
if (!OperatorConventions.BINARY_OPERATION_NAMES.containsKey(binaryExpression.getOperationToken()) &&
|
||||
!KtTokens.ALL_ASSIGNMENTS.contains(binaryExpression.getOperationToken())) {
|
||||
return false;
|
||||
}
|
||||
return PsiTreeUtil.isAncestor(binaryExpression.getLeft(), expression, false);
|
||||
}
|
||||
|
||||
private static boolean isDangerousWithNull(@NotNull KtSimpleNameExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
@@ -1463,7 +1469,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@NotNull
|
||||
private KotlinTypeInfo assignmentIsNotAnExpressionError(KtBinaryExpression expression, ExpressionTypingContext context) {
|
||||
facade.checkStatementType(expression, context);
|
||||
context.trace.report(ASSIGNMENT_IN_EXPRESSION_CONTEXT.on(expression));
|
||||
if (!context.isDebuggerContext) {
|
||||
context.trace.report(ASSIGNMENT_IN_EXPRESSION_CONTEXT.on(expression));
|
||||
}
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -373,7 +373,9 @@ public class DataFlowAnalyzer {
|
||||
public KotlinTypeInfo illegalStatementType(@NotNull KtExpression expression, @NotNull ExpressionTypingContext context, @NotNull ExpressionTypingInternals facade) {
|
||||
facade.checkStatementType(
|
||||
expression, context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT));
|
||||
context.trace.report(EXPRESSION_EXPECTED.on(expression, expression));
|
||||
if (!context.isDebuggerContext) {
|
||||
context.trace.report(EXPRESSION_EXPECTED.on(expression, expression));
|
||||
}
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user