incomplete assignment bug from EA fixed
This commit is contained in:
+6
-3
@@ -169,6 +169,9 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected JetType visitAssignmentOperation(JetBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
|
protected JetType visitAssignmentOperation(JetBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
|
||||||
|
JetExpression right = expression.getRight();
|
||||||
|
if (right == null) return null;
|
||||||
|
|
||||||
//There is a temporary binding trace for an opportunity to resolve set method for array if needed (the initial trace should be used there)
|
//There is a temporary binding trace for an opportunity to resolve set method for array if needed (the initial trace should be used there)
|
||||||
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(contextWithExpectedType.trace);
|
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(contextWithExpectedType.trace);
|
||||||
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE).replaceBindingTrace(temporaryBindingTrace);
|
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE).replaceBindingTrace(temporaryBindingTrace);
|
||||||
@@ -180,7 +183,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
JetType leftType = facade.getType(left, context);
|
JetType leftType = facade.getType(left, context);
|
||||||
if (leftType == null) {
|
if (leftType == null) {
|
||||||
facade.getType(expression.getRight(), context);
|
facade.getType(right, context);
|
||||||
context.trace.report(UNRESOLVED_REFERENCE.on(operationSign));
|
context.trace.report(UNRESOLVED_REFERENCE.on(operationSign));
|
||||||
temporaryBindingTrace.commit();
|
temporaryBindingTrace.commit();
|
||||||
return null;
|
return null;
|
||||||
@@ -208,7 +211,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
for (ResolvedCall<? extends FunctionDescriptor> call : ambiguityResolutionResults.getResultingCalls()) {
|
for (ResolvedCall<? extends FunctionDescriptor> call : ambiguityResolutionResults.getResultingCalls()) {
|
||||||
descriptors.add(call.getResultingDescriptor());
|
descriptors.add(call.getResultingDescriptor());
|
||||||
}
|
}
|
||||||
facade.getType(expression.getRight(), context);
|
facade.getType(right, context);
|
||||||
context.trace.record(AMBIGUOUS_REFERENCE_TARGET, operationSign, descriptors);
|
context.trace.record(AMBIGUOUS_REFERENCE_TARGET, operationSign, descriptors);
|
||||||
}
|
}
|
||||||
else if (assignmentOperationType != null) {
|
else if (assignmentOperationType != null) {
|
||||||
@@ -222,7 +225,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
context.trace.record(VARIABLE_REASSIGNMENT, expression);
|
context.trace.record(VARIABLE_REASSIGNMENT, expression);
|
||||||
if (left instanceof JetArrayAccessExpression) {
|
if (left instanceof JetArrayAccessExpression) {
|
||||||
ExpressionTypingContext contextForResolve = context.replaceScope(scope).replaceBindingTrace(TemporaryBindingTrace.create(contextWithExpectedType.trace));
|
ExpressionTypingContext contextForResolve = context.replaceScope(scope).replaceBindingTrace(TemporaryBindingTrace.create(contextWithExpectedType.trace));
|
||||||
basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, expression.getRight(), contextForResolve, context.trace);
|
basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, right, contextForResolve, context.trace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
basic.checkLValue(context.trace, expression.getLeft());
|
basic.checkLValue(context.trace, expression.getLeft());
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package sum
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
fun sum(a : IntArray) : Int {
|
||||||
|
// Write your solution here
|
||||||
|
<!UNRESOLVED_REFERENCE!>res<!> = 0
|
||||||
|
for (e in a)
|
||||||
|
res +=<!SYNTAX!><!>
|
||||||
|
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
test(0)
|
||||||
|
test(1, 1)
|
||||||
|
test(-1, -1, 0)
|
||||||
|
test(6, 1, 2, 3)
|
||||||
|
test(6, 1, 1, 1, 1, 1, 1)
|
||||||
|
}
|
||||||
|
// HELPER FUNCTIONS
|
||||||
|
fun test(expectedSum : Int, vararg data : Int) {
|
||||||
|
val actualSum = sum(data)
|
||||||
|
assertEquals(actualSum, expectedSum, "\ndata = ${Arrays.toString(data)}\n" +
|
||||||
|
"sum(data) = ${actualSum}, but must be $expectedSum ")
|
||||||
|
}
|
||||||
|
fun assertEquals<T>(actual : T?, expected : T?, message : Any? = null) {
|
||||||
|
if (actual != expected) {
|
||||||
|
if (message == null)
|
||||||
|
throw AssertionError()
|
||||||
|
else
|
||||||
|
throw AssertionError(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user