KT-1078 Problem with visibility in do-while

This commit is contained in:
svtk
2012-01-20 14:52:48 +04:00
parent b4b1ec1bb5
commit 8ec8fa47a4
2 changed files with 28 additions and 2 deletions
@@ -20,7 +20,10 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.jet.lang.types.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
@@ -182,7 +185,14 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
else if (body != null) {
WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope");
conditionScope = writableScope;
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context);
List<JetElement> block;
if (body instanceof JetBlockExpression) {
block = ((JetBlockExpression)body).getStatements();
}
else {
block = Collections.<JetElement>singletonList(body);
}
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context);
}
JetExpression condition = expression.getCondition();
checkCondition(conditionScope, condition, context);
@@ -0,0 +1,16 @@
//KT-1078 Problem with visibility in do-while
package kt1078
fun test() : B {
do {
val x = foo()
} while(x.bar()) // x is not visible here!
return B()
}
class B() {
fun bar() = true
}
fun foo() = B()