Skip to content

Commit 0ecb050

Browse files
committed
Add documentation
1 parent a5c1ebb commit 0ecb050

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ private[quoted] object Matcher {
1616
import qctx.tasty.{_, given}
1717
import Matching._
1818

19+
/** A map relating equivalent symbols from the scrutinee and the pattern
20+
* For example in
21+
* ```
22+
* '{val a = 4; a * a} match case '{ val x = 4; x * x }
23+
* ```
24+
* when matching `a * a` with `x * x` the enviroment will contain `Map(a -> x)`.
25+
*/
1926
private type Env = Map[Symbol, Symbol]
2027

2128
inline private def withEnv[T](env: Env)(body: => (given Env) => T): T = body(given env)
@@ -139,7 +146,7 @@ private[quoted] object Matcher {
139146
matched(scrutinee.seal)
140147

141148
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
142-
case (ClosedTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
149+
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
143150
if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
144151
scrutinee.tpe <:< tpt.tpe =>
145152
matched(scrutinee.seal)
@@ -301,18 +308,20 @@ private[quoted] object Matcher {
301308
}
302309
end treeOps
303310

304-
private object ClosedTerm {
311+
private object ClosedPatternTerm {
312+
/** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */
305313
def unapply(term: Term)(given Context, Env): Option[term.type] =
306-
if freeVars(term).isEmpty then Some(term) else None
314+
if freePatternVars(term).isEmpty then Some(term) else None
307315

308-
def freeVars(tree: Tree)(given qctx: Context, env: Env): Set[Symbol] =
316+
/** Return all free variables of the term defined in the pattern (i.e. defined in `Env`) */
317+
def freePatternVars(term: Term)(given qctx: Context, env: Env): Set[Symbol] =
309318
val accumulator = new TreeAccumulator[Set[Symbol]] {
310319
def foldTree(x: Set[Symbol], tree: Tree)(given ctx: Context): Set[Symbol] =
311320
tree match
312321
case tree: Ident if env.contains(tree.symbol) => foldOverTree(x + tree.symbol, tree)
313322
case _ => foldOverTree(x, tree)
314323
}
315-
accumulator.foldTree(Set.empty, tree)
324+
accumulator.foldTree(Set.empty, term)
316325
}
317326

318327
private object IdentArgs {

library/src/scala/tasty/reflect/TypeOrBoundsOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait TypeOrBoundsOps extends Core {
2929
def widen(given ctx: Context): Type = internal.Type_widen(self)
3030

3131
/** Widen from TermRef to its underlying non-termref
32-
* base type, while also skipping Expr types.
32+
* base type, while also skipping `=>T` types.
3333
*/
3434
def widenTermRefExpr(given ctx: Context): Type = internal.Type_widenTermRefExpr(self)
3535

0 commit comments

Comments
 (0)