[IR] Report error from IR interpreter on field recursive initialization
#KT-59890 #KT-61802 Fixed
This commit is contained in:
+6
@@ -30,4 +30,10 @@ public class FirLightTreeWithInterpreterDiagnosticsTestGenerated extends Abstrac
|
|||||||
public void testExceptionFromInterpreter() throws Exception {
|
public void testExceptionFromInterpreter() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.kt");
|
runTest("compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("recursionAccess.kt")
|
||||||
|
public void testRecursionAccess() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/irInterpreter/recursionAccess.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -30,4 +30,10 @@ public class FirPsiWithInterpreterDiagnosticsTestGenerated extends AbstractFirPs
|
|||||||
public void testExceptionFromInterpreter() throws Exception {
|
public void testExceptionFromInterpreter() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.kt");
|
runTest("compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("recursionAccess.kt")
|
||||||
|
public void testRecursionAccess() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/irInterpreter/recursionAccess.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -14,7 +14,10 @@ import org.jetbrains.kotlin.ir.interpreter.fqName
|
|||||||
import org.jetbrains.kotlin.ir.interpreter.isAccessToNotNullableObject
|
import org.jetbrains.kotlin.ir.interpreter.isAccessToNotNullableObject
|
||||||
import org.jetbrains.kotlin.ir.interpreter.preprocessor.IrInterpreterKCallableNamePreprocessor.Companion.isEnumName
|
import org.jetbrains.kotlin.ir.interpreter.preprocessor.IrInterpreterKCallableNamePreprocessor.Companion.isEnumName
|
||||||
import org.jetbrains.kotlin.ir.interpreter.preprocessor.IrInterpreterKCallableNamePreprocessor.Companion.isKCallableNameCall
|
import org.jetbrains.kotlin.ir.interpreter.preprocessor.IrInterpreterKCallableNamePreprocessor.Companion.isKCallableNameCall
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||||
|
import org.jetbrains.kotlin.ir.types.isAny
|
||||||
|
import org.jetbrains.kotlin.ir.types.isPrimitiveType
|
||||||
|
import org.jetbrains.kotlin.ir.types.isStringClassType
|
||||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||||
import org.jetbrains.kotlin.ir.util.statements
|
import org.jetbrains.kotlin.ir.util.statements
|
||||||
@@ -180,6 +183,9 @@ class IrInterpreterCommonChecker : IrInterpreterChecker {
|
|||||||
(owner.type.isPrimitiveType() || owner.type.isStringClassType())
|
(owner.type.isPrimitiveType() || owner.type.isStringClassType())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We allow recursion access, but it will fail during interpretation. This way it is easier to implement error reporting.
|
||||||
|
if (visitedStack.contains(owner)) return true
|
||||||
|
|
||||||
return owner.asVisited {
|
return owner.asVisited {
|
||||||
when {
|
when {
|
||||||
// TODO fix later; used it here because java boolean resolves very strange,
|
// TODO fix later; used it here because java boolean resolves very strange,
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
/recursionAccess.kt:(180,194): error: Cannot evaluate constant expression: ???
|
||||||
|
|
||||||
|
/recursionAccess.kt:(280,283): error: Cannot evaluate constant expression: ???
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !RENDER_IR_DIAGNOSTICS_FULL_TEXT
|
||||||
|
// !LANGUAGE: +IntrinsicConstEvaluation
|
||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// WITH_STDLIB
|
||||||
|
|
||||||
|
object A {
|
||||||
|
const val recursive1: Int = 1 <!EVALUATION_ERROR!>+ B.recursive2<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
class B {
|
||||||
|
companion object {
|
||||||
|
const val recursive2: Int = A.recursive1 <!EVALUATION_ERROR!>+ 2<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user