Skip to content

Commit

Permalink
Merge pull request #13224 from dotty-staging/fix-13218
Browse files Browse the repository at this point in the history
Weaken assertion for duplicate attachments
  • Loading branch information
anatoliykmetyuk authored Aug 2, 2021
2 parents 2191757 + 0450ca0 commit 160d63e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
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 = ???

0 comments on commit 160d63e

Please sign in to comment.