diff --git a/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 2cff5d852e2..e64977081e3 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -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 arguments = Collections.singletonList(typeProjection); + return new JetTypeImpl(Collections.emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments)); + } + @NotNull public JetType getIntType() { return intType; diff --git a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index b9cf1d46d9d..807c2c002e9 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -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 diff --git a/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java b/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java index 9bf20387b0b..762fca93e9a 100644 --- a/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java +++ b/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java @@ -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"); + assertType("typeof(typeof(1))", "TypeInfo>"); + } + public void testJumps() throws Exception { assertType("throw e", JetStandardClasses.getNothingType()); assertType("return", JetStandardClasses.getNothingType());