KT-359 ++/--/+= must be included into calculation of MUST_BE_WRAPPED_IN_A_REF
This commit is contained in:
+1
@@ -506,6 +506,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
else {
|
||||
context.trace.record(BindingContext.VARIABLE_REASSIGNMENT, expression);
|
||||
ExpressionTypingUtils.checkWrappingInRef(baseExpression, context);
|
||||
}
|
||||
// TODO : Maybe returnType?
|
||||
result = receiverType;
|
||||
|
||||
+15
@@ -6,6 +6,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -24,6 +26,7 @@ import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.RESULT_TYPE_MISMATCH;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.MUST_BE_WRAPPED_IN_A_REF;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -249,4 +252,16 @@ public class ExpressionTypingUtils {
|
||||
}
|
||||
return context.expectedType;
|
||||
}
|
||||
|
||||
public static void checkWrappingInRef(JetExpression expression, ExpressionTypingContext context) {
|
||||
if (!(expression instanceof JetSimpleNameExpression)) return;
|
||||
JetSimpleNameExpression simpleName = (JetSimpleNameExpression) expression;
|
||||
VariableDescriptor variable = AutoCastUtils.getVariableDescriptorFromSimpleName(context.trace.getBindingContext(), simpleName);
|
||||
if (variable != null) {
|
||||
DeclarationDescriptor containingDeclaration = variable.getContainingDeclaration();
|
||||
if (context.scope.getContainingDeclaration() != containingDeclaration && containingDeclaration instanceof CallableDescriptor) {
|
||||
context.trace.record(MUST_BE_WRAPPED_IN_A_REF, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -8,7 +8,6 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.calls.AutoCastUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
@@ -16,7 +15,6 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.MUST_BE_WRAPPED_IN_A_REF;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.getExpressionReceiver;
|
||||
|
||||
@@ -107,6 +105,7 @@ public class ExpressionTypingVisitorWithWritableScope extends BasicExpressionTyp
|
||||
JetType typeForBinaryCall = getTypeForBinaryCall(scope, counterpartName, context, expression);
|
||||
if (typeForBinaryCall != null) {
|
||||
context.trace.record(BindingContext.VARIABLE_REASSIGNMENT, expression);
|
||||
ExpressionTypingUtils.checkWrappingInRef(expression.getLeft(), context);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -149,13 +148,7 @@ public class ExpressionTypingVisitorWithWritableScope extends BasicExpressionTyp
|
||||
context.trace.record(BindingContext.VARIABLE_ASSIGNMENT, simpleName, property);
|
||||
}
|
||||
}
|
||||
VariableDescriptor variable = AutoCastUtils.getVariableDescriptorFromSimpleName(context.trace.getBindingContext(), simpleName);
|
||||
if (variable != null) {
|
||||
DeclarationDescriptor containingDeclaration = variable.getContainingDeclaration();
|
||||
if (context.scope.getContainingDeclaration() != containingDeclaration && containingDeclaration instanceof CallableDescriptor) {
|
||||
context.trace.record(MUST_BE_WRAPPED_IN_A_REF, variable);
|
||||
}
|
||||
}
|
||||
ExpressionTypingUtils.checkWrappingInRef(simpleName, context);
|
||||
}
|
||||
return checkExpectedType(expression, context);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class FunctionBodyTyper {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
fun notContainsBreak() {
|
||||
fun refs() {
|
||||
var <info>a</info> = 1
|
||||
val v = {
|
||||
<info>a</info> = 2
|
||||
@@ -16,3 +16,22 @@ fun notContainsBreak() {
|
||||
<info>y</info> = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun refsPlusAssign() {
|
||||
var <info>a</info> = 1
|
||||
val v = {
|
||||
<info>a</info> += 2
|
||||
}
|
||||
|
||||
var <info>x</info> = 1
|
||||
val b = object {
|
||||
fun foo() {
|
||||
<info>x</info> += 2
|
||||
}
|
||||
}
|
||||
|
||||
var <info>y</info> = 1
|
||||
fun foo() {
|
||||
<info>y</info> += 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user