Skip to content

Commit 160d63e

Browse files
Merge pull request #13224 from dotty-staging/fix-13218
Weaken assertion for duplicate attachments
2 parents 2191757 + 0450ca0 commit 160d63e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,17 @@ object Contexts {
929929
/** Flag to suppress inlining, set after overflow */
930930
private[dotc] var stopInlining: Boolean = false
931931

932+
/** A variable that records that some error was reported in a globally committable context.
933+
* The error will not necessarlily be emitted, since it could still be that
934+
* the enclosing context will be aborted. The variable is used as a smoke test
935+
* to turn off assertions that might be wrong if the program is erroneous. To
936+
* just test for `ctx.reporter.errorsReported` is not always enough, since it
937+
* could be that the context in which the assertion is tested is a completer context
938+
* that's different from the context where the error was reported. See i13218.scala
939+
* for a test.
940+
*/
941+
private[dotc] var errorsToBeReported = false
942+
932943
// Reporters state
933944
private[dotc] var indent: Int = 0
934945

@@ -958,6 +969,7 @@ object Contexts {
958969
uniqueNamedTypes.clear()
959970
emptyTypeBounds = null
960971
emptyWildcardBounds = null
972+
errorsToBeReported = false
961973
errorTypeMsg.clear()
962974
sources.clear()
963975
files.clear()

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ abstract class Reporter extends interfaces.ReporterResult {
157157
case dia: Error =>
158158
errors = dia :: errors
159159
_errorCount += 1
160+
if ctx.typerState.isGlobalCommittable then
161+
ctx.base.errorsToBeReported = true
160162
case dia: Info => // nothing to do here
161163
// match error if d is something else
162164

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ object Attachment {
117117
}
118118

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

tests/neg/i13218.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class TagTest extends AnyFreeSpec:
2+
"a" - {
3+
"b" in {
4+
class TF[F[_]]
5+
meow // error
6+
}
7+
}
8+
9+
trait AnyFreeSpec:
10+
protected class Wrapper(s: String):
11+
def -(f: => Unit): Unit = ???
12+
def in(f: => Unit): Unit = ???
13+
14+
implicit def wrap(s: String): Wrapper = ???

0 commit comments

Comments
 (0)