diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index 698661d6ac2..bde3f0cf9ec 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -244,6 +244,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/implicitTypeInFakeOverride.kt"); } + @TestMetadata("incorrectDataClass.kt") + public void testIncorrectDataClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.kt"); + } + @TestMetadata("incorrectSuperCall.kt") public void testIncorrectSuperCall() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/incorrectSuperCall.kt"); diff --git a/compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.fir.txt b/compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.fir.txt new file mode 100644 index 00000000000..7ba603cf38d --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.fir.txt @@ -0,0 +1,17 @@ +FILE: incorrectDataClass.kt + public final data class Foo : R|kotlin/Any| { + public constructor(a: R|kotlin/Int|, b: R|kotlin/Int|): R|Foo| { + super() + } + + public final val b: R|kotlin/Int| = R|/b| + public get(): R|kotlin/Int| + + public final val c: R|kotlin/Int| = Int(4) + public get(): R|kotlin/Int| + + public final operator fun component1(): R|kotlin/Int| + + public final fun copy(b: R|kotlin/Int| = this@R|/Foo|.R|/Foo.b|): R|Foo| + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.kt b/compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.kt new file mode 100644 index 00000000000..214fca2b270 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.kt @@ -0,0 +1,5 @@ +// ISSUE: KT-44554 + +data class Foo(a: Int, val b: Int) { + val c = 4 +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index 92d29a5322b..9b2a3b940cd 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -284,6 +284,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolve/implicitTypeInFakeOverride.kt"); } + @Test + @TestMetadata("incorrectDataClass.kt") + public void testIncorrectDataClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.kt"); + } + @Test @TestMetadata("incorrectSuperCall.kt") public void testIncorrectSuperCall() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 931d3a4966f..f7ad4f2e209 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -287,6 +287,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/implicitTypeInFakeOverride.kt"); } + @Test + @TestMetadata("incorrectDataClass.kt") + public void testIncorrectDataClass() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/incorrectDataClass.kt"); + } + @Test @TestMetadata("incorrectSuperCall.kt") public void testIncorrectSuperCall() throws Exception { diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 3959e85a96a..214134975b2 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -862,9 +862,7 @@ class RawFirBuilder( } if (classOrObject.hasModifier(DATA_KEYWORD) && firPrimaryConstructor != null) { - val zippedParameters = classOrObject.primaryConstructorParameters.zip( - declarations.filterIsInstance(), - ) + val zippedParameters = classOrObject.primaryConstructorParameters.filter { it.hasValOrVar() } zip declarations.filterIsInstance() DataClassMembersGenerator( baseSession, classOrObject, @@ -877,7 +875,7 @@ class RawFirBuilder( // just making a shallow copy isn't enough type ref may be a function type ref // and contain value parameters inside withDefaultSourceElementKind(newKind) { - (property.returnTypeRef.psi as KtTypeReference).toFirOrImplicitType() + (property.returnTypeRef.psi as KtTypeReference?).toFirOrImplicitType() } }, ).generate()