KT-46063 Quick fix: remaining when branches for 'expect' sealed
'List<WhenMissingCase>.hasUnknown' property was changed in 4222bb9a.
As a result quickfix's AddWhenRemainingBranchesFix.Companion.isAvailable
started responding 'no'.
This commit restores original property and provides a separate one for
compiler needs.
^KT-46063 Fixed
This commit is contained in:
@@ -47,7 +47,7 @@ import java.util.*
|
|||||||
|
|
||||||
|
|
||||||
val List<WhenMissingCase>.hasUnknown: Boolean
|
val List<WhenMissingCase>.hasUnknown: Boolean
|
||||||
get() = any { it == WhenMissingCase.Unknown || it is WhenMissingCase.ConditionTypeIsExpect }
|
get() = firstOrNull() == WhenMissingCase.Unknown
|
||||||
|
|
||||||
private interface WhenExhaustivenessChecker {
|
private interface WhenExhaustivenessChecker {
|
||||||
fun getMissingCases(
|
fun getMissingCases(
|
||||||
|
|||||||
@@ -23,13 +23,11 @@ import com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.kotlin.analyzer.moduleInfo
|
import org.jetbrains.kotlin.analyzer.moduleInfo
|
||||||
import org.jetbrains.kotlin.analyzer.unwrapPlatform
|
import org.jetbrains.kotlin.analyzer.unwrapPlatform
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.cfg.hasUnknown
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newTable
|
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newTable
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newText
|
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newText
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.platform.isCommon
|
import org.jetbrains.kotlin.platform.isCommon
|
||||||
@@ -697,9 +695,12 @@ object Renderers {
|
|||||||
|
|
||||||
private val WHEN_MISSING_LIMIT = 7
|
private val WHEN_MISSING_LIMIT = 7
|
||||||
|
|
||||||
|
private val List<WhenMissingCase>.assumesElseBranchOnly: Boolean
|
||||||
|
get() = any { it == WhenMissingCase.Unknown || it is WhenMissingCase.ConditionTypeIsExpect }
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val RENDER_WHEN_MISSING_CASES = Renderer<List<WhenMissingCase>> {
|
val RENDER_WHEN_MISSING_CASES = Renderer<List<WhenMissingCase>> {
|
||||||
if (!it.hasUnknown) {
|
if (!it.assumesElseBranchOnly) {
|
||||||
val list = it.joinToString(", ", limit = WHEN_MISSING_LIMIT) { "'$it'" }
|
val list = it.joinToString(", ", limit = WHEN_MISSING_LIMIT) { "'$it'" }
|
||||||
val branches = if (it.size > 1) "branches" else "branch"
|
val branches = if (it.size > 1) "branches" else "branch"
|
||||||
"$list $branches or 'else' branch instead"
|
"$list $branches or 'else' branch instead"
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// "Add remaining branches" "true"
|
||||||
|
// SHOULD_BE_AVAILABLE_AFTER_EXECUTION
|
||||||
|
// ERROR: Expected class 'CommonSealedClass' has no actual declaration in module testModule_Common
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
|
||||||
|
expect sealed class CommonSealedClass()
|
||||||
|
class SInheritor1 : CommonSealedClass()
|
||||||
|
class SInheritor2 : CommonSealedClass()
|
||||||
|
|
||||||
|
fun hello(c: CommonSealedClass): Int = <caret>when(c) {
|
||||||
|
|
||||||
|
}
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// "Add remaining branches" "true"
|
||||||
|
// SHOULD_BE_AVAILABLE_AFTER_EXECUTION
|
||||||
|
// ERROR: Expected class 'CommonSealedClass' has no actual declaration in module testModule_Common
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
|
||||||
|
expect sealed class CommonSealedClass()
|
||||||
|
class SInheritor1 : CommonSealedClass()
|
||||||
|
class SInheritor2 : CommonSealedClass()
|
||||||
|
|
||||||
|
fun hello(c: CommonSealedClass): Int = <selection><caret></selection>when(c) {
|
||||||
|
is SInheritor1 -> TODO()
|
||||||
|
is SInheritor2 -> TODO()
|
||||||
|
else -> TODO()
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Add remaining branches" "true"
|
||||||
|
// SHOULD_BE_AVAILABLE_AFTER_EXECUTION
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
|
||||||
|
sealed class CommonSealedClass()
|
||||||
|
class SInheritor1 : CommonSealedClass()
|
||||||
|
class SInheritor2 : CommonSealedClass()
|
||||||
|
|
||||||
|
fun hello(c: CommonSealedClass): Int = <caret>when(c) {
|
||||||
|
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// "Add remaining branches" "true"
|
||||||
|
// SHOULD_BE_AVAILABLE_AFTER_EXECUTION
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
// ERROR: Unresolved reference: TODO
|
||||||
|
|
||||||
|
sealed class CommonSealedClass()
|
||||||
|
class SInheritor1 : CommonSealedClass()
|
||||||
|
class SInheritor2 : CommonSealedClass()
|
||||||
|
|
||||||
|
fun hello(c: CommonSealedClass): Int = <selection><caret></selection>when(c) {
|
||||||
|
is SInheritor1 -> TODO()
|
||||||
|
is SInheritor2 -> TODO()
|
||||||
|
}
|
||||||
+10
@@ -416,6 +416,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
|||||||
runTest("idea/testData/multiModuleQuickFix/createActual/enum/");
|
runTest("idea/testData/multiModuleQuickFix/createActual/enum/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("expectSealedInCommonWhen")
|
||||||
|
public void testExpectSealedInCommonWhen() throws Exception {
|
||||||
|
runTest("idea/testData/multiModuleQuickFix/createActual/expectSealedInCommonWhen/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("function")
|
@TestMetadata("function")
|
||||||
public void testFunction() throws Exception {
|
public void testFunction() throws Exception {
|
||||||
runTest("idea/testData/multiModuleQuickFix/createActual/function/");
|
runTest("idea/testData/multiModuleQuickFix/createActual/function/");
|
||||||
@@ -476,6 +481,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
|||||||
runTest("idea/testData/multiModuleQuickFix/createActual/sealed/");
|
runTest("idea/testData/multiModuleQuickFix/createActual/sealed/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("sealedInCommonWhen")
|
||||||
|
public void testSealedInCommonWhen() throws Exception {
|
||||||
|
runTest("idea/testData/multiModuleQuickFix/createActual/sealedInCommonWhen/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("sealedSubclass")
|
@TestMetadata("sealedSubclass")
|
||||||
public void testSealedSubclass() throws Exception {
|
public void testSealedSubclass() throws Exception {
|
||||||
runTest("idea/testData/multiModuleQuickFix/createActual/sealedSubclass/");
|
runTest("idea/testData/multiModuleQuickFix/createActual/sealedSubclass/");
|
||||||
|
|||||||
Reference in New Issue
Block a user