[LL FIR] add ability to suppress contract violation exception
^KT-56543
This commit is contained in:
committed by
Space Team
parent
8387ea8a39
commit
2463b904f7
+12
-6
@@ -5,7 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.FirLazyResolveContractViolationException
|
||||
|
||||
internal class LLFirLazyResolveContractChecker {
|
||||
private val currentTransformerPhase = ThreadLocal.withInitial<FirResolvePhase?> { null }
|
||||
@@ -26,12 +28,16 @@ internal class LLFirLazyResolveContractChecker {
|
||||
val currentPhase = currentTransformerPhase.get() ?: return
|
||||
|
||||
if (requestedPhase >= currentPhase) {
|
||||
error(
|
||||
"""`lazyResolveToPhase($requestedPhase)` cannot be called from a transformer with a phase $currentPhase.
|
||||
`lazyResolveToPhase` can be called only from a transformer with a phase which is strictly greater than a requested phase;
|
||||
i.e., `lazyResolveToPhase(A)` may be only called from a lazy transformer with a phase B, where A < B. This is a contract of lazy resolve""".trimIndent()
|
||||
)
|
||||
val exception = FirLazyResolveContractViolationException(currentPhase = currentPhase, requestedPhase = requestedPhase)
|
||||
if (System.getProperty("kotlin.suppress.lazy.resolve.contract.violation") != null) {
|
||||
LoggerHolder.LOG.warn(exception)
|
||||
} else {
|
||||
throw exception
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object LoggerHolder {
|
||||
val LOG = Logger.getInstance(LLFirLazyResolveContractChecker::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user