diff --git a/compiler/src/dotty/tools/dotc/util/Attachment.scala b/compiler/src/dotty/tools/dotc/util/Attachment.scala index ba182a4a50ec..582ff6da0557 100644 --- a/compiler/src/dotty/tools/dotc/util/Attachment.scala +++ b/compiler/src/dotty/tools/dotc/util/Attachment.scala @@ -1,5 +1,7 @@ package dotty.tools.dotc.util +import dotty.tools.dotc.core.Contexts.Context + /** A class inheriting from Attachment.Container supports * adding, removing and lookup of attachments. Attachments are typed key/value pairs. * @@ -103,19 +105,19 @@ object Attachment { final def withAttachmentsFrom(container: Container): this.type = { var current: Link[?] = container.next while (current != null) { - if (current.key.isInstanceOf[StickyKey[?]]) pushAttachment(current.key, current.value) + if (current.key.isInstanceOf[StickyKey[?]]) putAttachment(current.key, current.value) current = current.next } this } def withAttachment[V](key: Key[V], value: V): this.type = { - pushAttachment(key, value) + putAttachment(key, value) this } - final def pushAttachment[V](key: Key[V], value: V): Unit = { - assert(!hasAttachment(key), s"duplicate attachment for key $key") + final def pushAttachment[V](key: Key[V], value: V)(using ctx: Context): Unit = { + assert(!hasAttachment(key) || ctx.reporter.errorsReported, s"duplicate attachment for key $key") next = new Link(key, value, next) } diff --git a/tests/neg/i9294.scala b/tests/neg/i9294.scala new file mode 100644 index 000000000000..5f8c776a417c --- /dev/null +++ b/tests/neg/i9294.scala @@ -0,0 +1 @@ +@foo class foo[X] // error // error