Fix NPE in KtSourceElement.elementType #KT-44152 Fixed
This commit is contained in:
+6
@@ -46857,6 +46857,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
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
|
@Test
|
||||||
@TestMetadata("returnToTypedArray.kt")
|
@TestMetadata("returnToTypedArray.kt")
|
||||||
public void testReturnToTypedArray() throws Exception {
|
public void testReturnToTypedArray() throws Exception {
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ class KtOffsetsOnlySourceElement(
|
|||||||
|
|
||||||
// TODO: consider renaming to something like AstBasedSourceElement
|
// TODO: consider renaming to something like AstBasedSourceElement
|
||||||
sealed class KtSourceElement : AbstractKtSourceElement() {
|
sealed class KtSourceElement : AbstractKtSourceElement() {
|
||||||
abstract val elementType: IElementType
|
abstract val elementType: IElementType?
|
||||||
abstract val kind: KtSourceElementKind
|
abstract val kind: KtSourceElementKind
|
||||||
abstract val lighterASTNode: LighterASTNode
|
abstract val lighterASTNode: LighterASTNode
|
||||||
abstract val treeStructure: FlyweightCapableTreeStructure<LighterASTNode>
|
abstract val treeStructure: FlyweightCapableTreeStructure<LighterASTNode>
|
||||||
@@ -233,11 +233,11 @@ sealed class KtSourceElement : AbstractKtSourceElement() {
|
|||||||
abstract override fun equals(other: Any?): Boolean
|
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
|
// Potentially exceptions can be provoked by elementType / lighterASTNode
|
||||||
sealed class KtPsiSourceElement(val psi: PsiElement) : KtSourceElement() {
|
sealed class KtPsiSourceElement(val psi: PsiElement) : KtSourceElement() {
|
||||||
override val elementType: IElementType
|
override val elementType: IElementType?
|
||||||
get() = psi.node.elementType
|
get() = psi.node?.elementType
|
||||||
|
|
||||||
override val startOffset: Int
|
override val startOffset: Int
|
||||||
get() = psi.textRange.startOffset
|
get() = psi.textRange.startOffset
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
+6
@@ -46857,6 +46857,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt");
|
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
|
@Test
|
||||||
@TestMetadata("returnToTypedArray.kt")
|
@TestMetadata("returnToTypedArray.kt")
|
||||||
public void testReturnToTypedArray() throws Exception {
|
public void testReturnToTypedArray() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user