diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendErrors.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendErrors.kt index 911db5624c8..04038bc4c53 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendErrors.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CommonBackendErrors.kt @@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.EXPECT_ACTUAL_ANNOTATION_INCOMPATIBILITY import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.INCOMPATIBILITY import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.DECLARATION_NAME +import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.EVALUATION_ERROR_EXPLANATION import org.jetbrains.kotlin.backend.common.BackendDiagnosticRenderers.SYMBOL_OWNER_DECLARATION_FQ_NAME import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.diagnostics.* @@ -64,7 +65,7 @@ object KtDefaultCommonBackendErrorMessages : BaseDiagnosticRendererFactory() { map.put( CommonBackendErrors.EVALUATION_ERROR, "Cannot evaluate constant expression: {0}", - STRING, + EVALUATION_ERROR_EXPLANATION, ) map.put( CommonBackendErrors.ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE, @@ -91,4 +92,16 @@ object BackendDiagnosticRenderers { "Annotation `$expectAnnotationFqName` $reason" } val DECLARATION_NAME = Renderer { it.name.asString() } + val EVALUATION_ERROR_EXPLANATION = Renderer { + val result = Regex("Exception (\\S+)(: (.*))?").matchEntire(it)?.groupValues + val exceptionName = result?.getOrNull(1) + val message = result?.getOrNull(3) + when { + !message.isNullOrBlank() -> message + exceptionName == StackOverflowError::class.java.name -> "stack overflow (potentially due to infinite recursion)" + exceptionName == NullPointerException::class.java.name -> "null reference access" + exceptionName != null -> exceptionName.split('.').last() + else -> it + } + } } diff --git a/compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.fir.ir.diag.txt b/compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.fir.ir.diag.txt index 70c7990b1aa..421f6af106c 100644 --- a/compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.fir.ir.diag.txt +++ b/compiler/testData/diagnostics/irInterpreter/exceptionFromInterpreter.fir.ir.diag.txt @@ -1,5 +1,5 @@ -/exceptionFromInterpreter.kt:(195,200): error: Cannot evaluate constant expression: Exception java.lang.ArithmeticException: / by zero +/exceptionFromInterpreter.kt:(195,200): error: Cannot evaluate constant expression: / by zero -/exceptionFromInterpreter.kt:(239,254): error: Cannot evaluate constant expression: Exception java.lang.IllegalArgumentException: marginPrefix must be non-blank string. +/exceptionFromInterpreter.kt:(239,254): error: Cannot evaluate constant expression: marginPrefix must be non-blank string. -/exceptionFromInterpreter.kt:(303,308): error: Cannot evaluate constant expression: Exception java.lang.ArithmeticException: / by zero +/exceptionFromInterpreter.kt:(303,308): error: Cannot evaluate constant expression: / by zero diff --git a/compiler/testData/diagnostics/irInterpreter/recursionAccess.fir.ir.diag.txt b/compiler/testData/diagnostics/irInterpreter/recursionAccess.fir.ir.diag.txt index 7c6f0c7e029..8496ce9582d 100644 --- a/compiler/testData/diagnostics/irInterpreter/recursionAccess.fir.ir.diag.txt +++ b/compiler/testData/diagnostics/irInterpreter/recursionAccess.fir.ir.diag.txt @@ -1,3 +1,3 @@ -/recursionAccess.kt:(178,194): error: Cannot evaluate constant expression: Exception java.lang.StackOverflowError +/recursionAccess.kt:(178,194): error: Cannot evaluate constant expression: stack overflow (potentially due to infinite recursion) -/recursionAccess.kt:(267,283): error: Cannot evaluate constant expression: Exception java.lang.NullPointerException +/recursionAccess.kt:(267,283): error: Cannot evaluate constant expression: null reference access