Skip to content
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

foldOver in default TreeAccumulator can't process Typed nodes. #14393

Closed
rssh opened this issue Jan 31, 2022 · 2 comments · Fixed by #14396
Closed

foldOver in default TreeAccumulator can't process Typed nodes. #14393

rssh opened this issue Jan 31, 2022 · 2 comments · Fixed by #14396
Milestone

Comments

@rssh
Copy link
Contributor

rssh commented Jan 31, 2022

Compiler version

3.1.1

Minimized code

file M.scala

package x
import scala.quoted.*

object M {

  inline def useFoldTree[X](inline x:X):X = ${
     useFoldTreeImpl('x)
  }

  def useFoldTreeImpl[X:Type](x:Expr[X])(using Quotes):Expr[X] = {
     import quotes.reflect.*
     val search = new TreeAccumulator[Int] {
        def foldTree(s:Int, tree: Tree)(owner: Symbol): Int =
                 foldOverTree(s,tree)(owner)
     }
     search.foldTree(0,x.asTerm)(Symbol.spliceOwner)
     x
  }

}

File X.scala

package x

def thing() =
      M.useFoldTree {

        Option("") match
          case None =>
          case Some(_) =>
            ???

      }

Output

[info] compiling 2 Scala sources to /Users/rssh/tests/dotty/cantiBot1/target/scala-3.1.1/classes ...
[error] -- Error: /Users/rssh/tests/dotty/cantiBot1/src/main/scala/x/X.scala:5:20 ------
[error] 5 |      M.useFoldTree {
[error]    |      ^
[error]    |Exception occurred while executing macro expansion.
[error]    |scala.MatchError: Typed(UnApply(TypeApply(Select(Ident(Some),unapply),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class String)])),List(),List(Ident(_))),TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Some),List(TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class String)))]) (of class dotty.tools.dotc.ast.Trees$Typed)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree(Quotes.scala:4421)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree$(Quotes.scala:4334)
[error]    |	at x.M$$anon$1.foldOverTree(M.scala:12)
[error]    |	at x.M$$anon$1.foldTree(M.scala:14)
[error]    |	at x.M$$anon$1.foldTree(M.scala:13)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree(Quotes.scala:4417)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree$(Quotes.scala:4334)
[error]    |	at x.M$$anon$1.foldOverTree(M.scala:12)
[error]    |	at x.M$$anon$1.foldTree(M.scala:14)
[error]    |	at x.M$$anon$1.foldTree(M.scala:13)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldTrees$$anonfun$1(Quotes.scala:4339)
[error]    |	at scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:169)
[error]    |	at scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:165)
[error]    |	at scala.collection.immutable.List.foldLeft(List.scala:79)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldTrees(Quotes.scala:4339)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldTrees$(Quotes.scala:4334)
[error]    |	at x.M$$anon$1.foldTrees(M.scala:12)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree(Quotes.scala:4374)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree$(Quotes.scala:4334)
[error]    |	at x.M$$anon$1.foldOverTree(M.scala:12)
[error]    |	at x.M$$anon$1.foldTree(M.scala:14)
[error]    |	at x.M$$anon$1.foldTree(M.scala:13)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree(Quotes.scala:4366)
[error]    |	at scala.quoted.Quotes$reflectModule$TreeAccumulator.foldOverTree$(Quotes.scala:4334)
[error]    |	at x.M$$anon$1.foldOverTree(M.scala:12)
[error]    |	at x.M$$anon$1.foldTree(M.scala:14)

Expectation

Should be compiled

@rssh rssh added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 31, 2022
@smarter smarter added area:metaprogramming and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 31, 2022
@rssh
Copy link
Contributor Author

rssh commented Jan 31, 2022

cantiBot1.tar.gz

ready to run project

@rssh rssh changed the title foldOver in default TreeAccumulator can't process match statement foldOver in default TreeAccumulator can't process Typed nodes. Feb 1, 2022
rssh added a commit to rssh/dotty-cps-async that referenced this issue Feb 1, 2022
rssh added a commit to rssh/dotty-cps-async that referenced this issue Feb 1, 2022
rssh added a commit to rssh/dotty that referenced this issue Feb 1, 2022
@rssh
Copy link
Contributor Author

rssh commented Feb 2, 2022

submitted fix in #14396

@nicolasstucki nicolasstucki linked a pull request Feb 3, 2022 that will close this issue
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants