[FIR] KTIJ-23973: Prevent SourceCodeAnalysisException wrapping
^KTIJ-23973 Fixed
diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt
index 10074e5..699ffee 100644
--- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt
+++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt
@@ -34,7 +34,7 @@
import org.jetbrains.kotlin.serialization.deserialization.getClassId
import org.jetbrains.kotlin.serialization.deserialization.getName
import org.jetbrains.kotlin.types.Variance
-import org.jetbrains.kotlin.util.shouldIjPlatformExceptionBeRethrown
+import org.jetbrains.kotlin.util.mapThrowable
class FirTypeDeserializer(
val moduleData: FirModuleData,
@@ -102,8 +102,9 @@
val id = nameResolver.getClassId(fqNameIndex).takeIf { !it.isLocal } ?: StandardClassIds.Any
return ConeClassLikeLookupTagImpl(id)
} catch (e: Throwable) {
- if (shouldIjPlatformExceptionBeRethrown(e)) throw e
- throw RuntimeException("Looking up for ${nameResolver.getClassId(fqNameIndex)}", e)
+ throw mapThrowable(e) {
+ RuntimeException("Looking up for ${nameResolver.getClassId(fqNameIndex)}", it)
+ }
}
}
diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt
index c70c97a..469d484 100644
--- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt
+++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt
@@ -25,7 +25,7 @@
import org.jetbrains.kotlin.fir.visibilityChecker
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
-import org.jetbrains.kotlin.util.shouldIjPlatformExceptionBeRethrown
+import org.jetbrains.kotlin.util.mapThrowable
private operator fun <T> Pair<T, *>?.component1() = this?.first
private operator fun <T> Pair<*, T>?.component2() = this?.second
@@ -206,8 +206,9 @@
}
}
} catch (e: Throwable) {
- if (shouldIjPlatformExceptionBeRethrown(e)) throw e
- throw RuntimeException("While processing constructors", e)
+ throw mapThrowable(e) {
+ RuntimeException("While processing constructors", it)
+ }
}
}
diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt
index 6dbb1fe..0ddcff0 100644
--- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt
+++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt
@@ -52,7 +52,7 @@
import org.jetbrains.kotlin.types.ConstantValueKind
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
import org.jetbrains.kotlin.util.OperatorNameConventions
-import org.jetbrains.kotlin.util.shouldIjPlatformExceptionBeRethrown
+import org.jetbrains.kotlin.util.mapThrowable
open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveTransformerDispatcher) : FirPartialBodyResolveTransformer(transformer) {
private inline val builtinTypes: BuiltinTypes get() = session.builtinTypes
@@ -418,8 +418,9 @@
}
callCompleter.completeCall(resultExpression, data)
} catch (e: Throwable) {
- if (shouldIjPlatformExceptionBeRethrown(e)) throw e
- throw RuntimeException("While resolving call ${functionCall.render()}", e)
+ throw mapThrowable(e) {
+ RuntimeException("While resolving call ${functionCall.render()}", it)
+ }
}
val result = completeInference.transformToIntegerOperatorCallOrApproximateItIfNeeded(data)
if (!resolvingAugmentedAssignment) {
diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/util/AnalysisExceptions.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/util/AnalysisExceptions.kt
index 4e76e96..625bf4d 100644
--- a/compiler/frontend.common/src/org/jetbrains/kotlin/util/AnalysisExceptions.kt
+++ b/compiler/frontend.common/src/org/jetbrains/kotlin/util/AnalysisExceptions.kt
@@ -38,9 +38,9 @@
}
class FileAnalysisException(
- private val path: String,
+ val path: String,
override val cause: Throwable,
- private val lineAndOffset: Pair<Int, Int>? = null,
+ val lineAndOffset: Pair<Int, Int>? = null,
) : Exception() {
override val message
get(): String {
@@ -88,3 +88,12 @@
throw if (throwable is SourceCodeAnalysisException) throwable.cause else throwable
}
}
+
+inline fun mapThrowable(throwable: Throwable, transform: (Throwable) -> Throwable): Throwable {
+ return when {
+ shouldIjPlatformExceptionBeRethrown(throwable) -> throwable
+ throwable is SourceCodeAnalysisException -> SourceCodeAnalysisException(throwable.source, transform(throwable.cause))
+ throwable is FileAnalysisException -> FileAnalysisException(throwable.path, transform(throwable.cause), throwable.lineAndOffset)
+ else -> transform(throwable)
+ }
+}