[FIR] Set vararg modifier on data class copy method parameters
This only happens in red code, but it prevents unhelpful initializer type mismatch errors.
This commit is contained in:
committed by
Space Team
parent
dcb200d6d3
commit
cfc824f9f2
+1
@@ -212,6 +212,7 @@ internal fun deserializeClassToSymbol(
|
||||
},
|
||||
toFirSource = { src, kind -> KtFakeSourceElement(src as PsiElement, kind) },
|
||||
addValueParameterAnnotations = { annotations += context.annotationDeserializer.loadAnnotations(it) },
|
||||
isVararg = { it.isVarArg }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,6 +31,6 @@ FILE: withSuppression.kt
|
||||
|
||||
public final operator fun component1(): R|kotlin/String|
|
||||
|
||||
public final fun copy(x: R|kotlin/String| = this@R|/D|.R|/D.x|): R|D|
|
||||
public final fun copy(vararg x: R|kotlin/Array<out kotlin/String>| = this@R|/D|.R|/D.x|): R|D|
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -132,6 +132,9 @@ abstract class AbstractLightTreeRawFirBuilder(
|
||||
override val LighterASTNode?.indexExpressions: List<LighterASTNode>?
|
||||
get() = this?.getLastChildExpression()?.getChildrenAsArray()?.filterNotNull()?.filter { it.isExpression() }
|
||||
|
||||
override val LighterASTNode.isVararg: Boolean
|
||||
get() = getChildNodeByType(KtNodeTypes.MODIFIER_LIST)?.getChildNodeByType(VARARG_KEYWORD) != null
|
||||
|
||||
fun LighterASTNode.getParent(): LighterASTNode? {
|
||||
return tree.getParent(this)
|
||||
}
|
||||
|
||||
@@ -140,6 +140,9 @@ open class PsiRawFirBuilder(
|
||||
override val PsiElement?.indexExpressions: List<PsiElement>?
|
||||
get() = (this as? KtArrayAccessExpression)?.indexExpressions
|
||||
|
||||
override val PsiElement.isVararg: Boolean
|
||||
get() = (this as? KtParameter)?.isVarArg ?: false
|
||||
|
||||
private val KtModifierListOwner.visibility: Visibility
|
||||
get() = with(modifierList) {
|
||||
when {
|
||||
|
||||
+10
-7
@@ -63,6 +63,7 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
||||
abstract val T?.selectorExpression: T?
|
||||
abstract val T?.arrayExpression: T?
|
||||
abstract val T?.indexExpressions: List<T>?
|
||||
abstract val T.isVararg: Boolean
|
||||
|
||||
/**** Class name utils ****/
|
||||
inline fun <T> withChildClassName(
|
||||
@@ -901,6 +902,7 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
||||
createParameterTypeRefWithSourceKind,
|
||||
{ src, kind -> src?.toFirSourceElement(kind) },
|
||||
addValueParameterAnnotations,
|
||||
{ it.isVararg },
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1028,21 +1030,22 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> FirRegularClassBuilder.createDataClassCopyFunction(
|
||||
fun <TBase, TSource : TBase, TParameter : TBase> FirRegularClassBuilder.createDataClassCopyFunction(
|
||||
classId: ClassId,
|
||||
sourceElement: T,
|
||||
sourceElement: TSource,
|
||||
dispatchReceiver: ConeClassLikeType?,
|
||||
zippedParameters: List<Pair<T, FirProperty>>,
|
||||
zippedParameters: List<Pair<TParameter, FirProperty>>,
|
||||
createClassTypeRefWithSourceKind: (KtFakeSourceElementKind) -> FirTypeRef,
|
||||
createParameterTypeRefWithSourceKind: (FirProperty, KtFakeSourceElementKind) -> FirTypeRef,
|
||||
toFirSource: (T?, KtFakeSourceElementKind) -> KtSourceElement?,
|
||||
addValueParameterAnnotations: FirValueParameterBuilder.(T) -> Unit,
|
||||
toFirSource: (TBase?, KtFakeSourceElementKind) -> KtSourceElement?,
|
||||
addValueParameterAnnotations: FirValueParameterBuilder.(TParameter) -> Unit,
|
||||
isVararg: (TParameter) -> Boolean,
|
||||
): FirSimpleFunction {
|
||||
fun generateComponentAccess(
|
||||
parameterSource: KtSourceElement?,
|
||||
firProperty: FirProperty,
|
||||
classTypeRefWithCorrectSourceKind: FirTypeRef,
|
||||
firPropertyReturnTypeRefWithCorrectSourceKind: FirTypeRef
|
||||
firPropertyReturnTypeRefWithCorrectSourceKind: FirTypeRef,
|
||||
) =
|
||||
buildPropertyAccessExpression {
|
||||
this.source = parameterSource
|
||||
@@ -1088,7 +1091,7 @@ fun <T> FirRegularClassBuilder.createDataClassCopyFunction(
|
||||
defaultValue = generateComponentAccess(parameterSource, firProperty, classTypeRef, propertyReturnTypeRef)
|
||||
isCrossinline = false
|
||||
isNoinline = false
|
||||
isVararg = false
|
||||
this.isVararg = isVararg(ktParameter)
|
||||
addValueParameterAnnotations(ktParameter)
|
||||
for (annotation in annotations) {
|
||||
annotation.replaceUseSiteTarget(null)
|
||||
|
||||
Reference in New Issue
Block a user