Skip to content

Add missing position to pattern constructors #5953

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
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
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dotty.tools.dotc.core.Contexts
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.StdNames.nme

trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {
trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with RootPositionImpl {

def ValueDeco(value: Value): Pattern.ValueAPI = new Pattern.ValueAPI {
def value(implicit ctx: Context): Term = value
Expand Down Expand Up @@ -74,7 +74,7 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {
object Bind extends BindModule {

def copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind =
tpd.cpy.Bind(original)(name.toTermName, pattern)
withDefaultPos(ctx => tpd.cpy.Bind(original)(name.toTermName, pattern)(ctx))

def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] = pattern match {
case IsBind(pattern) => Some((pattern.name.toString, pattern.body))
Expand All @@ -93,7 +93,7 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {
object Unapply extends UnapplyModule {

def copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply =
tpd.cpy.UnApply(original)(fun, implicits, patterns)
withDefaultPos(ctx => tpd.cpy.UnApply(original)(fun, implicits, patterns)(ctx))

def unapply(x: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = x match {
case IsUnapply(x) => Some((x.fun, x.implicits, UnapplyDeco(x).patterns))
Expand All @@ -110,7 +110,7 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {

object Alternatives extends AlternativesModule {
def apply(patterns: List[Pattern])(implicit ctx: Context): Alternatives =
tpd.Alternative(patterns)
withDefaultPos(ctx => tpd.Alternative(patterns)(ctx))

def copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives =
tpd.cpy.Alternative(original)(patterns)
Expand All @@ -131,10 +131,10 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {

object TypeTest extends TypeTestModule {
def apply(tpt: TypeTree)(implicit ctx: Context): TypeTest =
tpd.Typed(untpd.Ident(nme.WILDCARD).withType(tpt.tpe), tpt)
withDefaultPos(ctx => tpd.Typed(untpd.Ident(nme.WILDCARD)(ctx.source).withType(tpt.tpe)(ctx), tpt)(ctx))

def copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest =
tpd.cpy.Typed(original)(untpd.Ident(nme.WILDCARD).withType(tpt.tpe), tpt)
tpd.cpy.Typed(original)(untpd.Ident(nme.WILDCARD).withSpan(original.span).withType(tpt.tpe), tpt)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be an argument that we should disregard TypeTrees in TastyReflect -- they are not reliable, macros should always depend on types instead of type trees.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the trees for positions. And this is not a type tree, it is the pattern _: T of a case _: T =>


def unapply(x: Pattern)(implicit ctx: Context): Option[TypeTree] = x match {
case Trees.Typed(Trees.UnApply(_, _, _), _) => None
Expand Down