diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index 8f9424acf64..2343a383dba 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -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 block; + if (body instanceof JetBlockExpression) { + block = ((JetBlockExpression)body).getStatements(); + } + else { + block = Collections.singletonList(body); + } + context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context); } JetExpression condition = expression.getCondition(); checkCondition(conditionScope, condition, context); diff --git a/compiler/testData/diagnostics/tests/scopes/kt1078.jet b/compiler/testData/diagnostics/tests/scopes/kt1078.jet new file mode 100644 index 00000000000..2667028763e --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/kt1078.jet @@ -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() \ No newline at end of file