typeof() supported
This commit is contained in:
@@ -50,6 +50,7 @@ public class JetStandardLibrary {
|
|||||||
private final ClassDescriptor stringClass;
|
private final ClassDescriptor stringClass;
|
||||||
private final ClassDescriptor arrayClass;
|
private final ClassDescriptor arrayClass;
|
||||||
private final ClassDescriptor iterableClass;
|
private final ClassDescriptor iterableClass;
|
||||||
|
private final ClassDescriptor typeInfoClass;
|
||||||
private final JetType byteType;
|
private final JetType byteType;
|
||||||
|
|
||||||
private final JetType charType;
|
private final JetType charType;
|
||||||
@@ -86,6 +87,7 @@ public class JetStandardLibrary {
|
|||||||
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
||||||
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
||||||
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
||||||
|
this.typeInfoClass = (ClassDescriptor) libraryScope.getClassifier("TypeInfo");
|
||||||
|
|
||||||
this.byteType = new JetTypeImpl(getByte());
|
this.byteType = new JetTypeImpl(getByte());
|
||||||
this.charType = new JetTypeImpl(getChar());
|
this.charType = new JetTypeImpl(getChar());
|
||||||
@@ -161,6 +163,17 @@ public class JetStandardLibrary {
|
|||||||
return iterableClass;
|
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
|
@NotNull
|
||||||
public JetType getIntType() {
|
public JetType getIntType() {
|
||||||
return intType;
|
return intType;
|
||||||
|
|||||||
@@ -814,7 +814,8 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitTypeofExpression(JetTypeofExpression expression) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -81,6 +81,11 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
|||||||
assertType("(1, 'a')", JetStandardClasses.getTupleType(library.getIntType(), library.getCharType()));
|
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 {
|
public void testJumps() throws Exception {
|
||||||
assertType("throw e", JetStandardClasses.getNothingType());
|
assertType("throw e", JetStandardClasses.getNothingType());
|
||||||
assertType("return", JetStandardClasses.getNothingType());
|
assertType("return", JetStandardClasses.getNothingType());
|
||||||
|
|||||||
Reference in New Issue
Block a user