typeof() supported

This commit is contained in:
Andrey Breslav
2011-05-13 15:18:45 +04:00
parent 5c2e90345a
commit d9bbecfaee
3 changed files with 20 additions and 1 deletions
@@ -50,6 +50,7 @@ public class JetStandardLibrary {
private final ClassDescriptor stringClass;
private final ClassDescriptor arrayClass;
private final ClassDescriptor iterableClass;
private final ClassDescriptor typeInfoClass;
private final JetType byteType;
private final JetType charType;
@@ -86,6 +87,7 @@ public class JetStandardLibrary {
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
this.typeInfoClass = (ClassDescriptor) libraryScope.getClassifier("TypeInfo");
this.byteType = new JetTypeImpl(getByte());
this.charType = new JetTypeImpl(getChar());
@@ -161,6 +163,17 @@ public class JetStandardLibrary {
return iterableClass;
}
public ClassDescriptor getTypeInfo() {
return typeInfoClass;
}
@NotNull
public JetType getTypeInfoType(@NotNull JetType type) {
TypeProjection typeProjection = new TypeProjection(type);
List<TypeProjection> arguments = Collections.singletonList(typeProjection);
return new JetTypeImpl(Collections.<Annotation>emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments));
}
@NotNull
public JetType getIntType() {
return intType;
@@ -814,7 +814,8 @@ public class JetTypeInferrer {
@Override
public void visitTypeofExpression(JetTypeofExpression expression) {
trace.getErrorHandler().genericError(expression.getNode(), "Return some reflection interface"); // TODO
JetType type = safeGetType(scope, expression.getBaseExpression(), false);
result = semanticServices.getStandardLibrary().getTypeInfoType(type);
}
@Override
@@ -81,6 +81,11 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
assertType("(1, 'a')", JetStandardClasses.getTupleType(library.getIntType(), library.getCharType()));
}
public void testTypeInfo() throws Exception {
assertType("typeof(1)", "TypeInfo<Int>");
assertType("typeof(typeof(1))", "TypeInfo<TypeInfo<Int>>");
}
public void testJumps() throws Exception {
assertType("throw e", JetStandardClasses.getNothingType());
assertType("return", JetStandardClasses.getNothingType());