V0012 keyword_expression_operand
if, match, with, try, fn, handler and fail expressions cannot be operands of a binary or postfix operator without parentheses (design §3.2).
An error from the parse phase. sakura explain V0012 prints this explanation offline.
if, match, with, try, fn, handler and fail expressions cannot be operands of a
binary or postfix operator without parentheses (design §3.2).
Wrong:
match x { … }.len()Fixed:
(match x { … }).len()Wrong program
compiler/tests/ui/V0012_keyword_expression_operand.sakura, which the compiler's ui suite runs through sakura check:
fn size(o: Option<Int>) -> Int {
match o { Some(n) => n, None => 0 }.abs()
}sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"schema_version": "1.0",
"kind": "diagnostic",
"id": "d:e46435be8e9e83af",
"code": "V0012",
"severity": "error",
"phase": "parse",
"message": "wrap the `match` expression in parentheses to use it as an operand",
"snapshot": "sha256:$SNAPSHOT",
"symbol_id": "main::V0012_keyword_expression_operand::size",
"spans": [
{
"uri": "file://$DIR/V0012_keyword_expression_operand.sakura",
"content_hash": "sha256:377d8532f3ab925ee33afb4febdc4749eafb1664be51c76f6a3398e3492c9ecf",
"start_byte": 104,
"end_byte": 105,
"role": "primary"
}
],
"related_ids": [],
"expected": null,
"actual": null,
"obligation": null,
"counterexample": null,
"explanation_uri": "sakura://explain/V0012",
"fixes": []
}Fixed program
compiler/tests/ui/V0012_keyword_expression_operand.fixed.sakura, which sakura check accepts with no diagnostics:
fn size(o: Option<Int>) -> Int {
(match o {
Some(n) => n,
None => 0,
}).abs()
}