Skip to content

Commit b690ef8

Browse files
author
Steven Scott
committed
Declare FiniteDuration.toCoarsest to return a FiniteDuration
FiniteDuration.toCoarsest is declared with a return type of Duration even though it can only ever return a FiniteDuration. Change the declaration to return a FiniteDuration so that using this method doesn't require a cast or pattern match on the result in cases where a FiniteDuration is required.
1 parent 178e8df commit b690ef8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/library/scala/concurrent/duration/Duration.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ final class FiniteDuration(val length: Long, val unit: TimeUnit) extends Duratio
705705

706706
final def isFinite() = true
707707

708-
final def toCoarsest: Duration = {
708+
final override def toCoarsest: FiniteDuration = {
709709
def loop(length: Long, unit: TimeUnit): FiniteDuration = {
710710
def coarserOrThis(coarser: TimeUnit, divider: Int) =
711711
if (length % divider == 0) loop(length / divider, coarser)

test/files/run/duration-coarsest.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ object Test extends App {
2525
23 hours,
2626
40 days
2727
) foreach (x => assert(x == x.toCoarsest, x))
28-
}
28+
29+
// toCoarsest on a FiniteDuration should return a FiniteDuration
30+
val finite: FiniteDuration = 1.second.toCoarsest
31+
}

0 commit comments

Comments
 (0)