From 16d963bcb032deb669247e4a95c6391971cafd75 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 23 Sep 2013 10:35:43 +0200 Subject: SI-7868 Account for numeric widening in match translation Pattern match translation was unprepared for trees of the shape: (0: Short) match { case A.unapply(.toInt) (_) => () case _ => () } While a scrutinee is inelibigle for implicit views in order to conform to the type of the extractor call, it is allowed to weakly conform. In this case, the typechecker will add the numeric widening with a `toInt` call. This commit: - Changes treeInfo.Unapplied to recognize this tree shape - Changes spliceApply to recognize and preserve the widening when substituting the unapply selector with the binder - Tests reification of such pattern matches, which also depends on treeInfo.Unapplied. --- test/files/run/t7868.scala | 13 +++++++++++++ test/files/run/t7868b.check | 6 ++++++ test/files/run/t7868b.scala | 11 +++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/files/run/t7868.scala create mode 100644 test/files/run/t7868b.check create mode 100644 test/files/run/t7868b.scala (limited to 'test/files/run') diff --git a/test/files/run/t7868.scala b/test/files/run/t7868.scala new file mode 100644 index 0000000000..1f938adf31 --- /dev/null +++ b/test/files/run/t7868.scala @@ -0,0 +1,13 @@ +object A { + def unapply(n: Int): Option[Int] = Some(n) + + def run = (0: Short) match { + case A(_) => + case _ => + } +} + + +object Test extends App { + A.run +} diff --git a/test/files/run/t7868b.check b/test/files/run/t7868b.check new file mode 100644 index 0000000000..6577c4bc4e --- /dev/null +++ b/test/files/run/t7868b.check @@ -0,0 +1,6 @@ +Expr[Int]({ + val x = (0: Short): @unchecked match { + case A((x @ _)) => x + }; + x +}) diff --git a/test/files/run/t7868b.scala b/test/files/run/t7868b.scala new file mode 100644 index 0000000000..759eeaf862 --- /dev/null +++ b/test/files/run/t7868b.scala @@ -0,0 +1,11 @@ +object A { + def unapply(n: Int): Option[Int] = Some(1) +} + +object Test extends App { + import reflect.runtime.universe._ + println(reify { + val A(x) = (0: Short) + x + }) +} -- cgit v1.2.3