Types for jump expressions
This commit is contained in:
@@ -17,9 +17,29 @@ import java.util.Map;
|
||||
public class JetTypeChecker {
|
||||
public static final JetTypeChecker INSTANCE = new JetTypeChecker();
|
||||
|
||||
/*
|
||||
: jump
|
||||
: if
|
||||
: when
|
||||
: try
|
||||
: functionLiteral
|
||||
: "this" ("<" type ">")?
|
||||
: "typeof" "(" expression ")"
|
||||
: "new" constructorInvocation
|
||||
: objectLiteral
|
||||
: declaration
|
||||
: loop
|
||||
: SimpleName
|
||||
: "namespace" // for the root namespace
|
||||
*/
|
||||
public Type getType(JetExpression expression) {
|
||||
final Type[] result = new Type[1];
|
||||
expression.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitParenthesizedExpression(JetParenthesizedExpression expression) {
|
||||
result[0] = getType(expression.getExpression());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConstantExpression(JetConstantExpression expression) {
|
||||
IElementType elementType = expression.getNode().getElementType();
|
||||
@@ -49,6 +69,31 @@ public class JetTypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThrowExpression(JetThrowExpression expression) {
|
||||
result[0] = JetStandardClasses.getNothingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReturnExpression(JetReturnExpression expression) {
|
||||
result[0] = JetStandardClasses.getNothingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBreakExpression(JetBreakExpression expression) {
|
||||
result[0] = JetStandardClasses.getNothingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitContinueExpression(JetContinueExpression expression) {
|
||||
result[0] = JetStandardClasses.getNothingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeofExpression(JetTypeofExpression expression) {
|
||||
throw new UnsupportedOperationException("Return some reflection interface"); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTupleExpression(JetTupleExpression expression) {
|
||||
List<JetExpression> entries = expression.getEntries();
|
||||
@@ -56,6 +101,7 @@ public class JetTypeChecker {
|
||||
for (JetExpression entry : entries) {
|
||||
types.add(getType(entry));
|
||||
}
|
||||
// TODO : labels
|
||||
result[0] = JetStandardClasses.getTupleType(types);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,16 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
assertType("(1, 'a')", JetStandardClasses.getTupleType(JetStandardClasses.getIntType(), JetStandardClasses.getCharType()));
|
||||
}
|
||||
|
||||
public void testJumps() throws Exception {
|
||||
assertType("throw e", JetStandardClasses.getNothingType());
|
||||
assertType("return", JetStandardClasses.getNothingType());
|
||||
assertType("return 1", JetStandardClasses.getNothingType());
|
||||
assertType("continue", JetStandardClasses.getNothingType());
|
||||
assertType("continue \"foo\"", JetStandardClasses.getNothingType());
|
||||
assertType("break", JetStandardClasses.getNothingType());
|
||||
assertType("break \"foo\"", JetStandardClasses.getNothingType());
|
||||
}
|
||||
|
||||
public void testBasicSubtyping() throws Exception {
|
||||
assertSubtype("Boolean", "Boolean");
|
||||
assertSubtype("Byte", "Byte");
|
||||
@@ -120,17 +130,17 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
assertSubtype("(Short)", "(Short)");
|
||||
assertSubtype("(Int)", "(Int)");
|
||||
assertSubtype("(Long)", "(Long)");
|
||||
assertSubtype("(Float)", "(Float)");
|
||||
assertSubtype("(Double)", "(Double)");
|
||||
assertSubtype("(Unit)", "(Unit)");
|
||||
assertSubtype("(Unit, Unit)", "(Unit, Unit)");
|
||||
assertSubtype("(Float)", "(Float)");
|
||||
assertSubtype("(Double)", "(Double)");
|
||||
assertSubtype("(Unit)", "(Unit)");
|
||||
assertSubtype("(Unit, Unit)", "(Unit, Unit)");
|
||||
|
||||
assertNotSubtype("(Unit)", "(Int)");
|
||||
|
||||
assertSubtype("(Unit)", "(Any)");
|
||||
assertSubtype("(Unit, Unit)", "(Any, Any)");
|
||||
assertSubtype("(Unit, Unit)", "(Any, Unit)");
|
||||
assertSubtype("(Unit, Unit)", "(Unit, Any)");
|
||||
assertSubtype("(Unit)", "(Any)");
|
||||
assertSubtype("(Unit, Unit)", "(Any, Any)");
|
||||
assertSubtype("(Unit, Unit)", "(Any, Unit)");
|
||||
assertSubtype("(Unit, Unit)", "(Unit, Any)");
|
||||
}
|
||||
|
||||
public void testProjections() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user