Kotlin: Catch exception thrown by kotlinc

This commit is contained in:
Tamas Vajk
2022-09-08 14:09:18 +02:00
parent ac307137ad
commit 824ba6ed2a
2 changed files with 13 additions and 6 deletions

View File

@@ -97,8 +97,15 @@ open class KotlinFileExtractor(
if (d.isFakeOverride) {
return true
}
if ((d as? IrFunction)?.descriptor?.isHiddenToOvercomeSignatureClash == true) {
return true
try {
if ((d as? IrFunction)?.descriptor?.isHiddenToOvercomeSignatureClash == true) {
return true
}
}
catch (e: NotImplementedError) {
// `org.jetbrains.kotlin.ir.descriptors.IrBasedClassConstructorDescriptor.isHiddenToOvercomeSignatureClash` throws the exception
logger.warnElement("Couldn't query if element is fake, deciding it's not.", d, e)
return false
}
return false
}

View File

@@ -248,15 +248,15 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
}
class FileLogger(loggerBase: LoggerBase, override val tw: FileTrapWriter): Logger(loggerBase, tw) {
fun warnElement(msg: String, element: IrElement) {
fun warnElement(msg: String, element: IrElement, exn: Throwable? = null) {
val locationString = tw.getLocationString(element)
val mkLocationId = { tw.getLocation(element) }
loggerBase.diagnostic(tw, Severity.Warn, msg, null, locationString, mkLocationId)
loggerBase.diagnostic(tw, Severity.Warn, msg, exn?.stackTraceToString(), locationString, mkLocationId)
}
fun errorElement(msg: String, element: IrElement) {
fun errorElement(msg: String, element: IrElement, exn: Throwable? = null) {
val locationString = tw.getLocationString(element)
val mkLocationId = { tw.getLocation(element) }
loggerBase.diagnostic(tw, Severity.Error, msg, null, locationString, mkLocationId)
loggerBase.diagnostic(tw, Severity.Error, msg, exn?.stackTraceToString(), locationString, mkLocationId)
}
}