E4118

E4118#

Cannot match type with map pattern.

You can use map patterns on custom types, as long as they have a method get that returns an optional value for a given key.

Erroneous example#

///|
priv struct MyMap {}

///|
test {
  let map : MyMap = {}
  match map {
    { "a": a, .. } => println("a: \{a}")
    //^~~~~~~~~~~~~~
    // Error: Please implement method `get` for type MyMap to match it with map pattern.
  }
}

Suggestion#

Implement the get method as suggested in the error message.

///|
priv struct  {
   : [, ]
}

///|
fn ::( : ,  : ) -> ? {
  ..()
}

///|
test {
  let  :  = { : { "a": 1, "b": 2, "c": 3 } }
  match  {
    { "a": , .. } => ("a: \{a}")
    _ => ("missing")
  }
}