# E4165

Compiler diagnostic name: `missing_op_as_view`.

Missing `op_as_view` method for array pattern matching.

Open array patterns such as `[head, ..tail]` need a value that can provide a
view for the `..` part of the pattern. `op_as_view` is the compiler's internal
name for the `_[_:_]` view operator; in source code this operation is provided
by annotating a compatible method with `#alias("_[_:_]")`.

## Erroneous example

The following example tries to use an open array pattern on an `Int`, which does
not provide `op_as_view`:

```{literalinclude} /sources/error_codes/4165_error/top.mbt
:language: moonbit
```

MoonBit will report an error.

## Suggestion

Use an array-like value that provides the view operation. When defining that
operation, annotate the method with `#alias("_[_:_]")`, for example:

```moonbit
#alias("_[_:_]")
fn Type::view(self : Type, start? : Int = 0, end? : Int) -> View {
  ...
}
```

The fixed example uses `Array[Int]`, which already provides this operation:

```{literalinclude} /sources/error_codes/4165_fixed/top.mbt
:language: moonbit
```
