Skip to content

Fix Tasty reflect patterns with select trees #4675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

@liufengyun liufengyun Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When used in a traverser or accumulator, a method-select may qualify. Also, it may return true for implicit params of extractors. Maybe add a doc for potential misuse.

case _ => None
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/simpleMatchRef.decompiled
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/pos/simpleMatchRef.scala
Original file line number Diff line number Diff line change
@@ -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