[JS IR] Fix annotation constructor body generation

This commit is contained in:
Roman Artemev
2019-11-21 17:57:05 +03:00
committed by romanart
parent c5e25a0382
commit 2e22ddba39
2 changed files with 38 additions and 1 deletions
@@ -258,11 +258,17 @@ private val primaryConstructorLoweringPhase = makeJsModulePhase(
prerequisite = setOf(enumClassConstructorLoweringPhase)
)
private val annotationConstructorLowering = makeJsModulePhase(
::AnnotationConstructorLowering,
name = "AnnotationConstructorLowering",
description = "Generate annotation constructor body"
)
private val initializersLoweringPhase = makeJsModulePhase(
::InitializersLowering,
name = "InitializersLowering",
description = "Merge init block and field initializers into [primary] constructor",
prerequisite = setOf(enumClassConstructorLoweringPhase, primaryConstructorLoweringPhase)
prerequisite = setOf(enumClassConstructorLoweringPhase, primaryConstructorLoweringPhase, annotationConstructorLowering)
)
private val multipleCatchesLoweringPhase = makeJsModulePhase(
@@ -397,6 +403,7 @@ val jsPhases = namedIrModulePhase(
innerClassConstructorCallsLoweringPhase then
propertiesLoweringPhase then
primaryConstructorLoweringPhase then
annotationConstructorLowering then
initializersLoweringPhase then
// Common prefix ends
enumClassLoweringPhase then
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir.backend.js.lower
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
import org.jetbrains.kotlin.backend.common.CommonBackendContext
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
class AnnotationConstructorLowering(context: CommonBackendContext) : ClassLoweringPass {
private val unitType = context.irBuiltIns.unitType
override fun lower(irClass: IrClass) {
if (irClass.kind != ClassKind.ANNOTATION_CLASS) return
val constructor = irClass.declarations.filterIsInstance<IrConstructor>().single()
assert(constructor.isPrimary)
// put empty body to make sure proper initializer is generated
constructor.body = IrBlockBodyImpl(constructor.startOffset, constructor.endOffset).apply {
statements += IrInstanceInitializerCallImpl(startOffset, endOffset, irClass.symbol, unitType)
}
}
}