Skip to content

Commit f898fc1

Browse files
oderskymilessabin
authored andcommitted
Add new utility method: withAttachment
1 parent ed79907 commit f898fc1

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,7 @@ object desugar {
849849
fwd
850850
}
851851
val moduleName = tdef.name.toTermName
852-
val localRef = Select(Ident(moduleName), tdef.name)
853-
localRef.pushAttachment(SuppressAccessCheck, ())
852+
val localRef = Select(Ident(moduleName), tdef.name).withAttachment(SuppressAccessCheck, ())
854853
val aliasType = cpy.TypeDef(tdef)(rhs = completeForwarder(localRef)).withSpan(tdef.span.startPos)
855854
val localType = tdef.withMods(Modifiers(Synthetic | Opaque).withPrivateWithin(tdef.name))
856855

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
263263
}
264264

265265
/** Install the derived type tree as a dependency on `sym` */
266-
def watching(sym: Symbol): this.type = {
267-
pushAttachment(OriginalSymbol, sym)
268-
this
269-
}
266+
def watching(sym: Symbol): this.type = withAttachment(OriginalSymbol, sym)
270267

271268
/** A hook to ensure that all necessary symbols are completed so that
272269
* OriginalSymbol attachments are propagated to this tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,7 @@ class Typer extends Namer
24372437
def tryApply(implicit ctx: Context) = {
24382438
val pt1 = pt.withContext(ctx)
24392439
val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt1)
2440-
sel.pushAttachment(InsertedApply, ())
2440+
.withAttachment(InsertedApply, ())
24412441
if (sel.tpe.isError) sel
24422442
else try adapt(simplify(sel, pt1, locked), pt1, locked) finally sel.removeAttachment(InsertedApply)
24432443
}

compiler/src/dotty/tools/dotc/util/Attachment.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ object Attachment {
101101
this
102102
}
103103

104+
def withAttachment[V](key: Key[V], value: V): this.type = {
105+
pushAttachment(key, value)
106+
this
107+
}
108+
104109
final def pushAttachment[V](key: Key[V], value: V): Unit = {
105110
assert(!getAttachment(key).isDefined, s"duplicate attachment for key $key")
106111
next = new Link(key, value, next)

0 commit comments

Comments
 (0)