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");
|
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
|
@Test
|
||||||
@TestMetadata("wildcardInValueParameter.kt")
|
@TestMetadata("wildcardInValueParameter.kt")
|
||||||
public void testWildcardInValueParameter() throws Exception {
|
public void testWildcardInValueParameter() throws Exception {
|
||||||
|
|||||||
+6
@@ -13972,6 +13972,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
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
|
@Test
|
||||||
@TestMetadata("wildcardInValueParameter.kt")
|
@TestMetadata("wildcardInValueParameter.kt")
|
||||||
public void testWildcardInValueParameter() throws Exception {
|
public void testWildcardInValueParameter() throws Exception {
|
||||||
|
|||||||
+6
@@ -13966,6 +13966,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
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
|
@Test
|
||||||
@TestMetadata("wildcardInValueParameter.kt")
|
@TestMetadata("wildcardInValueParameter.kt")
|
||||||
public void testWildcardInValueParameter() throws Exception {
|
public void testWildcardInValueParameter() throws Exception {
|
||||||
|
|||||||
+6
@@ -13972,6 +13972,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/unresolvedClassifierInWhere.kt");
|
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
|
@Test
|
||||||
@TestMetadata("wildcardInValueParameter.kt")
|
@TestMetadata("wildcardInValueParameter.kt")
|
||||||
public void testWildcardInValueParameter() throws Exception {
|
public void testWildcardInValueParameter() throws Exception {
|
||||||
|
|||||||
+20
-11
@@ -1975,18 +1975,22 @@ class LightTreeRawFirDeclarationBuilder(
|
|||||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeConstraint
|
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeConstraint
|
||||||
*/
|
*/
|
||||||
private fun convertTypeConstraint(typeConstraint: LighterASTNode): TypeConstraint {
|
private fun convertTypeConstraint(typeConstraint: LighterASTNode): TypeConstraint {
|
||||||
lateinit var identifier: String
|
var identifier: String? = null
|
||||||
lateinit var firType: FirTypeRef
|
var firType: FirTypeRef? = null
|
||||||
lateinit var referenceExpression: LighterASTNode
|
var referenceExpression: LighterASTNode? = null
|
||||||
|
|
||||||
val diagnostic = ConeSimpleDiagnostic(
|
|
||||||
"Type parameter annotations are not allowed inside where clauses", DiagnosticKind.AnnotationNotAllowed,
|
|
||||||
)
|
|
||||||
|
|
||||||
val annotations = mutableListOf<FirAnnotation>()
|
val annotations = mutableListOf<FirAnnotation>()
|
||||||
typeConstraint.forEachChildren {
|
typeConstraint.forEachChildren {
|
||||||
when (it.tokenType) {
|
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 -> {
|
REFERENCE_EXPRESSION -> {
|
||||||
identifier = it.asText
|
identifier = it.asText
|
||||||
referenceExpression = it
|
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 {
|
) where T : FirDeclaration, T : FirTypeParameterRefsOwner {
|
||||||
val typeParamNames = typeParameters.map { it.name }.toSet()
|
val typeParamNames = typeParameters.map { it.name }.toSet()
|
||||||
val result = typeConstraints.mapNotNull { constraint ->
|
val result = typeConstraints.mapNotNull { constraint ->
|
||||||
val name = constraint.identifier.nameAsSafeName()
|
val name = constraint.identifier?.nameAsSafeName()
|
||||||
if (!typeParamNames.contains(name)) {
|
if (name != null && !typeParamNames.contains(name)) {
|
||||||
DanglingTypeConstraint(name, constraint.source)
|
DanglingTypeConstraint(name, constraint.source)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
|
|||||||
|
|
||||||
class TypeConstraint(
|
class TypeConstraint(
|
||||||
val annotations: List<FirAnnotation>,
|
val annotations: List<FirAnnotation>,
|
||||||
val identifier: String,
|
val identifier: String?,
|
||||||
val firTypeRef: FirTypeRef,
|
val firTypeRef: FirTypeRef,
|
||||||
val source: KtSourceElement
|
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");
|
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
|
@Test
|
||||||
@TestMetadata("wildcardInValueParameter.kt")
|
@TestMetadata("wildcardInValueParameter.kt")
|
||||||
public void testWildcardInValueParameter() throws Exception {
|
public void testWildcardInValueParameter() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user