E3012

E3012#

Struct pattern and map pattern cannot be mixed. The key in map pattern must be a literal, while the key in struct pattern must be the field name.

Erroneous example#

struct S {
  value : Int
}

pub fn S::get(self : S, index : String) -> Int? {
  if index == "value" {
    return Some(self.value)
  }
  return None
}

test {
  let s : S = { value: 42 }
  match s {
    { "value": value, value, .. } => println("Value is: \{value}") // Error: Struct pattern and map pattern cannot be mixed.
    _ => println("No value")
  }
}

Suggestion#

Remove either the map pattern part or the struct pattern part from the pattern.

///|
pub(all) struct  {
   : 
}

///|
pub fn ::( : ,  : ) -> ? {
  if  == "value" {
    return (.)
  }
  return 
}

///|
fn ( : ) ->  {
  match  {
    { "value": , .. } => ("Value is: \{value}")
    _ => ("No value")
  }
}

///|
test {
  let  :  = { : 42 }
  ()
  ()
}

Or,

///|
fn ( : ) ->  {
  match  {
    {  } => ("Value is: \{value}")
  }
}