scala - Pattern Match Abstract Type Trait Member -


sealed trait foo {    type t <: option[any]    val x : t }  case class bar(x : option[int]) extends foo {     type t = option[int] }  val baz : foo = bar(some(42))  baz.x match {    case some(a) =>    case none => 1337 } 

this error message when attempting pattern match:

:12: error: pattern type incompatible expected type; found   : none.type required: baz.t 

i believe due type-erasure on type t.

i'm not sure why fails, limitation in type inference. following works:

(baz.x: option[any]) match {    case some(a) =>    case none => 1337 } 

in case, asking subtype of option not make sense. better define option's element type:

sealed trait foo {   type   def x: option[a] }  case class bar(x : option[int]) extends foo {    type = int }  val baz : foo = bar(some(42))  baz.x match {   case some(a) =>   case none    => 1337 } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -