diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-07-25 10:21:26 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-07-25 10:28:32 +1000 |
commit | a2cba53e18864a5b9092f1e329c6e0afb09566c5 (patch) | |
tree | abb8bdde67d24f3106fbde27e43d2420e8eee671 /test | |
parent | 6b99dfe746cbb76828db495b58e55db2a0265ee2 (diff) | |
download | scala-a2cba53e18864a5b9092f1e329c6e0afb09566c5.tar.gz scala-a2cba53e18864a5b9092f1e329c6e0afb09566c5.tar.bz2 scala-a2cba53e18864a5b9092f1e329c6e0afb09566c5.zip |
SD-167 Fine tuning constructor pattern translation
- Avoid calling NoSymbol.owner when checking whether we're
dealing with a case class constructor pattern or a general
extractor. Tested manually with the test case in the ticket,
no more output is produced under `-Xdev`.
- Be more conservative about the conversion to a case class
pattern: rather than looking just at the type of the pattern
tree, also look at the tree itself to ensure its safe to
elide. This change is analagous to SI-4859, which restricted
rewrites of case apply calls to case constructors.
I've manually tested that case class patterns are still efficiently
translated:
```
object Test {
def main(args: Array[String]) {
Some(1) match { case Some(x) => }
}
}
```
```
% qscalac -Xprint:patmat sandbox/test.scala
[[syntax trees at end of patmat]] // test.scala
package <empty> {
object Test extends scala.AnyRef {
def <init>(): Test.type = {
Test.super.<init>();
()
};
def main(args: Array[String]): Unit = {
case <synthetic> val x1: Some[Int] = scala.Some.apply[Int](1);
case4(){
if (x1.ne(null))
matchEnd3(())
else
case5()
};
case5(){
matchEnd3(throw new MatchError(x1))
};
matchEnd3(x: Unit){
x
}
}
}
}
```
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/sd167.check | 1 | ||||
-rw-r--r-- | test/files/run/sd167.scala | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/test/files/run/sd167.check b/test/files/run/sd167.check new file mode 100644 index 0000000000..587be6b4c3 --- /dev/null +++ b/test/files/run/sd167.check @@ -0,0 +1 @@ +x diff --git a/test/files/run/sd167.scala b/test/files/run/sd167.scala new file mode 100644 index 0000000000..5095e772ad --- /dev/null +++ b/test/files/run/sd167.scala @@ -0,0 +1,8 @@ +object Test { + implicit class ToExtractor(val s: StringContext) { + def x = {println("x"); Some } + } + def main(args: Array[String]) { + Some(1) match { case x"${a}" => } // used to convert to `case Some(a) =>` and omit side effects + } +} |