Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weaken assertion for duplicate attachments #13224

Merged
merged 2 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,17 @@ object Contexts {
/** Flag to suppress inlining, set after overflow */
private[dotc] var stopInlining: Boolean = false

/** A variable that records that some error was reported in a globally committable context.
* The error will not necessarlily be emitted, since it could still be that
* the enclosing context will be aborted. The variable is used as a smoke test
* to turn off assertions that might be wrong if the program is erroneous. To
* just test for `ctx.reporter.errorsReported` is not always enough, since it
* could be that the context in which the assertion is tested is a completer context
* that's different from the context where the error was reported. See i13218.scala
* for a test.
*/
private[dotc] var errorsToBeReported = false

// Reporters state
private[dotc] var indent: Int = 0

Expand Down Expand Up @@ -958,6 +969,7 @@ object Contexts {
uniqueNamedTypes.clear()
emptyTypeBounds = null
emptyWildcardBounds = null
errorsToBeReported = false
errorTypeMsg.clear()
sources.clear()
files.clear()
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ abstract class Reporter extends interfaces.ReporterResult {
case dia: Error =>
errors = dia :: errors
_errorCount += 1
if ctx.typerState.isGlobalCommittable then
ctx.base.errorsToBeReported = true
case dia: Info => // nothing to do here
// match error if d is something else

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/util/Attachment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object Attachment {
}

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")
assert(!hasAttachment(key) || ctx.base.errorsToBeReported, s"duplicate attachment for key $key")
next = new Link(key, value, next)
}

Expand Down
14 changes: 14 additions & 0 deletions tests/neg/i13218.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class TagTest extends AnyFreeSpec:
"a" - {
"b" in {
class TF[F[_]]
meow // error
}
}

trait AnyFreeSpec:
protected class Wrapper(s: String):
def -(f: => Unit): Unit = ???
def in(f: => Unit): Unit = ???

implicit def wrap(s: String): Wrapper = ???