Fix NPE in KtSourceElement.elementType #KT-44152 Fixed

This commit is contained in:
Mikhail Glukhikh
2022-03-10 08:40:38 +03:00
committed by Space
parent 8c7a8edb75
commit 4178c8156a
4 changed files with 33 additions and 4 deletions
@@ -46857,6 +46857,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
}
@Test
@TestMetadata("kt44152.kt")
public void testKt44152() throws Exception {
runTest("compiler/testData/codegen/box/toArray/kt44152.kt");
}
@Test
@TestMetadata("returnToTypedArray.kt")
public void testReturnToTypedArray() throws Exception {
@@ -221,7 +221,7 @@ class KtOffsetsOnlySourceElement(
// TODO: consider renaming to something like AstBasedSourceElement
sealed class KtSourceElement : AbstractKtSourceElement() {
abstract val elementType: IElementType
abstract val elementType: IElementType?
abstract val kind: KtSourceElementKind
abstract val lighterASTNode: LighterASTNode
abstract val treeStructure: FlyweightCapableTreeStructure<LighterASTNode>
@@ -233,11 +233,11 @@ sealed class KtSourceElement : AbstractKtSourceElement() {
abstract override fun equals(other: Any?): Boolean
}
// NB: in certain situations, psi.node could be null
// NB: in certain situations, psi.node could be null (see e.g. KT-44152)
// Potentially exceptions can be provoked by elementType / lighterASTNode
sealed class KtPsiSourceElement(val psi: PsiElement) : KtSourceElement() {
override val elementType: IElementType
get() = psi.node.elementType
override val elementType: IElementType?
get() = psi.node?.elementType
override val startOffset: Int
get() = psi.textRange.startOffset
+17
View File
@@ -0,0 +1,17 @@
// SKIP_JDK6
// TARGET_BACKEND: JVM_IR
// FULL_JDK
// WITH_STDLIB
// USE_PSI_CLASS_FILES_READING
// Based on incorrectToArrayDetection.kt
import java.lang.reflect.Modifier
abstract class A : Collection<String> {
protected fun <T> foo(x: Array<T>): Array<T> = x
}
fun box(): String {
val method = A::class.java.declaredMethods.single { it.name == "foo" }
return if (Modifier.isProtected(method.modifiers)) "OK" else "Fail: $method"
}
@@ -46857,6 +46857,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
}
@Test
@TestMetadata("kt44152.kt")
public void testKt44152() throws Exception {
runTest("compiler/testData/codegen/box/toArray/kt44152.kt");
}
@Test
@TestMetadata("returnToTypedArray.kt")
public void testReturnToTypedArray() throws Exception {