[FIR] FirJavaFacade: do not duplicate record constructor
The fresh version of intellij has all record-related declarations, so an additional fake constructor leads to errors like KTIJ-25364 (OVERLOAD_RESOLUTION_AMBIGUITY) ^KTIJ-25366 Fixed ^KTIJ-25364 Fixed ^KTIJ-25368 Fixed ^KTIJ-25370 Fixed
This commit is contained in:
committed by
Space Team
parent
97a12af03e
commit
b67b37cdb3
+12
@@ -33559,6 +33559,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsDefaultConstructor.kt")
|
||||||
|
public void testSimpleRecordsDefaultConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsDefaultConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsWithSecondaryConstructor.kt")
|
||||||
|
public void testSimpleRecordsWithSecondaryConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsWithSecondaryConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("supertypesCheck.kt")
|
@TestMetadata("supertypesCheck.kt")
|
||||||
public void testSupertypesCheck() throws Exception {
|
public void testSupertypesCheck() throws Exception {
|
||||||
|
|||||||
+12
@@ -33559,6 +33559,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsDefaultConstructor.kt")
|
||||||
|
public void testSimpleRecordsDefaultConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsDefaultConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsWithSecondaryConstructor.kt")
|
||||||
|
public void testSimpleRecordsWithSecondaryConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsWithSecondaryConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("supertypesCheck.kt")
|
@TestMetadata("supertypesCheck.kt")
|
||||||
public void testSupertypesCheck() throws Exception {
|
public void testSupertypesCheck() throws Exception {
|
||||||
|
|||||||
+12
@@ -33559,6 +33559,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsDefaultConstructor.kt")
|
||||||
|
public void testSimpleRecordsDefaultConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsDefaultConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsWithSecondaryConstructor.kt")
|
||||||
|
public void testSimpleRecordsWithSecondaryConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsWithSecondaryConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("supertypesCheck.kt")
|
@TestMetadata("supertypesCheck.kt")
|
||||||
public void testSupertypesCheck() throws Exception {
|
public void testSupertypesCheck() throws Exception {
|
||||||
|
|||||||
+12
@@ -33673,6 +33673,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsDefaultConstructor.kt")
|
||||||
|
public void testSimpleRecordsDefaultConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsDefaultConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsWithSecondaryConstructor.kt")
|
||||||
|
public void testSimpleRecordsWithSecondaryConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsWithSecondaryConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("supertypesCheck.kt")
|
@TestMetadata("supertypesCheck.kt")
|
||||||
public void testSupertypesCheck() throws Exception {
|
public void testSupertypesCheck() throws Exception {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.java
|
package org.jetbrains.kotlin.fir.java
|
||||||
|
|
||||||
|
import com.intellij.psi.impl.light.LightRecordCanonicalConstructor
|
||||||
import org.jetbrains.kotlin.*
|
import org.jetbrains.kotlin.*
|
||||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
@@ -320,6 +321,7 @@ abstract class FirJavaFacade(
|
|||||||
|
|
||||||
if (javaClassDeclaredConstructors.isEmpty()
|
if (javaClassDeclaredConstructors.isEmpty()
|
||||||
&& javaClass.classKind == ClassKind.CLASS
|
&& javaClass.classKind == ClassKind.CLASS
|
||||||
|
&& !javaClass.isRecord
|
||||||
&& javaClass.hasDefaultConstructor()
|
&& javaClass.hasDefaultConstructor()
|
||||||
) {
|
) {
|
||||||
declarations += convertJavaConstructorToFir(
|
declarations += convertJavaConstructorToFir(
|
||||||
@@ -441,6 +443,12 @@ abstract class FirJavaFacade(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is possible that JavaClass already has a synthetic primary constructor ([LightRecordCanonicalConstructor])
|
||||||
|
* Such behavior depends on a platform version and psi providers
|
||||||
|
* (e.g., in IntelliJ plugin Java class can have additional declarations)
|
||||||
|
*/
|
||||||
|
if (destination.none { it is FirJavaConstructor && it.isPrimary }) {
|
||||||
destination += buildJavaConstructor {
|
destination += buildJavaConstructor {
|
||||||
source = javaClass.toSourceElement(KtFakeSourceElementKind.ImplicitJavaRecordConstructor)
|
source = javaClass.toSourceElement(KtFakeSourceElementKind.ImplicitJavaRecordConstructor)
|
||||||
this.moduleData = moduleData
|
this.moduleData = moduleData
|
||||||
@@ -476,6 +484,7 @@ abstract class FirJavaFacade(
|
|||||||
containingClassForStaticMemberAttr = classType.lookupTag
|
containingClassForStaticMemberAttr = classType.lookupTag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun convertJavaFieldToFir(
|
private fun convertJavaFieldToFir(
|
||||||
javaField: JavaField,
|
javaField: JavaField,
|
||||||
@@ -636,7 +645,7 @@ abstract class FirJavaFacade(
|
|||||||
hasStableParameterNames = false
|
hasStableParameterNames = false
|
||||||
}
|
}
|
||||||
this.visibility = visibility
|
this.visibility = visibility
|
||||||
isPrimary = javaConstructor == null
|
isPrimary = javaConstructor == null || source?.psi is LightRecordCanonicalConstructor
|
||||||
returnTypeRef = buildResolvedTypeRef {
|
returnTypeRef = buildResolvedTypeRef {
|
||||||
type = ownerClassBuilder.buildSelfTypeRef()
|
type = ownerClassBuilder.buildSelfTypeRef()
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// LANGUAGE: +JvmRecordSupport
|
||||||
|
|
||||||
|
// FILE: MyRecord.java
|
||||||
|
public record MyRecord(String str) {}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
MyRecord("") // OK
|
||||||
|
MyRecord<!NO_VALUE_FOR_PARAMETER!>()<!> // error
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// LANGUAGE: +JvmRecordSupport
|
||||||
|
|
||||||
|
// FILE: MyRecord.java
|
||||||
|
public record MyRecord(String string, int number) {
|
||||||
|
public MyRecord(Long number, String string) {
|
||||||
|
this(string, 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
fun foo(mr: MyRecord) {
|
||||||
|
MyRecord("", 1)
|
||||||
|
MyRecord(4L, "")
|
||||||
|
}
|
||||||
Generated
+12
@@ -34517,6 +34517,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecords.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsDefaultConstructor.kt")
|
||||||
|
public void testSimpleRecordsDefaultConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsDefaultConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("simpleRecordsWithSecondaryConstructor.kt")
|
||||||
|
public void testSimpleRecordsWithSecondaryConstructor() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/jvmRecord/simpleRecordsWithSecondaryConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("supertypesCheck.kt")
|
@TestMetadata("supertypesCheck.kt")
|
||||||
public void testSupertypesCheck() throws Exception {
|
public void testSupertypesCheck() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user