FIR IDE: Enforce an order on subclasses of sealed class
Currently the order is non-determinstic, causing non-determinstic behavior in the IDE diagnostics. This change enforces an alphabetic order.
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
c198c57e62
commit
8805675539
+4
-1
@@ -84,6 +84,9 @@ class FirIdeSealedHierarchyProcessor(session: FirSession, scopeSession: ScopeSes
|
|||||||
.mapNotNull { it.classIdIfNonLocal() }
|
.mapNotNull { it.classIdIfNonLocal() }
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
|
// Enforce a deterministic order on the result.
|
||||||
|
subclasses.sortBy { it.toString() }
|
||||||
|
|
||||||
data[regularClass] = subclasses
|
data[regularClass] = subclasses
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,4 +101,4 @@ class FirIdeSealedHierarchyProcessor(session: FirSession, scopeSession: ScopeSes
|
|||||||
private fun getPackageViaDirectoryService(ktClass: KtClass): PsiPackage? {
|
private fun getPackageViaDirectoryService(ktClass: KtClass): PsiPackage? {
|
||||||
val directory = ktClass.containingFile.containingDirectory ?: return null
|
val directory = ktClass.containingFile.containingDirectory ?: return null
|
||||||
return JavaDirectoryService.getInstance().getPackage(directory)
|
return JavaDirectoryService.getInstance().getPackage(directory)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ sealed class Variant {
|
|||||||
object Another : Variant()
|
object Another : Variant()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun nonExhaustiveSealed(v: Variant) = <error descr="[NO_ELSE_IN_WHEN] 'when' expression must be exhaustive, add necessary 'is Something', 'Another' branches or 'else' branch instead">when</error>(v) {
|
fun nonExhaustiveSealed(v: Variant) = <error descr="[NO_ELSE_IN_WHEN] 'when' expression must be exhaustive, add necessary 'Another', 'is Something' branches or 'else' branch instead">when</error>(v) {
|
||||||
Variant.Singleton -> false
|
Variant.Singleton -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user