Extract diagnostics about 'sealed when' to a separate one

^KT-59152
This commit is contained in:
Mikhail Zarechenskiy
2023-06-07 14:33:05 +02:00
committed by Space Team
parent c613b312f9
commit d772126f2c
4 changed files with 9 additions and 7 deletions
@@ -480,7 +480,7 @@ object WhenChecker {
fun checkSealedWhenIsReserved(sink: DiagnosticSink, element: PsiElement) { fun checkSealedWhenIsReserved(sink: DiagnosticSink, element: PsiElement) {
KtPsiUtil.getPreviousWord(element, "sealed")?.let { KtPsiUtil.getPreviousWord(element, "sealed")?.let {
sink.report(Errors.UNSUPPORTED.on(it, "sealed when")) sink.report(Errors.UNSUPPORTED_SEALED_WHEN.on(it))
} }
} }
} }
@@ -78,6 +78,7 @@ public interface Errors {
DiagnosticFactory0<KtElement> EXPLICIT_BACKING_FIELDS_UNSUPPORTED = DiagnosticFactory0.create(ERROR); DiagnosticFactory0<KtElement> EXPLICIT_BACKING_FIELDS_UNSUPPORTED = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> UNSUPPORTED_INHERITANCE_FROM_JAVA_MEMBER_REFERENCING_KOTLIN_FUNCTION = DiagnosticFactory1.create(ERROR); DiagnosticFactory1<PsiElement, String> UNSUPPORTED_INHERITANCE_FROM_JAVA_MEMBER_REFERENCING_KOTLIN_FUNCTION = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> UNSUPPORTED_SEALED_WHEN = DiagnosticFactory0.create(ERROR);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -826,6 +826,7 @@ public class DefaultErrorMessages {
MAP.put(EXPLICIT_BACKING_FIELDS_UNSUPPORTED, "Explicit backing field declarations are not supported in FE 1.0"); MAP.put(EXPLICIT_BACKING_FIELDS_UNSUPPORTED, "Explicit backing field declarations are not supported in FE 1.0");
MAP.put(UNSUPPORTED_INHERITANCE_FROM_JAVA_MEMBER_REFERENCING_KOTLIN_FUNCTION, "Inheritance of a Java member referencing 'kotlin.jvm.functions.FunctionN': {0} is unsupported", STRING); MAP.put(UNSUPPORTED_INHERITANCE_FROM_JAVA_MEMBER_REFERENCING_KOTLIN_FUNCTION, "Inheritance of a Java member referencing 'kotlin.jvm.functions.FunctionN': {0} is unsupported", STRING);
MAP.put(UNSUPPORTED_SEALED_WHEN, "'sealed' in front of 'when' is reserved");
MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE);
MAP.put(MISSING_STDLIB, "{0}. Ensure you have the standard Kotlin library in dependencies", STRING); MAP.put(MISSING_STDLIB, "{0}. Ensure you have the standard Kotlin library in dependencies", STRING);
@@ -11,22 +11,22 @@
infix fun Any.sealed(a: Any?) {} infix fun Any.sealed(a: Any?) {}
val x = 1 <!UNSUPPORTED!>sealed<!> when (1) { val x = 1 <!UNSUPPORTED_SEALED_WHEN!>sealed<!> when (1) {
1 -> 1 1 -> 1
else -> 2 else -> 2
} }
val x1 = 1 <!UNSUPPORTED!>sealed<!> /**/ when (1) { val x1 = 1 <!UNSUPPORTED_SEALED_WHEN!>sealed<!> /**/ when (1) {
1 -> 1 1 -> 1
else -> 2 else -> 2
} }
fun foo() { fun foo() {
<!UNRESOLVED_REFERENCE, UNSUPPORTED!>sealed<!><!SYNTAX!><!> when { <!UNRESOLVED_REFERENCE, UNSUPPORTED_SEALED_WHEN!>sealed<!><!SYNTAX!><!> when {
else -> {} else -> {}
} }
1 <!UNSUPPORTED!>sealed<!> when { 1 <!UNSUPPORTED_SEALED_WHEN!>sealed<!> when {
else -> {} else -> {}
} }
@@ -35,11 +35,11 @@ fun foo() {
}) })
1 1
<!UNRESOLVED_REFERENCE, UNSUPPORTED!>sealed<!><!SYNTAX!><!> when { <!UNRESOLVED_REFERENCE, UNSUPPORTED_SEALED_WHEN!>sealed<!><!SYNTAX!><!> when {
else -> {} else -> {}
} }
1 <!UNSUPPORTED!>sealed<!> 1 <!UNSUPPORTED_SEALED_WHEN!>sealed<!>
when { when {
else -> {} else -> {}
} }