Skip to content

Commit de44d07

Browse files
committed
Introduce bindTypeSymbols utility in tpd.TreeOps
1 parent d40009a commit de44d07

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11371137
/** Replace Ident nodes references to the underlying tree that defined them */
11381138
def underlying(using Context): Tree = MapToUnderlying().transform(tree)
11391139

1140+
/** Collect all the TypeSymbol's of the type Bind nodes in the tree. */
1141+
def bindTypeSymbols(using Context): List[TypeSymbol] =
1142+
tree.collectSubTrees { case b: Bind if b.isType => b.symbol.asType }
1143+
11401144
// --- Higher order traversal methods -------------------------------
11411145

11421146
/** Apply `f` to each subtree of this tree */

compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,31 +216,21 @@ class InlineReducer(inliner: Inliner)(using Context):
216216
type TypeBindsMap = SimpleIdentityMap[TypeSymbol, java.lang.Boolean]
217217

218218
def getTypeBindsMap(pat: Tree, tpt: Tree): TypeBindsMap = {
219-
val getBinds = new TreeAccumulator[Set[TypeSymbol]] {
220-
def apply(syms: Set[TypeSymbol], t: Tree)(using Context): Set[TypeSymbol] = {
221-
val syms1 = t match {
222-
case t: Bind if t.symbol.isType =>
223-
syms + t.symbol.asType
224-
case _ => syms
225-
}
226-
foldOver(syms1, t)
227-
}
228-
}
229-
230219
// Extractors can contain Bind nodes in type parameter lists,
231220
// for that case tree looks like this:
232221
// UnApply[t @ t](pats)(implicits): T[t]
233222
// Test case is pos/inline-caseclass.scala.
223+
//
234224
// Alternatively, for explicitly specified type binds in type annotations like in
235225
// case A(B): A[t]
236226
// the tree will look like this:
237227
// Unapply[t](pats)(implicits) : T[t @ t]
238228
// and the binds will be found in the type tree instead
239229
// Test case is pos-macros/i15971
240-
val tptBinds = getBinds(Set.empty[TypeSymbol], tpt)
230+
val tptBinds = tpt.bindTypeSymbols.toSet
241231
val binds: Set[TypeSymbol] = pat match {
242232
case UnApply(TypeApply(_, tpts), _, _) =>
243-
getBinds(Set.empty[TypeSymbol], tpts) ++ tptBinds
233+
tpts.flatMap(_.bindTypeSymbols).toSet ++ tptBinds
244234
case _ => tptBinds
245235
}
246236

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,7 @@ trait TypeAssigner {
429429
def assignType(tree: untpd.CaseDef, pat: Tree, body: Tree)(using Context): CaseDef = {
430430
val ownType =
431431
if (body.isType) {
432-
val getParams = new TreeAccumulator[mutable.ListBuffer[TypeSymbol]] {
433-
def apply(ps: mutable.ListBuffer[TypeSymbol], t: Tree)(using Context) = t match {
434-
case t: Bind if t.symbol.isType => foldOver(ps += t.symbol.asType, t)
435-
case _ => foldOver(ps, t)
436-
}
437-
}
438-
val params1 = getParams(new mutable.ListBuffer[TypeSymbol](), pat).toList
432+
val params1 = pat.bindTypeSymbols
439433
val params2 = pat.tpe match
440434
case AppliedType(tycon, args) =>
441435
val tparams = tycon.typeParamSymbols

0 commit comments

Comments
 (0)