JVM: generate $assertionsDisabled before inlining the node

This fixes the problem where compiling a class initializer that contains
a call to an `assert`ing function in a separate module causes the
assertion to always be enabled (i.e. the attached test used to fail in
CompileKotlinAgainstInlineKotlin mode).
This commit is contained in:
pyos
2019-10-10 13:20:48 +02:00
committed by Ilmir Usmanov
parent d8ad0ec43a
commit bc4be53569
6 changed files with 69 additions and 9 deletions
@@ -231,12 +231,6 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
//through generation captured parameters will be added to invocationParamBuilder
putClosureParametersOnStack()
val shouldSpillStack = !canSkipStackSpillingOnInline(node)
if (shouldSpillStack) {
addInlineMarker(codegen.v, true)
}
val parameters = invocationParamBuilder.buildParameters()
val info = RootInliningContext(
@@ -271,16 +265,21 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
removeFinallyMarkers(adapter)
}
adapter.accept(MethodBodyVisitor(codegen.v))
// In case `codegen.v` is `<clinit>`, initializer for the `$assertionsDisabled` field
// needs to be inserted before the code that actually uses it.
generateAssertFieldIfNeeded(info)
val shouldSpillStack = !canSkipStackSpillingOnInline(node)
if (shouldSpillStack) {
addInlineMarker(codegen.v, true)
}
adapter.accept(MethodBodyVisitor(codegen.v))
if (shouldSpillStack) {
addInlineMarker(codegen.v, false)
}
defaultSourceMapper.callSiteMarker = null
generateAssertFieldIfNeeded(info)
return result
}