properly handle empty lines in REPL

This commit is contained in:
Stepan Koltsov
2012-06-09 23:25:41 +04:00
parent f11767319a
commit b0553ff651
6 changed files with 33 additions and 6 deletions
@@ -177,9 +177,6 @@ public class ExpressionTypingServices {
@Nullable
public JetType getBlockReturnedType(@NotNull JetScope outerScope, @NotNull JetBlockExpression expression, @NotNull CoercionStrategy coercionStrategyForLastExpression, ExpressionTypingContext context, BindingTrace trace) {
List<JetElement> block = expression.getStatements();
if (block.isEmpty()) {
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, context);
}
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
if (containingDescriptor instanceof ScriptDescriptor) {
@@ -192,7 +189,14 @@ public class ExpressionTypingServices {
WritableScope scope = new WritableScopeImpl(
outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace), "getBlockReturnedType");
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
JetType r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);
JetType r;
if (block.isEmpty()) {
r = DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, context);
}
else {
r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);
}
scope.changeLockLevel(WritableScope.LockLevel.READING);
if (containingDescriptor instanceof ScriptDescriptor) {