[FIR] Unwrap vararg array types for diagnostic rendering
#KT-65770 Fixed
This commit is contained in:
committed by
Space Team
parent
eae72eac54
commit
33648e1f44
@@ -78,7 +78,7 @@ class FirRenderer(
|
||||
propertyAccessorRenderer = null,
|
||||
callArgumentsRenderer = FirCallNoArgumentsRenderer(),
|
||||
modifierRenderer = FirPartialModifierRenderer(),
|
||||
valueParameterRenderer = FirValueParameterRendererNoDefaultValue(),
|
||||
valueParameterRenderer = FirValueParameterRendererForReadability(),
|
||||
declarationRenderer = FirDeclarationRenderer("local ")
|
||||
)
|
||||
}
|
||||
|
||||
+7
-1
@@ -15,6 +15,7 @@ open class FirValueParameterRenderer {
|
||||
private val annotationRenderer get() = components.annotationRenderer
|
||||
protected val declarationRenderer get() = components.declarationRenderer
|
||||
private val modifierRenderer get() = components.modifierRenderer
|
||||
protected val typeRenderer get() = components.typeRenderer
|
||||
|
||||
fun renderParameters(valueParameters: List<FirValueParameter>) {
|
||||
printer.print("(")
|
||||
@@ -34,10 +35,15 @@ open class FirValueParameterRenderer {
|
||||
if (valueParameter.name != SpecialNames.NO_NAME_PROVIDED) {
|
||||
printer.print(valueParameter.name.toString() + ": ")
|
||||
}
|
||||
valueParameter.returnTypeRef.accept(visitor)
|
||||
|
||||
renderParameterType(valueParameter)
|
||||
renderDefaultValue(valueParameter)
|
||||
}
|
||||
|
||||
protected open fun renderParameterType(valueParameter: FirValueParameter) {
|
||||
valueParameter.returnTypeRef.accept(visitor)
|
||||
}
|
||||
|
||||
protected open fun renderDefaultValue(valueParameter: FirValueParameter) {
|
||||
valueParameter.defaultValue?.let {
|
||||
printer.print(" = ")
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.fir.renderer
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.arrayElementType
|
||||
|
||||
class FirValueParameterRendererForReadability : FirValueParameterRenderer() {
|
||||
override fun renderParameterType(valueParameter: FirValueParameter) {
|
||||
val returnTypeRef = valueParameter.returnTypeRef
|
||||
|
||||
if (valueParameter.isVararg && returnTypeRef is FirResolvedTypeRef) {
|
||||
val arrayElementType = returnTypeRef.type.arrayElementType()
|
||||
if (arrayElementType != null) {
|
||||
typeRenderer.render(arrayElementType)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
super.renderParameterType(valueParameter)
|
||||
}
|
||||
|
||||
override fun renderDefaultValue(valueParameter: FirValueParameter) {
|
||||
valueParameter.defaultValue?.let {
|
||||
printer.print(" = ...")
|
||||
}
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.fir.renderer
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
|
||||
class FirValueParameterRendererNoDefaultValue : FirValueParameterRenderer() {
|
||||
override fun renderDefaultValue(valueParameter: FirValueParameter) {
|
||||
valueParameter.defaultValue?.let {
|
||||
printer.print(" = ...")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
@@ -155,3 +156,27 @@ fun FirTypeProjection.toConeTypeProjection(): ConeTypeProjection = when (this) {
|
||||
}
|
||||
else -> errorWithAttachment("Unexpected ${this::class.simpleName}") { withFirEntry("projection", this@toConeTypeProjection) }
|
||||
}
|
||||
|
||||
fun ConeKotlinType.arrayElementType(checkUnsignedArrays: Boolean = true): ConeKotlinType? {
|
||||
return when (val argument = arrayElementTypeArgument(checkUnsignedArrays)) {
|
||||
is ConeKotlinTypeProjection -> argument.type
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun ConeKotlinType.arrayElementTypeArgument(checkUnsignedArrays: Boolean = true): ConeTypeProjection? {
|
||||
val type = this.lowerBoundIfFlexible()
|
||||
if (type !is ConeClassLikeType) return null
|
||||
val classId = type.lookupTag.classId
|
||||
if (classId == StandardClassIds.Array) {
|
||||
return type.typeArguments.first()
|
||||
}
|
||||
val elementType = StandardClassIds.elementTypeByPrimitiveArrayType[classId] ?: runIf(checkUnsignedArrays) {
|
||||
StandardClassIds.elementTypeByUnsignedArrayType[classId]
|
||||
}
|
||||
if (elementType != null) {
|
||||
return elementType.constructClassLikeType(emptyArray(), isNullable = false)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user