[IR] Add explicit error in IR type transformer for member access expr
We must generate transform method for `IrMemberAccessExpression` by hand because of specifics of working with `typeArguments`. But we also must consider the case that in future we can add new fields in this element. If it happens, we will see error message. #KT-57812
This commit is contained in:
+7
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.generator.VISITOR_PACKAGE
|
||||
import org.jetbrains.kotlin.ir.generator.irTypeType
|
||||
import org.jetbrains.kotlin.ir.generator.model.*
|
||||
import org.jetbrains.kotlin.ir.generator.util.GeneratedFile
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
||||
import java.io.File
|
||||
|
||||
private val visitorTypeName = ClassName(VISITOR_PACKAGE, "IrElementVisitor")
|
||||
@@ -186,6 +187,12 @@ fun printTypeVisitor(generationPath: File, model: Model): GeneratedFile {
|
||||
val visitorParam = element.visitorParam
|
||||
when (element.name) {
|
||||
IrTree.memberAccessExpression.name -> {
|
||||
if (irTypeFields.singleOrNull()?.name != "typeArguments") {
|
||||
error(
|
||||
"""`Ir${IrTree.memberAccessExpression.name.capitalizeAsciiOnly()}` has unexpected fields with `IrType` type.
|
||||
|Please adjust logic of `${typeTransformerVoidTypeName.simpleName}`'s generation.""".trimMargin()
|
||||
)
|
||||
}
|
||||
beginControlFlow("(0 until $visitorParam.typeArgumentsCount).forEach {")
|
||||
beginControlFlow("$visitorParam.getTypeArgument(it)?.let { type ->")
|
||||
addStatement("expression.putTypeArgument(it, $transformTypeFunName($visitorParam, type, data))")
|
||||
|
||||
Reference in New Issue
Block a user