From 193386a9f325373a84fd132823cc588c996c8c3e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Jun 2018 07:37:51 +0200 Subject: [PATCH] Fix Tasty reflect patterns with select trees --- .../dotty/tools/dotc/tastyreflect/TastyImpl.scala | 2 +- tests/pos/simpleMatchRef.decompiled | 12 ++++++++++++ tests/pos/simpleMatchRef.scala | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/pos/simpleMatchRef.decompiled create mode 100644 tests/pos/simpleMatchRef.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala index ce2ac50fad10..7b239d8812d9 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala @@ -474,7 +474,7 @@ object TastyImpl extends scala.tasty.Tasty { object Value extends ValueExtractor { def unapply(x: Pattern)(implicit ctx: Context): Option[Term] = x match { case lit: tpd.Literal @unchecked => Some(lit) - case ident: tpd.Ident @unchecked if ident.isTerm => Some(ident) + case ref: tpd.RefTree @unchecked if ref.isTerm => Some(ref) case _ => None } } diff --git a/tests/pos/simpleMatchRef.decompiled b/tests/pos/simpleMatchRef.decompiled new file mode 100644 index 000000000000..3f07fe83bc65 --- /dev/null +++ b/tests/pos/simpleMatchRef.decompiled @@ -0,0 +1,12 @@ +/** Decompiled from out/posTestFromTasty/pos/simpleMatchRef/Foo.class */ +class Foo() { + val X: scala.Int = scala.Predef.??? + def foo(x: scala.Any): scala.Unit = x match { + case this.X => + scala.Predef.println("a") + case Y => + scala.Predef.println("b") + } +} +/** Decompiled from out/posTestFromTasty/pos/simpleMatchRef/Y.class */ +object Y diff --git a/tests/pos/simpleMatchRef.scala b/tests/pos/simpleMatchRef.scala new file mode 100644 index 000000000000..4048a68c2088 --- /dev/null +++ b/tests/pos/simpleMatchRef.scala @@ -0,0 +1,10 @@ + +class Foo { + val X: Int = ??? + def foo(x: Any): Unit = x match { + case X => println("a") + case Y => println("b") + } +} + +object Y