Skip to content

Commit a429ef1

Browse files
committed
enhance FinalCaseClasses rule to allow sealed case classes and add corresponding tests
1 parent b72090f commit a429ef1

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

analyzer/src/main/scala/com/avsystem/commons/analyzer/FinalCaseClasses.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ class FinalCaseClasses(g: Global) extends AnalyzerRule(g, "finalCaseClasses", Le
1010
import global.*
1111

1212
def analyze(unit: CompilationUnit): Unit = unit.body.foreach {
13-
case cd: ClassDef if !cd.mods.hasFlag(Flag.FINAL) && cd.mods.hasFlag(Flag.CASE) =>
13+
case cd: ClassDef if !cd.mods.hasFlag(Flag.FINAL | Flag.SEALED) && cd.mods.hasFlag(Flag.CASE) =>
1414
// Skip case classes defined inside traits (SI-4440)
15-
1615
val isInner = cd.symbol.isStatic
1716

1817
if (isInner) {

analyzer/src/test/scala/com/avsystem/commons/analyzer/FinalCaseClassesTest.scala

+16-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FinalCaseClassesTest extends AnyFunSuite with AnalyzerTest {
3838
}
3939

4040
// SI-4440 https://github.com/scala/bug/issues/4440
41-
test("should not be affected due to SI-4440"){
41+
test("should not be affected due to SI-4440") {
4242
assertNoErrors(
4343
//language=scala
4444
"""
@@ -56,4 +56,19 @@ class FinalCaseClassesTest extends AnyFunSuite with AnalyzerTest {
5656
""".stripMargin
5757
)
5858
}
59+
60+
test("sealed case class should not be affected") {
61+
assertNoErrors(
62+
//language=scala
63+
"""
64+
|sealed case class SealedCaseClass(x: Int) {
65+
| def double: Int = x * 2
66+
|}
67+
|object SealedCaseClass {
68+
| val jeden = SealedCaseClass(1)
69+
| val dwa = SealedCaseClass(2)
70+
|}
71+
""".stripMargin
72+
)
73+
}
5974
}

0 commit comments

Comments
 (0)