Skip to content

MatchError while traversing the Tasty tree using TastyInspector #14027

Closed
@BarkingBad

Description

@BarkingBad

Compiler version

Scala code runner version 3.1.2-RC1-bin-SNAPSHOT-git-0f6d16e -- Copyright 2002-2021, LAMP/EPFL (newest)

Minimized code

import scala.quoted.*
import scala.tasty.inspector.*

class Test:
  List() match
    case Nil => 1
    case _ :: tail => 2

class I extends Inspector:
  override def inspect(using q: Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
    import q.reflect.*
    val tree: Tree = tastys(0).ast
    val traverser = new TreeTraverser {}
    traverser.traverseTree(tree)(tree.symbol)

object Main extends App:
  TastyInspector.inspectAllTastyFiles(List("here/Test.tasty"), Nil, Nil)(new I)

Simply copy it into bug.scala and run

mkdir here
bin/scalac -d here bug.scala && bin/scala bug.scala        

Output

scala.MatchError: Typed(UnApply(TypeApply(Select(Ident(::),unapply),List(TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Nothing)])),List(),List(Ident(_), Bind(tail,Ident(_)))),TypeTree[AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class collection)),object immutable),::),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Nothing)))]) (of class dotty.tools.dotc.ast.Trees$Typed)
        at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree(Quotes.scala:4427)
        at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree$(Quotes.scala:4340)
        at I$$anon$1.foldOverTree(bug.scala:13)
        at scala.quoted.Quotes$reflectModule$TreeTraverser.traverseTreeChildren(Quotes.scala:4449)
        at scala.quoted.Quotes$reflectModule$TreeTraverser.traverseTreeChildren$(Quotes.scala:4443)
        at I$$anon$1.traverseTreeChildren(bug.scala:13)
        ...

Expectation

Completes without error

This code was working good in 3.1.0-RC1 and stopped working in 3.1.0. My guess is that the problem comes from match here:
https://github.com/lampepfl/dotty/blob/master/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala#L344
UnApply is subtype tpd.PatternTree which returns None. I claim so, because I have encountered some Typed(...) that were not causing problem with traversing, but all of them returned Some(...) from this function.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions