Skip to content

Commit e218978

Browse files
committed
add tests for explicit generics on case classes
1 parent bfcaf8a commit e218978

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,22 @@ final class ExplicitGenericsTest extends AnyFunSuite with AnalyzerTest {
4343
}
4444

4545
test("inferred in constructor should be rejected") {
46-
assertErrors(1,
46+
assertErrors(2,
4747
scala"""
4848
|import com.avsystem.commons.analyzer.TestUtils
4949
|
5050
|val x = new TestUtils.GenericClass()
51+
|val y = new TestUtils.GenericCaseClass(123)
52+
|""".stripMargin)
53+
}
54+
55+
56+
test("inferred in apply when constructor marked should be rejected") {
57+
assertErrors(1,
58+
scala"""
59+
|import com.avsystem.commons.analyzer.TestUtils
60+
|
61+
|val x = TestUtils.GenericCaseClass(123)
5162
|""".stripMargin)
5263
}
5364

@@ -59,4 +70,18 @@ final class ExplicitGenericsTest extends AnyFunSuite with AnalyzerTest {
5970
|val x = new TestUtils.GenericClass[Int]()
6071
|""".stripMargin)
6172
}
73+
74+
test("not marked should not be rejected") {
75+
assertNoErrors(
76+
scala"""
77+
|def method[T](e: T) = e
78+
|class NotMarkedGenericClass[T]
79+
|final case class NotMarkedGenericCaseClass[T](arg: T)
80+
|
81+
|val w = method(123)
82+
|val x = new NotMarkedGenericClass()
83+
|val y = NotMarkedGenericCaseClass(123)
84+
|val z = new NotMarkedGenericClass()
85+
|""".stripMargin)
86+
}
6287
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ object TestUtils {
3232
@explicitGenerics
3333
class GenericClass[T]
3434

35+
@explicitGenerics
3536
case class GenericCaseClass[T](arg: T)
3637
}

0 commit comments

Comments
 (0)