Aladdin - Scala Bugtracking
[#516] project: compiler priority: low category: bug
submitter assigned to status date submitted
Sean Martin won't fix 2006-01-17 19:07:01.0
subject Type inference fails on compound types
code
import scala.collection.mutable._;

object subscriber extends Subscriber[Message[String] with Undoable, Members] {
 def notify(pub: Members, event: Message[String] with Undoable): Unit = 
  event match {
   case Include(elem) => System.err.println("ADD: " + elem);
   case  Remove(elem) => System.err.println("REM: " + elem);
   //case i : Include[HasTree] with Undoable  =>
   //case r : Remove [HasTree] with Undoable  =>
  }
 }
  
what happened
Above code won't compile because type inferencing fails on message case classes. The commented cases must be use\
d instead to get the code to compile and work correctly. Additional output from the compiler (have no idea where\
 this is coming from):

infer constr (I)scala.collection.mutable.Include[I]:scala.collection.mutable.Include[I], pt = scala.collection.m\
utable.Message[Models.this.HasTree] with scala.collection.mutable.Undoable
free type params = List()
not a subtype scala.collection.mutable.Include[?I] of scala.collection.mutable.Message[Models.this.HasTree] with\
 scala.collection.mutable.Undoable
ici (I)scala.collection.mutable.Include[I] List(type I) scala.collection.mutable.Message[Models.this.HasTree] wi\
th scala.collection.mutable.Undoable
infer constr (A)scala.collection.mutable.Remove[A]:scala.collection.mutable.Remove[A], pt = scala.collection.mut\
able.Message[Models.this.HasTree] with scala.collection.mutable.Undoable
free type params = List()
not a subtype scala.collection.mutable.Remove[?A] of scala.collection.mutable.Message[Models.this.HasTree] with \
scala.collection.mutable.Undoable
ici (A)scala.collection.mutable.Remove[A] List(type A) scala.collection.mutable.Message[Models.this.HasTree] wit\
h scala.collection.mutable.Undoable
infer constr (I)scala.collection.mutable.Include[I]:scala.collection.mutable.Include[I], pt = scala.collection.m\
utable.Message[Models.this.HasTree] with scala.collection.mutable.Undoable
what expected Expected type inference to determine that elem is a string in the pattern of both cases. Not sure if Scala's type system is this expressive though....
[back to overview]
Changes of this bug report
Sean  edited on  2006-01-17 19:08:05.0
Sean  edited on  2006-01-17 19:08:26.0
Martin  edited on  2006-01-20 18:59:32.0
This is how type inference is defined: The selector type must be supertype of the type of each pattern. In this case it isn't, becaus the selector type is Message with Undoable and the patterns conform only to Message. You can get it to compile by widening the type of the selector:
(event: Message[String]) match {
   case Include(elem) => System.err.println("ADD: " + elem);
   case  Remove(elem) => System.err.println("REM: " + elem);
   //case i : Include[HasTree] with Undoable  =>
   //case r : Remove [HasTree] with Undoable  =>
  }
 }

Martin  edited on  2006-01-20 18:59:53.0