Add improved compiler error reporting util
This commit is contained in:
committed by
SvyatoslavScherbina
parent
ba212bddba
commit
79e36a31cf
+20
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.konan
|
|||||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
|
|
||||||
internal fun CommonBackendContext.reportCompilationError(message: String, irFile: IrFile, irElement: IrElement): Nothing {
|
internal fun CommonBackendContext.reportCompilationError(message: String, irFile: IrFile, irElement: IrElement): Nothing {
|
||||||
report(irElement, irFile, message, true)
|
report(irElement, irFile, message, true)
|
||||||
@@ -22,3 +23,22 @@ internal fun CommonBackendContext.reportCompilationError(message: String): Nothi
|
|||||||
internal fun CommonBackendContext.reportCompilationWarning(message: String) {
|
internal fun CommonBackendContext.reportCompilationWarning(message: String) {
|
||||||
report(null, null, message, false)
|
report(null, null, message, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun error(irFile: IrFile, element: IrElement?, message: String): Nothing {
|
||||||
|
error(buildString {
|
||||||
|
append("Internal compiler error: $message\n")
|
||||||
|
if (element == null) {
|
||||||
|
append("(IR element is null)")
|
||||||
|
} else {
|
||||||
|
val location = element.getCompilerMessageLocation(irFile)
|
||||||
|
append("at $location\n")
|
||||||
|
|
||||||
|
val renderedElement = try {
|
||||||
|
element.render()
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
"(unable to render IR element)"
|
||||||
|
}
|
||||||
|
append(renderedElement)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user