compiler message not clear with FiniteDuration.times

91 views
Skip to first unread message

Michel Daviot

unread,
May 15, 2013, 6:15:00 AM5/15/13
to scala-l...@googlegroups.com
sbt console
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07).

val fd=scala.concurrent.duration.FiniteDuration(3, "seconds")

fd * 2.5 // works fine
res0: scala.concurrent.duration.Duration = 7500 milliseconds

scala> val res:scala.concurrent.duration.FiniteDuration =fd * 2.5
<console>:14: error: type mismatch;
 found   : Double(2.5)
 required: Long
       val res:scala.concurrent.duration.FiniteDuration =fd * 2.5


I would expect instead of this message to have 
found : Duration
expected : FiniteDuration

Jason Zaugg

unread,
May 15, 2013, 6:49:24 AM5/15/13
to scala-l...@googlegroups.com
This is a consequence of the way that the compiler picks between overloaded alternatives.

Seen in isolation:

scala> trait A { def foo(a: Int): Any; def foo(a: Boolean): String}
defined trait A

scala> def foo(a: A) = a.foo(0): String
<console>:35: error: type mismatch;
 found   : Int(0)
 required: Boolean
       def foo(a: A) = a.foo(0): 

-jason
Reply all
Reply to author
Forward
0 new messages