E4083

E4083#

The default value in a with pattern cannot refer to a binder introduced by the complete pattern. The default expression is evaluated in the surrounding scope, where that binder is not available.

Erroneous example#

///|
pub fn value_or(value : Int?, result : Int) -> Int {
  match value {
    Some(result) | (None with result = result) => result
  }
}

Suggestion#

Use a value that is available in the surrounding scope.

///|
pub fn value_or(value : Int?, fallback : Int) -> Int {
  match value {
    Some(result) | (None with result = fallback) => result
  }
}