Skip to content

Commit 78ba7d5

Browse files
authored
Merge pull request #9320 from dotty-staging/fix-#9294
Fix #9294: Harden pushAttachment
2 parents d735476 + 69a0b57 commit 78ba7d5

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dotty.tools.dotc.util
22

3+
import dotty.tools.dotc.core.Contexts.Context
4+
35
/** A class inheriting from Attachment.Container supports
46
* adding, removing and lookup of attachments. Attachments are typed key/value pairs.
57
*
@@ -103,19 +105,19 @@ object Attachment {
103105
final def withAttachmentsFrom(container: Container): this.type = {
104106
var current: Link[?] = container.next
105107
while (current != null) {
106-
if (current.key.isInstanceOf[StickyKey[?]]) pushAttachment(current.key, current.value)
108+
if (current.key.isInstanceOf[StickyKey[?]]) putAttachment(current.key, current.value)
107109
current = current.next
108110
}
109111
this
110112
}
111113

112114
def withAttachment[V](key: Key[V], value: V): this.type = {
113-
pushAttachment(key, value)
115+
putAttachment(key, value)
114116
this
115117
}
116118

117-
final def pushAttachment[V](key: Key[V], value: V): Unit = {
118-
assert(!hasAttachment(key), s"duplicate attachment for key $key")
119+
final def pushAttachment[V](key: Key[V], value: V)(using ctx: Context): Unit = {
120+
assert(!hasAttachment(key) || ctx.reporter.errorsReported, s"duplicate attachment for key $key")
119121
next = new Link(key, value, next)
120122
}
121123

tests/neg/i9294.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@foo class foo[X] // error // error

0 commit comments

Comments
 (0)