提交 84f32c99 编写于 作者: S Svetlana Isakova

incomplete assignment bug from EA fixed

上级 091d8176
......@@ -169,6 +169,9 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
}
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)
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(contextWithExpectedType.trace);
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);
if (leftType == null) {
facade.getType(expression.getRight(), context);
facade.getType(right, context);
context.trace.report(UNRESOLVED_REFERENCE.on(operationSign));
temporaryBindingTrace.commit();
return null;
......@@ -208,7 +211,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
for (ResolvedCall<? extends FunctionDescriptor> call : ambiguityResolutionResults.getResultingCalls()) {
descriptors.add(call.getResultingDescriptor());
}
facade.getType(expression.getRight(), context);
facade.getType(right, context);
context.trace.record(AMBIGUOUS_REFERENCE_TARGET, operationSign, descriptors);
}
else if (assignmentOperationType != null) {
......@@ -222,7 +225,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
context.trace.record(VARIABLE_REASSIGNMENT, expression);
if (left instanceof JetArrayAccessExpression) {
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());
......
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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册