Skip to content

Commit a8cc076

Browse files
committed
Add new utility method: withAttachment
1 parent e389a37 commit a8cc076

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

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

+1-2
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

+1-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
259259
}
260260

261261
/** Install the derived type tree as a dependency on `sym` */
262-
def watching(sym: Symbol): this.type = {
263-
pushAttachment(OriginalSymbol, sym)
264-
this
265-
}
262+
def watching(sym: Symbol): this.type = withAttachment(OriginalSymbol, sym)
266263

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ class Typer extends Namer
24262426
def tryApply(implicit ctx: Context) = {
24272427
val pt1 = pt.withContext(ctx)
24282428
val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt1)
2429-
sel.pushAttachment(InsertedApply, ())
2429+
.withAttachment(InsertedApply, ())
24302430
if (sel.tpe.isError) sel
24312431
else try adapt(simplify(sel, pt1, locked), pt1, locked) finally sel.removeAttachment(InsertedApply)
24322432
}

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

+5
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)