FIR: support copy functions in data classes

This commit is contained in:
Mikhail Glukhikh
2019-05-16 11:14:43 +03:00
parent d9261acdfc
commit 2bf80ff64e
17 changed files with 341 additions and 16 deletions
@@ -538,6 +538,9 @@ open class FirBodyResolveTransformer(val session: FirSession, val implicitTypeOn
}
override fun transformFunctionCall(functionCall: FirFunctionCall, data: Any?): CompositeTransformResult<FirStatement> {
if (functionCall.calleeReference is FirResolvedCallableReference && functionCall.resultType is FirImplicitTypeRef) {
storeTypeFromCallee(functionCall)
}
if (functionCall.calleeReference !is FirSimpleNamedReference) return functionCall.compose()
val expectedTypeRef = data as FirTypeRef?
val completeInference =
+8
View File
@@ -0,0 +1,8 @@
data class Some(val x: Int, val y: String)
fun test(some: Some) {
val other = some.copy(y = "123")
val another = some.copy(x = 123)
val same = some.copy()
val different = some.copy(456, "456")
}
+31
View File
@@ -0,0 +1,31 @@
FILE: copy.kt
public final data class Some : R|kotlin/Any| {
public constructor(x: R|kotlin/Int|, y: R|kotlin/String|): R|Some| {
super<R|kotlin/Any|>()
}
public final val x: R|kotlin/Int| = R|<local>/x|
public get(): R|kotlin/Int|
public final val y: R|kotlin/String| = R|<local>/y|
public get(): R|kotlin/String|
public final fun component1(): R|kotlin/Int| {
^component1 R|/Some.x|
}
public final fun component2(): R|kotlin/String| {
^component2 R|/Some.y|
}
public final fun copy(x: R|kotlin/Int| = R|/Some.x|, y: R|kotlin/String| = R|/Some.y|): R|Some| {
^copy R|/Some.Some|(R|<local>/x|, R|<local>/y|)
}
}
public final fun test(some: R|Some|): R|kotlin/Unit| {
lval other: R|Some| = R|<local>/some|.R|/Some.copy|(y = String(123))
lval another: R|Some| = R|<local>/some|.R|/Some.copy|(x = Int(123))
lval same: R|Some| = R|<local>/some|.R|/Some.copy|()
lval different: R|Some| = R|<local>/some|.R|/Some.copy|(Int(456), String(456))
}
@@ -18,6 +18,10 @@ FILE: components.kt
^component2 R|/D.y|
}
public final fun copy(x: R|kotlin/Int| = R|/D.x|, y: R|kotlin/String| = R|/D.y|): R|D| {
^copy R|/D.D|(R|<local>/x|, R|<local>/y|)
}
}
public final fun foo(list: R|kotlin/collections/List<D>|): R|kotlin/Unit| {
lval <range>: R|kotlin/collections/List<D>| = R|<local>/list|
@@ -34,6 +34,11 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
runTest("compiler/fir/resolve/testData/resolve/companion.kt");
}
@TestMetadata("copy.kt")
public void testCopy() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/copy.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/derivedClass.kt");