Always create descriptors for class object psi element in lazy resolve
KT-4397 Exception: @NotNull method org/jetbrains/jet/lang/resolve/lazy/ResolveSession.getClassDescriptor must not return null #KT-4397 Fixed
This commit is contained in:
@@ -214,7 +214,8 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
return (ClassDescriptor) declaration;
|
||||
}
|
||||
|
||||
/*package*/ LazyClassDescriptor getClassObjectDescriptor(JetClassObject classObject) {
|
||||
@NotNull
|
||||
/*package*/ LazyClassDescriptor getClassObjectDescriptor(@NotNull JetClassObject classObject) {
|
||||
JetClass aClass = PsiTreeUtil.getParentOfType(classObject, JetClass.class);
|
||||
|
||||
final LazyClassDescriptor parentClassDescriptor;
|
||||
@@ -237,16 +238,18 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
// It's possible that there are several class objects and another class object is taking part in lazy resolve. We still want to
|
||||
// build descriptors for such class objects.
|
||||
final JetClassLikeInfo classObjectInfo = parentClassDescriptor.getClassObjectInfo(classObject);
|
||||
if (classObjectInfo != null) {
|
||||
final Name name = SpecialNames.getClassObjectName(parentClassDescriptor.getName());
|
||||
return storageManager.compute(new Function0<LazyClassDescriptor>() {
|
||||
@Override
|
||||
public LazyClassDescriptor invoke() {
|
||||
// Create under lock to avoid premature access to published 'this'
|
||||
return new LazyClassDescriptor(ResolveSession.this, parentClassDescriptor, name, classObjectInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
assert classObjectInfo != null :
|
||||
String.format("Failed to find class object info for existent class object declaration: %s",
|
||||
JetPsiUtil.getElementTextWithContext(classObject));
|
||||
|
||||
final Name name = SpecialNames.getClassObjectName(parentClassDescriptor.getName());
|
||||
return storageManager.compute(new Function0<LazyClassDescriptor>() {
|
||||
@Override
|
||||
public LazyClassDescriptor invoke() {
|
||||
// Create under lock to avoid premature access to published 'this'
|
||||
return new LazyClassDescriptor(ResolveSession.this, parentClassDescriptor, name, classObjectInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (LazyClassDescriptor) declaration;
|
||||
|
||||
+1
-3
@@ -258,9 +258,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
@Nullable
|
||||
public JetClassLikeInfo getClassObjectInfo(JetClassObject classObject) {
|
||||
if (classObject != null) {
|
||||
if (!DescriptorUtils.inStaticContext(this)) {
|
||||
return null;
|
||||
}
|
||||
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
|
||||
if (objectDeclaration != null) {
|
||||
return JetClassInfoUtil.createClassLikeInfo(objectDeclaration);
|
||||
@@ -269,6 +266,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
else if (getKind() == ClassKind.OBJECT || getKind() == ClassKind.ENUM_ENTRY || getKind() == ClassKind.ENUM_CLASS) {
|
||||
return new SyntheticClassObjectInfo(originalClassInfo, this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
class A {
|
||||
class B {
|
||||
class object {
|
||||
val TEST = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package test
|
||||
|
||||
internal final class A {
|
||||
/*primary*/ public constructor A()
|
||||
|
||||
internal final class B {
|
||||
/*primary*/ public constructor B()
|
||||
|
||||
internal class object <class-object-for-B> {
|
||||
/*primary*/ private constructor <class-object-for-B>()
|
||||
internal final val TEST: jet.Int
|
||||
internal final fun <get-TEST>(): jet.Int
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1577,6 +1577,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassObjectInStaticNestedClass.kt")
|
||||
public void testClassObjectInStaticNestedClass() throws Exception {
|
||||
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Deprecated.kt")
|
||||
public void testDeprecated() throws Exception {
|
||||
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt");
|
||||
|
||||
+5
@@ -105,6 +105,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassObjectInStaticNestedClass.kt")
|
||||
public void testClassObjectInStaticNestedClass() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Deprecated.kt")
|
||||
public void testDeprecated() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt");
|
||||
|
||||
Reference in New Issue
Block a user