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) {
@@ -0,0 +1,2 @@
// expected: rv: null
+8
View File
@@ -0,0 +1,8 @@
>>>
null
>>> 101
101
>>>
null
>>> 102
102
@@ -82,4 +82,8 @@ public class ScriptGenTest extends CodegenTestCase {
blackBoxFile("script/parameterClosure.ktscript");
}
public void testEmpty() {
blackBoxFile("script/empty.ktscript");
}
}
@@ -92,5 +92,10 @@ public class ReplInterpreterTest {
testFile("twoClosures.repl");
}
@Test
public void empty() {
testFile("empty.repl");
}
}
@@ -26,6 +26,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Stepan Koltsov
@@ -66,10 +68,12 @@ public class ReplSessionTestFile {
return new ReplSessionTestFile(list);
}
if (!odd.startsWith(">>> ")) {
Pattern pattern = Pattern.compile(">>>( |$)(.*)");
Matcher matcher = pattern.matcher(odd);
if (!matcher.matches()) {
throw new IllegalStateException("odd lines must start with >>>");
}
String code = odd.substring(4);
String code = matcher.group(2);
String even = reader.readLine();
if (even == null) {