Skip to content

Commit bca0d52

Browse files
oderskyWojciechMazur
authored andcommitted
Piggy-back some unrelated tests
[Cherry-picked 7539fb5]
1 parent 16c44a2 commit bca0d52

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/pos/first-class-patterns.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
// Trait of all extractors with unapply methods
3+
trait Matcher[A, B]:
4+
def unapply(x: A): Option[B]
5+
6+
// An extractor defined by an unappy method
7+
object Even extends Matcher[Int, Int]:
8+
def unapply(x: Int): Option[Int] =
9+
if x % 2 == 0 then Some(x) else None
10+
11+
// Method using a given extractor in pattern position
12+
def collect[A, B](xs: List[A], m: Matcher[A, B]): List[B] =
13+
xs match
14+
case Nil => Nil
15+
case m(x) :: xs1 => x :: collect(xs1, m)
16+
case _ :: xs1 => collect(xs1, m)
17+
18+
@main def test =
19+
val xs = List(1, 2, 3, 4)
20+
val ys = collect(xs, Even)
21+
println(ys)
22+
23+

tests/pos/into-bigint.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import language.experimental.into
2+
3+
class BigInt(x: Int):
4+
def + (other: into BigInt): BigInt = ???
5+
def * (other: into BigInt): BigInt = ???
6+
7+
object BigInt:
8+
given Conversion[Int, BigInt] = BigInt(_)
9+
10+
extension (x: into BigInt)
11+
def + (other: BigInt): BigInt = ???
12+
def * (other: BigInt): BigInt = ???
13+
14+
@main def Test =
15+
val x = BigInt(2)
16+
val y = 3
17+
val a1 = x + y
18+
val a2 = y * x
19+
val a3 = x * x
20+
val a4 = y + y
21+

0 commit comments

Comments
 (0)