Skip to content

Commit

Permalink
Do not report data races between symbols defined in class and its sel…
Browse files Browse the repository at this point in the history
…ftype

Analogous to the previous situation where we do not report a data race
if the previous symbol comes from a superclass, we now do the same if
the previous symbol comes from a given self type. Makes overrideDataRace.scala pass,
and finally enables stdlib test with TraverableViewLike.scala added.
  • Loading branch information
odersky committed Dec 14, 2015
1 parent 6c91684 commit ac99941
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ object Symbols {

type ThisName <: Name

//assert(_id != 30214)
//assert(id != 4285)

/** The last denotation of this symbol */
private[this] var lastDenot: SymDenotation = _
Expand Down
14 changes: 10 additions & 4 deletions src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,11 @@ object Types {
if (owner.isTerm) d else d.asSeenFrom(prefix)
}

private def checkSymAssign(sym: Symbol)(implicit ctx: Context) =
private def checkSymAssign(sym: Symbol)(implicit ctx: Context) = {
def ownerSelfType = sym.owner.info match {
case info: ClassInfo => info.givenSelfType
case _ => NoType
}
assert(
(lastSymbol eq sym) ||
(lastSymbol eq null) || {
Expand All @@ -1398,9 +1402,11 @@ object Types {
(lastDefRunId == NoRunId)
} ||
(lastSymbol.infoOrCompleter == ErrorType ||
sym.owner.derivesFrom(lastSymbol.owner) && sym.owner != lastSymbol.owner
),
s"data race? overwriting symbol of ${this.show} / $this / ${this.getClass} / ${lastSymbol.id} / ${sym.id} / ${sym.owner} / ${lastSymbol.owner} / ${ctx.phase} at run ${ctx.runId}")
sym.owner != lastSymbol.owner &&
(sym.owner.derivesFrom(lastSymbol.owner) ||
ownerSelfType.derivesFrom(lastSymbol.owner))),
s"data race? overwriting symbol of ${this.show} / $this / ${this.getClass} / ${lastSymbol.id} / ${sym.id} / ${lastSymbol.owner} / ${sym.owner} / ${ctx.phase} at run ${ctx.runId}")
}

protected def sig: Signature = Signature.NotAMethod

Expand Down
2 changes: 1 addition & 1 deletion test/dotc/scala-collections.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
## those classes use early initialisers.
#./scala-scala/src/library/scala/collection/IterableViewLike.scala
#./scala-scala/src/library/scala/collection/SeqViewLike.scala
#./scala-scala/src/library/scala/collection/TraversableViewLike.scala
./scala-scala/src/library/scala/collection/TraversableViewLike.scala
#./scala-scala/src/library/scala/collection/immutable/StreamViewLike.scala

## This class causes a crash in backend.
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/overrideDataRace.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test

trait Traversable {
def mkString: String = ???
}

trait ViewMkString {
self: Traversable =>

def mkString: String = mkString("")
def mkString(s: String) = ???

}

0 comments on commit ac99941

Please sign in to comment.