File tree Expand file tree Collapse file tree 7 files changed +19
-11
lines changed
test/dotty/tools/dotc/ast Expand file tree Collapse file tree 7 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ import dotty.tools.dotc.core.TypeError
9
9
import scala .annotation .tailrec
10
10
11
11
/** A TreeMap that maintains the necessary infrastructure to support
12
- * contxtual implicit searches (type-scope implicits are supported anyway).
12
+ * contextual implicit searches (type-scope implicits are supported anyway).
13
13
*
14
- * This incudes impicits defined in scope as well as imported implicits.
14
+ * This incudes implicits defined in scope as well as imported implicits.
15
15
*/
16
16
class TreeMapWithImplicits extends tpd.TreeMap {
17
17
import tpd ._
Original file line number Diff line number Diff line change @@ -437,7 +437,7 @@ object Trees {
437
437
extends GenericApply [T ] {
438
438
type ThisTree [- T >: Untyped ] = Apply [T ]
439
439
440
- def isGivenApply = getAttachment (untpd.ApplyGiven ).nonEmpty
440
+ def isGivenApply = hasAttachment (untpd.ApplyGiven )
441
441
def setGivenApply () = { pushAttachment(untpd.ApplyGiven , ()); this }
442
442
}
443
443
Original file line number Diff line number Diff line change @@ -298,7 +298,7 @@ object TypeTestsCasts {
298
298
299
299
if (sym.isTypeTest) {
300
300
val argType = tree.args.head.tpe
301
- val isTrusted = tree.getAttachment (PatternMatcher .TrustedTypeTestKey ).nonEmpty
301
+ val isTrusted = tree.hasAttachment (PatternMatcher .TrustedTypeTestKey )
302
302
if (! isTrusted && ! checkable(expr.tpe, argType, tree.span))
303
303
ctx.warning(i " the type test for $argType cannot be checked at runtime " , tree.sourcePos)
304
304
transformTypeTest(expr, tree.args.head.tpe, flagUnrelated = true )
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ trait TypeAssigner {
282
282
*/
283
283
def accessibleSelectionType (tree : untpd.RefTree , qual1 : Tree )(implicit ctx : Context ): Type = {
284
284
val ownType = selectionType(tree, qual1)
285
- if (tree.getAttachment (desugar.SuppressAccessCheck ).isDefined ) ownType
285
+ if (tree.hasAttachment (desugar.SuppressAccessCheck )) ownType
286
286
else ensureAccessible(ownType, qual1.isInstanceOf [Super ], tree.sourcePos)
287
287
}
288
288
Original file line number Diff line number Diff line change @@ -2437,7 +2437,7 @@ class Typer extends Namer
2437
2437
}
2438
2438
2439
2439
def isSyntheticApply (tree : Tree ): Boolean = tree match {
2440
- case tree : Select => tree.getAttachment (InsertedApply ).isDefined
2440
+ case tree : Select => tree.hasAttachment (InsertedApply )
2441
2441
case _ => false
2442
2442
}
2443
2443
@@ -2459,7 +2459,7 @@ class Typer extends Namer
2459
2459
else pt match {
2460
2460
case pt @ FunProto (Nil , _)
2461
2461
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) &&
2462
- tree.getAttachment (DroppedEmptyArgs ).isEmpty =>
2462
+ ! tree.hasAttachment (DroppedEmptyArgs ) =>
2463
2463
tree.putAttachment(DroppedEmptyArgs , ())
2464
2464
pt.markAsDropped()
2465
2465
tree
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ object Attachment {
23
23
else nx.getAttachment[V ](key)
24
24
}
25
25
26
+ /** Does an attachment corresponding to `key` exist? */
27
+ final def hasAttachment [V ](key : Key [V ]): Boolean = {
28
+ val nx = next
29
+ if (nx == null ) false
30
+ else if (nx.key eq key) true
31
+ else nx.hasAttachment[V ](key)
32
+ }
33
+
26
34
/** The attachment corresponding to `key`.
27
35
* @throws NoSuchElementException if no attachment with key exists
28
36
*/
@@ -107,7 +115,7 @@ object Attachment {
107
115
}
108
116
109
117
final def pushAttachment [V ](key : Key [V ], value : V ): Unit = {
110
- assert(! getAttachment (key).isDefined , s " duplicate attachment for key $key" )
118
+ assert(! hasAttachment (key), s " duplicate attachment for key $key" )
111
119
next = new Link (key, value, next)
112
120
}
113
121
Original file line number Diff line number Diff line change @@ -51,9 +51,9 @@ class AttachmentsTests extends DottyTest {
51
51
52
52
val copy = tpd.cpy.TypeDef (clazz)(rhs = tpd.EmptyTree )
53
53
assertTrue(" A copy should have been returned" , clazz ne copy)
54
- assertTrue(" Attachment should be present" , copy.getAttachment (StickyTestKey ).isDefined )
55
- assertTrue(" Attachment shouldn't be present" , copy.getAttachment (TestKey ).isEmpty )
56
- assertTrue(" Attachment should be present" , copy.getAttachment (StickyTestKey2 ).isDefined )
54
+ assertTrue(" Attachment should be present" , copy.hasAttachment (StickyTestKey ))
55
+ assertTrue(" Attachment shouldn't be present" , ! copy.hasAttachment (TestKey ))
56
+ assertTrue(" Attachment should be present" , copy.hasAttachment (StickyTestKey2 ))
57
57
58
58
case _ =>
59
59
fail
You can’t perform that action at this time.
0 commit comments