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
When a non-Any upper bound is given to a type parameter, 2.13 instantiates the parameter to the upper bound even when a more precise type is known in some situations (unlike 2.12 and Dotty). Compare:
Welcome to Scala2.12.4 (OpenJDK64-BitServerVM, Java1.8.0_162).
Type in expressions for evaluation. Ortry:help.
scala>defid0[T](x: T):T= x
id0: [T](x: T)T
scala> id0(if (1==1) 1else2)
res0:Int=1
scala>defid[T<:AnyVal](x: T):T= x
id: [T<:AnyVal](x: T)T
scala> id(if (1==1) 1else2)
res1:Int=1
And:
Welcome to Scala2.13.0-M3 (OpenJDK64-BitServerVM, Java1.8.0_162).
Type in expressions for evaluation. Ortry:help.
scala>defid0[T](x: T):T= x
id0: [T](x: T)T
scala> id0(if (1==1) 1else2)
res0:Int=1
scala>defid[T<:AnyVal](x: T):T= x
id: [T<:AnyVal](x: T)T
scala> id(if (1==1) 1else2)
res1:AnyVal=1
The text was updated successfully, but these errors were encountered:
Specifically, it's because of bounds propagation in TypeVar's deriveConstraint. I thought I had a PR that disabled that already... EDIT: scala/scala#6789
Note that this is sensitive to the expected type because typedIf assigns the expected type when it's fully defined. This is not in the spec -- instead, it's said to be the weak lub, as you'd imagine. (Same for match -- using the expected type is also not spec'ed)
Uh oh!
There was an error while loading. Please reload this page.
When a non-Any upper bound is given to a type parameter, 2.13 instantiates the parameter to the upper bound even when a more precise type is known in some situations (unlike 2.12 and Dotty). Compare:
And:
The text was updated successfully, but these errors were encountered: