E4144

E4144#

This is a constant, not a constructor, it cannot be applied to arguments.

This error occurs when you try to use a constant as a constructor in pattern. One possible reason for this error is that you have a constant with the same name as an constructor from some other packages, and in such case you need to either use qualified name or type annotations to disambiguate.

Erroneous example#

pub const Value : Int = 1

pub fn classify(value : Int) -> String {
  match value {
    Value(_) => "Value"
  //^~~~~
  // Error: 'Value' is a constant, not a constructor, it cannot be applied to arguments.
    _ => "Other"
  }
}

Suggestion#

If you want to match against the constant, you can remove the payload from the pattern.

pub const Value : Int = 1

pub fn classify(value : Int) -> String {
  match value {
    Value => "Value"
    _ => "Other"
  }
}

Or if the constant has the same name as a constructor from some other packages, you can use qualified name or type annotations to disambiguate.

pub fn classify_qualified(item : @a.Item) -> String {
  match item {
    @a.Value(_) => "Value"
  }
}