Skip to content

Commit

Permalink
Merge pull request #9083 from lrytz/smallCleanups
Browse files Browse the repository at this point in the history
[nomerge] small cleanups
  • Loading branch information
lrytz committed Jun 25, 2020
2 parents d332b43 + 5ba248e commit cbe6ade
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ abstract class RefChecks extends Transform {
|it should have been processed and eliminated during expansion of an enclosing macro."""
// The getOrElse part should never happen, it's just here as a backstop.
val msg = sym.compileTimeOnlyMessage getOrElse defaultMsg
reporter.error(pos, sym.compileTimeOnlyMessage getOrElse defaultMsg)
reporter.error(pos, msg)
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/library/scala/collection/immutable/HashMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
this.merge0(thatHash, 0, concatMerger[A, B])
case that =>
var result: HashMap[A, B] = this
that.asInstanceOf[GenTraversableOnce[(A, B)]] foreach { case kv: (_, _) => result = result + kv }
that.asInstanceOf[GenTraversableOnce[(A, B)]].foreach(result += _)
result
}
castToThat(result)
Expand All @@ -212,9 +212,9 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
val merger = HashMap.concatMerger[A, B].invert
val result: HashMap[A, B] = that match {
case thatHash: HashMap[A, B] =>
this.merge0(thatHash, 0, HashMap.concatMerger[A, B].invert)
this.merge0(thatHash, 0, merger)

case that:HasForeachEntry[A, B] =>
case that: HasForeachEntry[A, B] =>
object adder extends Function2[A, B, Unit] {
var result: HashMap[A, B] = HashMap.this
override def apply(key: A, value: B): Unit = {
Expand All @@ -231,12 +231,15 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
result = result.updated0(key, computeHash(key), 0, kv._2, kv, merger)
}
}
that.asInstanceOf[scala.Traversable[(A,B)]] foreach adder
that.asInstanceOf[GenTraversableOnce[(A,B)]] foreach adder
adder.result
}
castToThat(result)
}
}

// These methods exist to encapsulate the `.asInstanceOf[That]` in a slightly safer way -- only suitable values can
// be cast and the type of the `CanBuildFrom` guides type inference.
private[this] def castToThat[C, That](m: HashMap[A, B])(implicit bf: CanBuildFrom[HashMap[A, B], C, That]): That = {
m.asInstanceOf[That]
}
Expand Down

0 comments on commit cbe6ade

Please sign in to comment.