Fix exception from ::class literals on unresolved classes
This commit is contained in:
+8
-4
@@ -452,11 +452,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitClassLiteralExpression(@NotNull JetClassLiteralExpression expression, ExpressionTypingContext c) {
|
public JetTypeInfo visitClassLiteralExpression(@NotNull JetClassLiteralExpression expression, ExpressionTypingContext c) {
|
||||||
ClassDescriptor descriptor = resolveClassLiteral(expression, c);
|
ClassDescriptor descriptor = resolveClassLiteral(expression, c);
|
||||||
JetType type = descriptor == null
|
if (descriptor != null && !ErrorUtils.isError(descriptor)) {
|
||||||
? ErrorUtils.createErrorType("Unresolved class")
|
JetType type = components.reflectionTypes.getKClassType(Annotations.EMPTY, descriptor);
|
||||||
: components.reflectionTypes.getKClassType(Annotations.EMPTY, descriptor);
|
if (!type.isError()) {
|
||||||
|
return JetTypeInfo.create(type, c.dataFlowInfo);
|
||||||
|
}
|
||||||
|
c.trace.report(REFLECTION_TYPES_NOT_LOADED.on(expression.getDoubleColonTokenReference()));
|
||||||
|
}
|
||||||
|
|
||||||
return JetTypeInfo.create(type, c.dataFlowInfo);
|
return JetTypeInfo.create(ErrorUtils.createErrorType("Unresolved class"), c.dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -60,13 +60,19 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
public val kMutableTopLevelExtensionProperty: ClassDescriptor by ClassLookup
|
public val kMutableTopLevelExtensionProperty: ClassDescriptor by ClassLookup
|
||||||
|
|
||||||
public fun getKClassType(annotations: Annotations, classDescriptor: ClassDescriptor): JetType {
|
public fun getKClassType(annotations: Annotations, classDescriptor: ClassDescriptor): JetType {
|
||||||
|
val kClassDescriptor = kClass
|
||||||
|
if (ErrorUtils.isError(kClassDescriptor)) {
|
||||||
|
return kClassDescriptor.getDefaultType()
|
||||||
|
}
|
||||||
|
|
||||||
val typeConstructor = classDescriptor.getTypeConstructor()
|
val typeConstructor = classDescriptor.getTypeConstructor()
|
||||||
val arguments = typeConstructor.getParameters().map(TypeUtils::makeStarProjection)
|
val arguments = typeConstructor.getParameters().map(TypeUtils::makeStarProjection)
|
||||||
val kClassArguments = listOf(TypeProjectionImpl(
|
val kClassArguments = listOf(TypeProjectionImpl(
|
||||||
Variance.INVARIANT,
|
Variance.INVARIANT,
|
||||||
JetTypeImpl(Annotations.EMPTY, typeConstructor, false, arguments, classDescriptor.getMemberScope(arguments))
|
JetTypeImpl(Annotations.EMPTY, typeConstructor, false, arguments, classDescriptor.getMemberScope(arguments))
|
||||||
))
|
))
|
||||||
return JetTypeImpl(annotations, kClass.getTypeConstructor(), false, kClassArguments, kClass.getMemberScope(kClassArguments))
|
return JetTypeImpl(annotations, kClassDescriptor.getTypeConstructor(), false, kClassArguments,
|
||||||
|
kClassDescriptor.getMemberScope(kClassArguments))
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getKFunctionType(
|
public fun getKFunctionType(
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
fun foo() {}
|
fun foo() {}
|
||||||
|
|
||||||
class A {
|
class A(val prop: Any) {
|
||||||
fun baz() {}
|
fun baz() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
val bar = <!REFLECTION_TYPES_NOT_LOADED!>::<!>foo
|
val topLevelFun = <!REFLECTION_TYPES_NOT_LOADED!>::<!>foo
|
||||||
val quux = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>baz
|
val memberFun = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>baz
|
||||||
|
|
||||||
|
val classLiteral = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>class
|
||||||
|
val property = A<!REFLECTION_TYPES_NOT_LOADED!>::<!>prop
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package
|
package
|
||||||
|
|
||||||
internal val bar: [ERROR : Type for ::foo]
|
internal val classLiteral: [ERROR : Unresolved class]
|
||||||
internal val quux: [ERROR : Type for A::baz]
|
internal val memberFun: [ERROR : Type for A::baz]
|
||||||
|
internal val property: [ERROR : Type for A::prop]
|
||||||
|
internal val topLevelFun: [ERROR : Type for ::foo]
|
||||||
internal fun foo(): kotlin.Unit
|
internal fun foo(): kotlin.Unit
|
||||||
|
|
||||||
internal final class A {
|
internal final class A {
|
||||||
public constructor A()
|
public constructor A(/*0*/ prop: kotlin.Any)
|
||||||
|
internal final val prop: kotlin.Any
|
||||||
internal final fun baz(): kotlin.Unit
|
internal final fun baz(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
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 hashCode(): kotlin.Int
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val u = <!UNRESOLVED_REFERENCE!>Unresolved<!>::class
|
||||||
|
val g = <!UNRESOLVED_REFERENCE!>UnresolvedGeneric<!><<!UNRESOLVED_REFERENCE!>UnresolvedTypeArg<!>>::class
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal val g: [ERROR : Unresolved class]
|
||||||
|
internal val u: [ERROR : Unresolved class]
|
||||||
+6
@@ -630,6 +630,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/classLiteral/simpleClassLiteral.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/classLiteral/simpleClassLiteral.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unresolvedClass.kt")
|
||||||
|
public void testUnresolvedClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/classLiteral/unresolvedClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
||||||
|
|||||||
Reference in New Issue
Block a user