[FIR] fix exception on primary constructor parameter without a type

^KTIJ-25869 fixed
This commit is contained in:
Ilya Kirillov
2023-06-23 17:27:38 +02:00
committed by Space Team
parent c6bd981fad
commit 36c8987df2
8 changed files with 125 additions and 2 deletions
@@ -3865,6 +3865,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag
runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt");
}
@Test
@TestMetadata("primaryConstructorParameterWithoutReturnType.kt")
public void testPrimaryConstructorParameterWithoutReturnType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/primaryConstructorParameterWithoutReturnType.kt");
}
@Test
@TestMetadata("questionableSmartCast.kt")
public void testQuestionableSmartCast() throws Exception {
@@ -3865,6 +3865,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated
runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt");
}
@Test
@TestMetadata("primaryConstructorParameterWithoutReturnType.kt")
public void testPrimaryConstructorParameterWithoutReturnType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/primaryConstructorParameterWithoutReturnType.kt");
}
@Test
@TestMetadata("questionableSmartCast.kt")
public void testQuestionableSmartCast() throws Exception {
@@ -3396,6 +3396,11 @@ public class LazyBodyIsNotTouchedTestGenerated extends AbstractLazyBodyIsNotTouc
runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt");
}
@TestMetadata("primaryConstructorParameterWithoutReturnType.kt")
public void testPrimaryConstructorParameterWithoutReturnType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/primaryConstructorParameterWithoutReturnType.kt");
}
@TestMetadata("questionableSmartCast.kt")
public void testQuestionableSmartCast() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/questionableSmartCast.kt");
@@ -0,0 +1,73 @@
FILE: primaryConstructorParameterWithoutReturnType.kt
public final data class NoParameterNameAndReturnType : R|kotlin/Any| {
public constructor(<ERROR TYPE REF: No type for parameter>): R|NoParameterNameAndReturnType| {
super<R|kotlin/Any|>()
}
public final val <no name provided>: <ERROR TYPE REF: No type for parameter> = R|<local>/<no name provided>|
public get(): <ERROR TYPE REF: No type for parameter>
public final operator fun component1(): <ERROR TYPE REF: No type for parameter>
public final fun copy(<ERROR TYPE REF: No type for parameter> = this@R|/NoParameterNameAndReturnType|.R|/NoParameterNameAndReturnType.<no name provided>|): R|NoParameterNameAndReturnType|
}
public final data class NoParameterReturnTypeInTheMiddle : R|kotlin/Any| {
public constructor(x: R|kotlin/Int|, <ERROR TYPE REF: No type for parameter>, z: R|kotlin/Int|): R|NoParameterReturnTypeInTheMiddle| {
super<R|kotlin/Any|>()
}
public final val x: R|kotlin/Int| = R|<local>/x|
public get(): R|kotlin/Int|
public final val <no name provided>: <ERROR TYPE REF: No type for parameter> = R|<local>/<no name provided>|
public get(): <ERROR TYPE REF: No type for parameter>
public final val z: R|kotlin/Int| = R|<local>/z|
public get(): R|kotlin/Int|
public final operator fun component1(): R|kotlin/Int|
public final operator fun component2(): <ERROR TYPE REF: No type for parameter>
public final operator fun component3(): R|kotlin/Int|
public final fun copy(x: R|kotlin/Int| = this@R|/NoParameterReturnTypeInTheMiddle|.R|/NoParameterReturnTypeInTheMiddle.x|, <ERROR TYPE REF: No type for parameter> = this@R|/NoParameterReturnTypeInTheMiddle|.R|/NoParameterReturnTypeInTheMiddle.<no name provided>|, z: R|kotlin/Int| = this@R|/NoParameterReturnTypeInTheMiddle|.R|/NoParameterReturnTypeInTheMiddle.z|): R|NoParameterReturnTypeInTheMiddle|
}
public final data class NoParameterReturnType : R|kotlin/Any| {
public constructor(x: <ERROR TYPE REF: No type for parameter>): R|NoParameterReturnType| {
super<R|kotlin/Any|>()
}
public final val x: <ERROR TYPE REF: No type for parameter> = R|<local>/x|
public get(): <ERROR TYPE REF: No type for parameter>
public final operator fun component1(): <ERROR TYPE REF: No type for parameter>
public final fun copy(x: <ERROR TYPE REF: No type for parameter> = this@R|/NoParameterReturnType|.R|/NoParameterReturnType.x|): R|NoParameterReturnType|
}
public final data class NoParameterReturnTypeInTheMiddle : R|kotlin/Any| {
public constructor(x: R|kotlin/Int|, y: <ERROR TYPE REF: No type for parameter>, z: R|kotlin/Int|): R|NoParameterReturnTypeInTheMiddle| {
super<R|kotlin/Any|>()
}
public final val x: R|kotlin/Int| = R|<local>/x|
public get(): R|kotlin/Int|
public final val y: <ERROR TYPE REF: No type for parameter> = R|<local>/y|
public get(): <ERROR TYPE REF: No type for parameter>
public final val z: R|kotlin/Int| = R|<local>/z|
public get(): R|kotlin/Int|
public final operator fun component1(): R|kotlin/Int|
public final operator fun component2(): <ERROR TYPE REF: No type for parameter>
public final operator fun component3(): R|kotlin/Int|
public final fun copy(x: R|kotlin/Int| = this@R|/NoParameterReturnTypeInTheMiddle|.R|/NoParameterReturnTypeInTheMiddle.x|, y: <ERROR TYPE REF: No type for parameter> = this@R|/NoParameterReturnTypeInTheMiddle|.R|/NoParameterReturnTypeInTheMiddle.y|, z: R|kotlin/Int| = this@R|/NoParameterReturnTypeInTheMiddle|.R|/NoParameterReturnTypeInTheMiddle.z|): R|NoParameterReturnTypeInTheMiddle|
}
@@ -0,0 +1,7 @@
data class NoParameterNameAndReturnType(val<!SYNTAX!><!>)
data class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>NoParameterReturnTypeInTheMiddle<!>(val x: Int, val<!SYNTAX!><!>, val z: Int)
data class NoParameterReturnType(val x<!SYNTAX!><!>)
data class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>NoParameterReturnTypeInTheMiddle<!>(val x: Int, val y<!SYNTAX!><!>, val z: Int)
@@ -3865,6 +3865,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi
runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt");
}
@Test
@TestMetadata("primaryConstructorParameterWithoutReturnType.kt")
public void testPrimaryConstructorParameterWithoutReturnType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/primaryConstructorParameterWithoutReturnType.kt");
}
@Test
@TestMetadata("questionableSmartCast.kt")
public void testQuestionableSmartCast() throws Exception {
@@ -3865,6 +3865,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest
runTest("compiler/fir/analysis-tests/testData/resolve/problems/objectDerivedFromInnerClass.kt");
}
@Test
@TestMetadata("primaryConstructorParameterWithoutReturnType.kt")
public void testPrimaryConstructorParameterWithoutReturnType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/primaryConstructorParameterWithoutReturnType.kt");
}
@Test
@TestMetadata("questionableSmartCast.kt")
public void testQuestionableSmartCast() throws Exception {
@@ -1351,9 +1351,23 @@ open class PsiRawFirBuilder(
createParameterTypeRefWithSourceKind = { property, newKind ->
// 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()
val returnTypeRef = property.returnTypeRef
when (returnTypeRef) {
is FirErrorTypeRef -> {
buildErrorTypeRefCopy(returnTypeRef) {
source = returnTypeRef.source?.fakeElement(newKind)
}
}
else -> {
withDefaultSourceElementKind(newKind) {
(returnTypeRef.psi as KtTypeReference?).toFirOrImplicitType()
}
}
}
},
addValueParameterAnnotations = { addAnnotationsFrom(it as KtParameter, isFromPrimaryConstructor = true) },
).generate()