提交 d9bbecfa 编写于 作者: A Andrey Breslav

typeof() supported

上级 5c2e9034
......@@ -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());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册