Skip to content

Commit b0e33f5

Browse files
committed
Merge commit 'c58b240' into develop
2 parents d76af28 + c58b240 commit b0e33f5

File tree

6 files changed

+749
-696
lines changed

6 files changed

+749
-696
lines changed

src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala

Lines changed: 694 additions & 668 deletions
Large diffs are not rendered by default.

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
33033303
val owntype = elimAnonymousClass(owntype0)
33043304
if (needAdapt) cases1 = cases1 map (adaptCase(_, owntype))
33053305

3306-
(new MatchTranslator(this)).translateMatch(selector1, cases1, owntype) match {
3306+
(MatchTranslator(this)).translateMatch(selector1, cases1, owntype) match {
33073307
case Block(vd :: Nil, tree@Match(selector, cases)) =>
33083308
val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode, WildcardType))
33093309
var cases1 = typedCases(tree, cases, packCaptured(selector1.tpe.widen), pt)

src/library/scala/MatchingStrategy.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runOrElse(7, ?guard(false,?).flatMap(? =>one(foo)).orElse(one(bar)))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yvirtpatmat -Xexperimental
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
trait Intf {
2+
type Rep[+T]
3+
type M[+T] = Rep[Maybe[T]]
4+
5+
val __match: Matcher
6+
abstract class Matcher {
7+
// runs the matcher on the given input
8+
def runOrElse[T, U](in: Rep[T])(matcher: Rep[T] => M[U]): Rep[U]
9+
10+
def zero: M[Nothing]
11+
def one[T](x: Rep[T]): M[T]
12+
def guard[T](cond: Rep[Boolean], then: => Rep[T]): M[T]
13+
def isSuccess[T, U](x: Rep[T])(f: Rep[T] => M[U]): Rep[Boolean] // used for isDefinedAt
14+
}
15+
16+
abstract class Maybe[+A] {
17+
def flatMap[B](f: Rep[A] => M[B]): M[B]
18+
def orElse[B >: A](alternative: => M[B]): M[B]
19+
}
20+
21+
implicit def proxyMaybe[A](m: M[A]): Maybe[A]
22+
implicit def repInt(x: Int): Rep[Int]
23+
implicit def repBoolean(x: Boolean): Rep[Boolean]
24+
implicit def repString(x: String): Rep[String]
25+
26+
def test = 7 match { case 5 => "foo" case _ => "bar" }
27+
}
28+
29+
trait Impl extends Intf {
30+
type Rep[+T] = String
31+
32+
object __match extends Matcher {
33+
def runOrElse[T, U](in: Rep[T])(matcher: Rep[T] => M[U]): Rep[U] = ("runOrElse("+ in +", ?" + matcher("?") + ")")
34+
def zero: M[Nothing] = "zero"
35+
def one[T](x: Rep[T]): M[T] = "one("+x.toString+")"
36+
def guard[T](cond: Rep[Boolean], then: => Rep[T]): M[T] = "guard("+cond+","+then+")"
37+
def isSuccess[T, U](x: Rep[T])(f: Rep[T] => M[U]): Rep[Boolean] = ("isSuccess("+x+", ?" + f("?") + ")")
38+
}
39+
40+
implicit def proxyMaybe[A](m: M[A]): Maybe[A] = new Maybe[A] {
41+
def flatMap[B](f: Rep[A] => M[B]): M[B] = m + ".flatMap(? =>"+ f("?") +")"
42+
def orElse[B >: A](alternative: => M[B]): M[B] = m + ".orElse("+ alternative +")"
43+
}
44+
45+
def repInt(x: Int): Rep[Int] = x.toString
46+
def repBoolean(x: Boolean): Rep[Boolean] = x.toString
47+
def repString(x: String): Rep[String] = x
48+
}
49+
50+
object Test extends Impl with Intf with App {
51+
println(test)
52+
}

0 commit comments

Comments
 (0)