object Test {
val one = 1
final val final_one = 1
object OK {
def foo[T <: Int](t : T) : T = t
val a : 1 = foo(1)
val b : Int = foo(one)
val c : 1 = foo(final_one)
}
object Fail {
case class Foo[T <: Int](t : T)
val a : 1 = Foo(1).t //Error: Type mismatch
val b : Int = Foo(one).t
val c : 1 = Foo(final_one).t //Error: Type mismatch
}
object OK2 {
case class Foo[T <: Int with Singleton](t : T)
val a : 1 = Foo(1).t
val b : Int = Foo(one).t
val c : 1 = Foo(final_one).t
}
}
See code comments for the issues: