KT-7507 Check expected type for class literal expression
This commit is contained in:
committed by
Alexander Udalov
parent
d540ff8890
commit
5dc28f1313
+3
-1
@@ -517,7 +517,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
public JetTypeInfo visitClassLiteralExpression(@NotNull JetClassLiteralExpression expression, ExpressionTypingContext c) {
|
public JetTypeInfo visitClassLiteralExpression(@NotNull JetClassLiteralExpression expression, ExpressionTypingContext c) {
|
||||||
JetType type = resolveClassLiteral(expression, c);
|
JetType type = resolveClassLiteral(expression, c);
|
||||||
if (type != null && !type.isError()) {
|
if (type != null && !type.isError()) {
|
||||||
return TypeInfoFactoryPackage.createTypeInfo(components.reflectionTypes.getKClassType(Annotations.EMPTY, type), c);
|
return TypeInfoFactoryPackage.createCheckedTypeInfo(
|
||||||
|
components.reflectionTypes.getKClassType(Annotations.EMPTY, type), c, expression
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TypeInfoFactoryPackage.createTypeInfo(ErrorUtils.createErrorType("Unresolved class"), c);
|
return TypeInfoFactoryPackage.createTypeInfo(ErrorUtils.createErrorType("Unresolved class"), c);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
class A
|
||||||
|
class B
|
||||||
|
|
||||||
|
val a1 : KClass<*> = A::class
|
||||||
|
val a2 : KClass<A> = A::class
|
||||||
|
val a3 : KClass<B> = <!TYPE_MISMATCH!>A::class<!>
|
||||||
|
val a4 : B = <!TYPE_MISMATCH!>A::class<!>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal val a1: kotlin.reflect.KClass<*>
|
||||||
|
internal val a2: kotlin.reflect.KClass<A>
|
||||||
|
internal val a3: kotlin.reflect.KClass<B>
|
||||||
|
internal val a4: B
|
||||||
|
|
||||||
|
internal final class A {
|
||||||
|
public constructor A()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class B {
|
||||||
|
public constructor B()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -2031,6 +2031,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classLiteralType.kt")
|
||||||
|
public void testClassLiteralType() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classLiteral/classLiteralType.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericClasses.kt")
|
@TestMetadata("genericClasses.kt")
|
||||||
public void testGenericClasses() throws Exception {
|
public void testGenericClasses() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classLiteral/genericClasses.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classLiteral/genericClasses.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user