Skip to content

Commit

Permalink
Merge pull request #253 from sjrd/shared-term-in-pattern
Browse files Browse the repository at this point in the history
Handle SHAREDterm's in `readPattern`.
  • Loading branch information
bishabosha authored Feb 8, 2023
2 parents 9d8bb36 + ed32e02 commit c63ef7b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ lazy val tastyQuery =
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core.*
Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem]("tastyquery.Trees#PatternTree.withSpan"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("tastyquery.Types#Type.findMember"),
)
},
Expand Down
4 changes: 3 additions & 1 deletion tasty-query/shared/src/main/scala/tastyquery/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ object Trees {
override final def withSpan(span: Span): CaseDef = CaseDef(pattern, guard, body)(span)
}

sealed abstract class PatternTree(span: Span) extends Tree(span)
sealed abstract class PatternTree(span: Span) extends Tree(span):
def withSpan(span: Span): PatternTree
end PatternTree

/** Wildcard pattern `_`. */
final case class WildcardPattern(tpe: Type)(span: Span) extends PatternTree(span):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,10 @@ private[tasties] class TreeUnpickler(
val patType = readType
val patterns = reader.until(end)(readPattern)
Unapply(fun, args, patterns)(spn)
case SHAREDterm =>
val spn = span
reader.readByte()
forkAt(reader.readAddr()).readPattern.withSpan(spn)
case _ =>
val expr = readTerm
ExprPattern(expr)(expr.span)
Expand Down
22 changes: 22 additions & 0 deletions tasty-query/shared/src/test/scala/tastyquery/ReadTreeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,28 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
assert(containsSubtree(tryMatch)(clue(tree)))
}

testUnpickle("for-expressions", "simple_trees.ForExpressions") { tree =>
val test1Def = findTree(tree) { case test1Def @ DefDef(SimpleName("test1"), _, _, _, _) =>
test1Def
}

val forExpressionMatch1: StructureCheck = {
case CaseDef(
Unapply(
TypeApply(Select(Ident(SimpleName("Tuple2")), SignedName(SimpleName("unapply"), _, _)), _),
Nil,
List(
Bind(i, WildcardPattern(TypeRefInternal(_, TypeName(SimpleName("Int")))), _),
WildcardPattern(TypeRefInternal(_, TypeName(SimpleName("String"))))
)
),
None,
Literal(Constant(true))
) =>
}
assert(containsSubtree(forExpressionMatch1)(clue(test1Def)))
}

testUnpickle("singletonType", "simple_trees.SingletonType") { tree =>
val defDefWithSingleton: StructureCheck = {
case DefDef(
Expand Down
10 changes: 10 additions & 0 deletions test-sources/src/main/scala/simple_trees/ForExpressions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package simple_trees

class ForExpressions:
val listOfTups = List((1, "foo"))

def test1(): Unit =
for (i, _) <- listOfTups do
println(i)
end test1
end ForExpressions

0 comments on commit c63ef7b

Please sign in to comment.