Skip to content

Commit 1d620ff

Browse files
committed
New utility method tpd.Underscore
A typed `_'. This is needed in a few places.
1 parent 2c6d287 commit 1d620ff

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
418418
Thicket(valdef, clsdef)
419419
}
420420

421+
/** A `_' with given type */
422+
def Underscore(tp: Type)(implicit ctx: Context) = untpd.Ident(nme.WILDCARD).withType(tp)
423+
421424
def defaultValue(tpe: Types.Type)(implicit ctx: Context) = {
422425
val tpw = tpe.widen
423426

src/dotty/tools/dotc/transform/ExpandSAMs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer =>
7474
val defaultSym = ctx.newSymbol(isDefinedAtFn, nme.WILDCARD, Synthetic, selector.tpe.widen)
7575
val defaultCase =
7676
CaseDef(
77-
Bind(defaultSym, untpd.Ident(nme.WILDCARD).withType(selector.tpe.widen)),
77+
Bind(defaultSym, Underscore(selector.tpe.widen)),
7878
EmptyTree,
7979
Literal(Constant(false)))
8080
cpy.Match(applyRhs)(paramRef, cases.map(translateCase) :+ defaultCase)

src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
278278
CaseDef(computedState, EmptyTree, body)
279279
}
280280

281-
val default = CaseDef(untpd.Ident(nme.WILDCARD).withType(defn.LongType), EmptyTree, Literal(Constant(())))
281+
val default = CaseDef(Underscore(defn.LongType), EmptyTree, Literal(Constant(())))
282282

283283
val cases = Match(stateMask.appliedTo(ref(flagSymbol), Literal(Constant(ord))),
284284
List(compute, waitFirst, waitSecond, computed, default)) //todo: annotate with @switch

src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
6060
val sel = Ident(selector.termRef).withPos(tree.pos)
6161
val rethrow = tpd.CaseDef(EmptyTree, EmptyTree, Throw(ref(selector)))
6262
val newCases = tpd.CaseDef(
63-
Bind(selector,untpd.Ident(nme.WILDCARD).withPos(tree.pos).withType(selector.info)),
63+
Bind(selector, Underscore(selector.info).withPos(tree.pos)),
6464
EmptyTree,
6565
transformMatch(tpd.Match(sel, tree.cases ::: rethrow :: Nil)))
6666
cpy.Try(tree)(tree.expr, newCases :: Nil, tree.finalizer)

src/dotty/tools/dotc/transform/SyntheticMethods.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
105105
*/
106106
def equalsBody(that: Tree)(implicit ctx: Context): Tree = {
107107
val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic, clazzType, coord = ctx.owner.pos) // x$0
108-
def wildcardAscription(tp: Type) =
109-
Typed(untpd.Ident(nme.WILDCARD).withType(tp), TypeTree(tp))
108+
def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp))
110109
val pattern = Bind(thatAsClazz, wildcardAscription(clazzType)) // x$0 @ (_: C)
111110
val comparisons = accessors map (accessor =>
112111
This(clazz).select(accessor).select(defn.Any_==).appliedTo(ref(thatAsClazz).select(accessor)))

0 commit comments

Comments
 (0)