File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ import scala .util .FromDigits
2
+
3
+ object Test extends App {
4
+
5
+ val x : BigInt = 13232202002020202020202 // error
6
+ val z : BigDecimal = 132322020020.223 // error
7
+
8
+ case class Even (n : Int )
9
+
10
+ given FromDigits [Even ] {
11
+ def fromDigits (digits : String ): Even = {
12
+ val intValue = digits.toInt
13
+ if (intValue % 2 == 0 ) Even (intValue)
14
+ else throw FromDigits .MalformedNumber ()
15
+ }
16
+ }
17
+
18
+ val e : Even = 1234 // error
19
+
20
+ try {
21
+ println(123 : Even ) // error
22
+ } catch {
23
+ case ex : FromDigits .MalformedNumber => println(" malformed" )
24
+ }
25
+
26
+ x match {
27
+ case 13_232_202_002_020_202_020_202 => () // error
28
+ }
29
+ (x : Any ) match {
30
+ case 13232202002020202020202 : BigInt => () // error
31
+ }
32
+ x match {
33
+ case 13232202002020202020202 => assert(false ) // error
34
+ case - 0xaabb12345ACF12345AC => () // error
35
+ }
36
+
37
+ (e : Any ) match {
38
+ case 1234 : Even => // error
39
+ case _ : Even => // error
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments