[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) },
|
toFirSource = { src, kind -> KtFakeSourceElement(src as PsiElement, kind) },
|
||||||
addValueParameterAnnotations = { annotations += context.annotationDeserializer.loadAnnotations(it) },
|
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 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>?
|
override val LighterASTNode?.indexExpressions: List<LighterASTNode>?
|
||||||
get() = this?.getLastChildExpression()?.getChildrenAsArray()?.filterNotNull()?.filter { it.isExpression() }
|
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? {
|
fun LighterASTNode.getParent(): LighterASTNode? {
|
||||||
return tree.getParent(this)
|
return tree.getParent(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,9 @@ open class PsiRawFirBuilder(
|
|||||||
override val PsiElement?.indexExpressions: List<PsiElement>?
|
override val PsiElement?.indexExpressions: List<PsiElement>?
|
||||||
get() = (this as? KtArrayAccessExpression)?.indexExpressions
|
get() = (this as? KtArrayAccessExpression)?.indexExpressions
|
||||||
|
|
||||||
|
override val PsiElement.isVararg: Boolean
|
||||||
|
get() = (this as? KtParameter)?.isVarArg ?: false
|
||||||
|
|
||||||
private val KtModifierListOwner.visibility: Visibility
|
private val KtModifierListOwner.visibility: Visibility
|
||||||
get() = with(modifierList) {
|
get() = with(modifierList) {
|
||||||
when {
|
when {
|
||||||
|
|||||||
+10
-7
@@ -63,6 +63,7 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
|||||||
abstract val T?.selectorExpression: T?
|
abstract val T?.selectorExpression: T?
|
||||||
abstract val T?.arrayExpression: T?
|
abstract val T?.arrayExpression: T?
|
||||||
abstract val T?.indexExpressions: List<T>?
|
abstract val T?.indexExpressions: List<T>?
|
||||||
|
abstract val T.isVararg: Boolean
|
||||||
|
|
||||||
/**** Class name utils ****/
|
/**** Class name utils ****/
|
||||||
inline fun <T> withChildClassName(
|
inline fun <T> withChildClassName(
|
||||||
@@ -901,6 +902,7 @@ abstract class AbstractRawFirBuilder<T>(val baseSession: FirSession, val context
|
|||||||
createParameterTypeRefWithSourceKind,
|
createParameterTypeRefWithSourceKind,
|
||||||
{ src, kind -> src?.toFirSourceElement(kind) },
|
{ src, kind -> src?.toFirSourceElement(kind) },
|
||||||
addValueParameterAnnotations,
|
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,
|
classId: ClassId,
|
||||||
sourceElement: T,
|
sourceElement: TSource,
|
||||||
dispatchReceiver: ConeClassLikeType?,
|
dispatchReceiver: ConeClassLikeType?,
|
||||||
zippedParameters: List<Pair<T, FirProperty>>,
|
zippedParameters: List<Pair<TParameter, FirProperty>>,
|
||||||
createClassTypeRefWithSourceKind: (KtFakeSourceElementKind) -> FirTypeRef,
|
createClassTypeRefWithSourceKind: (KtFakeSourceElementKind) -> FirTypeRef,
|
||||||
createParameterTypeRefWithSourceKind: (FirProperty, KtFakeSourceElementKind) -> FirTypeRef,
|
createParameterTypeRefWithSourceKind: (FirProperty, KtFakeSourceElementKind) -> FirTypeRef,
|
||||||
toFirSource: (T?, KtFakeSourceElementKind) -> KtSourceElement?,
|
toFirSource: (TBase?, KtFakeSourceElementKind) -> KtSourceElement?,
|
||||||
addValueParameterAnnotations: FirValueParameterBuilder.(T) -> Unit,
|
addValueParameterAnnotations: FirValueParameterBuilder.(TParameter) -> Unit,
|
||||||
|
isVararg: (TParameter) -> Boolean,
|
||||||
): FirSimpleFunction {
|
): FirSimpleFunction {
|
||||||
fun generateComponentAccess(
|
fun generateComponentAccess(
|
||||||
parameterSource: KtSourceElement?,
|
parameterSource: KtSourceElement?,
|
||||||
firProperty: FirProperty,
|
firProperty: FirProperty,
|
||||||
classTypeRefWithCorrectSourceKind: FirTypeRef,
|
classTypeRefWithCorrectSourceKind: FirTypeRef,
|
||||||
firPropertyReturnTypeRefWithCorrectSourceKind: FirTypeRef
|
firPropertyReturnTypeRefWithCorrectSourceKind: FirTypeRef,
|
||||||
) =
|
) =
|
||||||
buildPropertyAccessExpression {
|
buildPropertyAccessExpression {
|
||||||
this.source = parameterSource
|
this.source = parameterSource
|
||||||
@@ -1088,7 +1091,7 @@ fun <T> FirRegularClassBuilder.createDataClassCopyFunction(
|
|||||||
defaultValue = generateComponentAccess(parameterSource, firProperty, classTypeRef, propertyReturnTypeRef)
|
defaultValue = generateComponentAccess(parameterSource, firProperty, classTypeRef, propertyReturnTypeRef)
|
||||||
isCrossinline = false
|
isCrossinline = false
|
||||||
isNoinline = false
|
isNoinline = false
|
||||||
isVararg = false
|
this.isVararg = isVararg(ktParameter)
|
||||||
addValueParameterAnnotations(ktParameter)
|
addValueParameterAnnotations(ktParameter)
|
||||||
for (annotation in annotations) {
|
for (annotation in annotations) {
|
||||||
annotation.replaceUseSiteTarget(null)
|
annotation.replaceUseSiteTarget(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user