Why does 2.10 insist on defining the boundaries of the type parameter (works fine in 2.9)?

I have the following case class:

case class Alert[T <: Transport](destination: Destination[T], message: Message[T]) 

In Scala 2.9.2, the following method signature is compiled:

 def send(notification: Alert[_]) { notification match { ... } } 

Now in Scala 2.10.1, it cannot compile with the following error:

 type arguments [_$1] do not conform to class Alert type parameter bounds [T <: code.notifications.Transport] 

Why is this? How can I fix the error? Simply assigning the same send types results in much larger compilation errors ...

Update: Looking at SIP-18 , I don’t think the reason is that I do not have existential types, as SIP-18 says that this is only necessary for types without wildcards, which is what I have here .

+4
source share
1 answer

The error seems to indicate that the existential type " _ " is not limited to the Transport subtype. This may be the preferred solution.

 trait Transport trait Destination[T] trait Message[T] case class Alert[T <: Transport](destination: Destination[T], message: Message[T]) def send[T <: Transport](notification: Alert[T]) { notification match { case _ => () } } 

It also works

 def send(notification: Alert[_ <: Transport]) 

but I think it’s preferable not to use existential types.

+2
source

All Articles