You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deriving this from type param upper bound
in addition (as before) to constraints that we encounter
scala> def stable[T <: 1](x: T): T = x
stable: [T <: 1](x: T)T
scala> stable(1)
res0: 1 = 1
scala> stable(2)
<console>:9: error: inferred type arguments [2] do not conform to method stable's type parameter bounds [T <: 1]
stable(2)
^
<console>:9: error: type mismatch;
found : Int(2)
required: T
stable(2)
^
scala> def stable[T <: Singleton](x: T): T = x
stable: [T <: Singleton](x: T)T
scala> val x: Int = 2
x: Int = 2
scala> val y: x.type = x
y: x.type = 2
scala> stable(y)
res3: x.type = 2
0 commit comments