LT: make where clause with errors parsing same as with PSI
- do not fail on the missing terms - propagate invalid name to avoid reporting dangling constraints #KT-58455 fixed
This commit is contained in:
committed by
Space Team
parent
87563f3aea
commit
1d461684ae
+6
@@ -13972,6 +13972,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereClauseSyntax.kt")
|
||||
public void testWhereClauseSyntax() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/whereClauseSyntax.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardInValueParameter.kt")
|
||||
public void testWildcardInValueParameter() throws Exception {
|
||||
|
||||
+6
@@ -13972,6 +13972,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereClauseSyntax.kt")
|
||||
public void testWhereClauseSyntax() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/whereClauseSyntax.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardInValueParameter.kt")
|
||||
public void testWildcardInValueParameter() throws Exception {
|
||||
|
||||
+6
@@ -13966,6 +13966,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereClauseSyntax.kt")
|
||||
public void testWhereClauseSyntax() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/whereClauseSyntax.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardInValueParameter.kt")
|
||||
public void testWildcardInValueParameter() throws Exception {
|
||||
|
||||
+6
@@ -13972,6 +13972,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereClauseSyntax.kt")
|
||||
public void testWhereClauseSyntax() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/whereClauseSyntax.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardInValueParameter.kt")
|
||||
public void testWildcardInValueParameter() throws Exception {
|
||||
|
||||
+20
-11
@@ -1975,18 +1975,22 @@ class LightTreeRawFirDeclarationBuilder(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeConstraint
|
||||
*/
|
||||
private fun convertTypeConstraint(typeConstraint: LighterASTNode): TypeConstraint {
|
||||
lateinit var identifier: String
|
||||
lateinit var firType: FirTypeRef
|
||||
lateinit var referenceExpression: LighterASTNode
|
||||
|
||||
val diagnostic = ConeSimpleDiagnostic(
|
||||
"Type parameter annotations are not allowed inside where clauses", DiagnosticKind.AnnotationNotAllowed,
|
||||
)
|
||||
var identifier: String? = null
|
||||
var firType: FirTypeRef? = null
|
||||
var referenceExpression: LighterASTNode? = null
|
||||
|
||||
val annotations = mutableListOf<FirAnnotation>()
|
||||
typeConstraint.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
ANNOTATION_ENTRY -> annotations += convertAnnotationEntry(it, diagnostic = diagnostic)
|
||||
ANNOTATION_ENTRY -> {
|
||||
annotations +=
|
||||
convertAnnotationEntry(
|
||||
it,
|
||||
diagnostic = ConeSimpleDiagnostic(
|
||||
"Type parameter annotations are not allowed inside where clauses", DiagnosticKind.AnnotationNotAllowed,
|
||||
)
|
||||
)
|
||||
}
|
||||
REFERENCE_EXPRESSION -> {
|
||||
identifier = it.asText
|
||||
referenceExpression = it
|
||||
@@ -1995,7 +1999,12 @@ class LightTreeRawFirDeclarationBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
return TypeConstraint(annotations, identifier, firType, referenceExpression.toFirSourceElement())
|
||||
return TypeConstraint(
|
||||
annotations,
|
||||
identifier,
|
||||
firType ?: buildErrorTypeRef { },
|
||||
(referenceExpression ?: typeConstraint).toFirSourceElement()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2391,8 +2400,8 @@ class LightTreeRawFirDeclarationBuilder(
|
||||
) where T : FirDeclaration, T : FirTypeParameterRefsOwner {
|
||||
val typeParamNames = typeParameters.map { it.name }.toSet()
|
||||
val result = typeConstraints.mapNotNull { constraint ->
|
||||
val name = constraint.identifier.nameAsSafeName()
|
||||
if (!typeParamNames.contains(name)) {
|
||||
val name = constraint.identifier?.nameAsSafeName()
|
||||
if (name != null && !typeParamNames.contains(name)) {
|
||||
DanglingTypeConstraint(name, constraint.source)
|
||||
} else {
|
||||
null
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
|
||||
class TypeConstraint(
|
||||
val annotations: List<FirAnnotation>,
|
||||
val identifier: String,
|
||||
val identifier: String?,
|
||||
val firTypeRef: FirTypeRef,
|
||||
val source: KtSourceElement
|
||||
)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// DIAGNOSTICS: -DEBUG_INFO_MISSING_UNRESOLVED
|
||||
interface I
|
||||
fun <E> foo() where E: I {}
|
||||
fun <E> fooE1() where <!SYNTAX!><!>: I {}
|
||||
fun <E> fooE2() where E: <!SYNTAX, SYNTAX!><!>{}
|
||||
fun <E> fooE3() where <!SYNTAX!><!>{}
|
||||
@@ -0,0 +1,6 @@
|
||||
// DIAGNOSTICS: -DEBUG_INFO_MISSING_UNRESOLVED
|
||||
interface I
|
||||
fun <E> foo() where E: I {}
|
||||
fun <E> fooE1() where <!SYNTAX!><!>: I {}
|
||||
fun <E> fooE2() where E: <!SYNTAX!><!>{}
|
||||
fun <E> fooE3() where <!SYNTAX!><!>{}
|
||||
Generated
+6
@@ -13972,6 +13972,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whereClauseSyntax.kt")
|
||||
public void testWhereClauseSyntax() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/whereClauseSyntax.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardInValueParameter.kt")
|
||||
public void testWildcardInValueParameter() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user