[FIR] Don't update explicit delegated constructor calls of classes with @JvmRecord
^KT-54573 Fixed
This commit is contained in:
committed by
Space Team
parent
880b278c40
commit
d898e256ca
+6
@@ -32309,6 +32309,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/disabledFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitSuperConstructorCall.kt")
|
||||
public void testExplicitSuperConstructorCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/explicitSuperConstructorCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("irrelevantFields.kt")
|
||||
public void testIrrelevantFields() throws Exception {
|
||||
|
||||
+6
@@ -32405,6 +32405,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/disabledFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitSuperConstructorCall.kt")
|
||||
public void testExplicitSuperConstructorCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/explicitSuperConstructorCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("irrelevantFields.kt")
|
||||
public void testIrrelevantFields() throws Exception {
|
||||
|
||||
+6
@@ -32309,6 +32309,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/disabledFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitSuperConstructorCall.kt")
|
||||
public void testExplicitSuperConstructorCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/explicitSuperConstructorCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("irrelevantFields.kt")
|
||||
public void testIrrelevantFields() throws Exception {
|
||||
|
||||
+6
@@ -364,6 +364,12 @@ public class FirBlackBoxModernJdkCodegenTestGenerated extends AbstractFirBlackBo
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/jvmRecordBinary.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt54573.kt")
|
||||
public void testKt54573() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/kt54573.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertiesOverrides.kt")
|
||||
public void testPropertiesOverrides() throws Exception {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.java
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -15,6 +16,7 @@ import org.jetbrains.kotlin.fir.declarations.hasAnnotationSafe
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isData
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirLazyDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.java.JvmSupertypeUpdater.DelegatedConstructorCallTransformer.Companion.recordType
|
||||
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
@@ -80,6 +82,14 @@ class JvmSupertypeUpdater(private val session: FirSession) : PlatformSupertypeUp
|
||||
delegatedConstructorCall: FirDelegatedConstructorCall,
|
||||
data: ScopeSession
|
||||
): FirStatement {
|
||||
/*
|
||||
* Here we need to update only implicit calls to Any()
|
||||
* And such calls don't have a real source and can not be an lazy calls
|
||||
*/
|
||||
if (
|
||||
delegatedConstructorCall is FirLazyDelegatedConstructorCall ||
|
||||
delegatedConstructorCall.source?.kind != KtFakeSourceElementKind.DelegatingConstructorCall
|
||||
) return delegatedConstructorCall
|
||||
val constructedTypeRef = delegatedConstructorCall.constructedTypeRef
|
||||
if (constructedTypeRef is FirImplicitTypeRef || constructedTypeRef.coneTypeSafe<ConeKotlinType>()?.isAny == true) {
|
||||
delegatedConstructorCall.replaceConstructedTypeRef(constructedTypeRef.resolvedTypeFromPrototype(recordType))
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// ISSUE: KT-54573
|
||||
// WITH_STDLIB
|
||||
|
||||
@JvmRecord
|
||||
data class A constructor(val x: Int, val s: String) {
|
||||
constructor(s: String) : this(s.length, s)
|
||||
}
|
||||
|
||||
fun box(): String = A("OK").s
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-54573
|
||||
// JVM_TARGET: 17
|
||||
|
||||
@JvmRecord
|
||||
data class A constructor(val x: Int, val s: String) {
|
||||
constructor(x: Long, s: String) : <!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>super<!>(<!TOO_MANY_ARGUMENTS!>x.toInt()<!>, <!TOO_MANY_ARGUMENTS!>s<!>)
|
||||
constructor(x: Byte, s: String) : <!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>super<!>(<!TOO_MANY_ARGUMENTS!>x.toInt()<!>, <!TOO_MANY_ARGUMENTS!>s.<!UNRESOLVED_REFERENCE!>unresolved<!>()<!>)
|
||||
|
||||
constructor(s: String) : this(s.length, s)
|
||||
constructor(s: CharSequence) : this(s.length, s.<!UNRESOLVED_REFERENCE!>unresolved<!>())
|
||||
}
|
||||
Generated
+6
@@ -32405,6 +32405,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/disabledFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitSuperConstructorCall.kt")
|
||||
public void testExplicitSuperConstructorCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/explicitSuperConstructorCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("irrelevantFields.kt")
|
||||
public void testIrrelevantFields() throws Exception {
|
||||
|
||||
+6
@@ -364,6 +364,12 @@ public class IrBlackBoxModernJdkCodegenTestGenerated extends AbstractIrBlackBoxC
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/jvmRecordBinary.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt54573.kt")
|
||||
public void testKt54573() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/kt54573.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertiesOverrides.kt")
|
||||
public void testPropertiesOverrides() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user