bug
bug copied to clipboard
Compound type constraint not handled correctly
scala> case class Foo(i: Int)
defined class Foo
scala> case class Bar(i: Int) extends AnyVal
defined class Bar
scala> def f[T <: Product with AnyRef](v: T) = v.toString
f: [T <: Product](v: T)String // Note: reported type should be T <: Product with AnyRef
scala> f(Foo(1))
res0: String = Foo(1)
scala> f(Bar(1))
<console>:11: error: inferred type arguments [Bar] do not conform to method f's type parameter bounds [T <: Product] // Note: reported type should be T <: Product with AnyRef
f(Bar(1))
^
<console>:11: error: type mismatch;
found : Bar
required: T
f(Bar(1))
^
This also appears to have semantic issues:
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class ProductRef(i: Int)
defined class ProductRef
scala> case class ProductVal(i: Int) extends AnyVal
defined class ProductVal
scala> val x: Any => String = {case x: Product with AnyRef => "It's an AnyRef"; case x: Product => "It's a product but not an AnyRef"}
x: Any => String = <function1>
scala> x(ProductRef(1))
res0: String = It's an AnyRef
scala> x(ProductVal(1))
res1: String = It's an AnyRef
Imported From: https://issues.scala-lang.org/browse/SI-8613?orig=1 Reporter: Duane Bailey (duane)