From da2f47f005e4b023ac50f2a8b9ce139dd981f049 Mon Sep 17 00:00:00 2001 From: Tim Zakian <2895723+tzakian@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:02:05 -0700 Subject: [PATCH] Minor enum fixes (#86) --- reference/src/SUMMARY.md | 2 +- reference/src/control-flow/pattern-matching.md | 2 +- reference/src/enums.md | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/reference/src/SUMMARY.md b/reference/src/SUMMARY.md index f825fef..5c1b5f5 100644 --- a/reference/src/SUMMARY.md +++ b/reference/src/SUMMARY.md @@ -22,7 +22,7 @@ - [Conditional Expressions](control-flow/conditionals.md) - [Loops](control-flow/loops.md) - [Labeled Control FLow](control-flow/labeled-control-flow.md) - - [Patterm Matching](control-flow/pattern-matching.md) + - [Pattern Matching](control-flow/pattern-matching.md) - [Functions](functions.md) - [Structs](structs.md) - [Enums](enums.md) diff --git a/reference/src/control-flow/pattern-matching.md b/reference/src/control-flow/pattern-matching.md index 533969d..086ebba 100644 --- a/reference/src/control-flow/pattern-matching.md +++ b/reference/src/control-flow/pattern-matching.md @@ -217,7 +217,7 @@ match (1) { Similarly, the following would also result in a type error because `MyEnum` and `MyStruct` are different types: -``` +```move match (MyStruct { x: 0, y: 0 }) { MyEnum::Variant(..) => 1, // TYPE ERROR: expected type MyEnum, found MyStruct diff --git a/reference/src/enums.md b/reference/src/enums.md index 31ace10..94b0298 100644 --- a/reference/src/enums.md +++ b/reference/src/enums.md @@ -194,7 +194,7 @@ You can pattern match on Move values by value, immutable reference, and mutable pattern matching by value, the value is moved into the match arm. When pattern matching by reference, the value is borrowed into the match arm (either immutably or mutably). We'll go through a brief description of pattern matching using `match` here, but for more information on pattern -matching using `match` in Move see the [Pattern Matching](./control-flow/pattern_matching.md) +matching using `match` in Move see the [Pattern Matching](./control-flow/pattern-matching.md) section. A `match` statement is used to pattern match on a Move value and consists of a number of _match @@ -259,14 +259,14 @@ module a::m { } public fun incr_enum_variant1(simple_enum: &mut SimpleEnum) { - match simple_enum { + match (simple_enum) { SimpleEnum::Variant1(mut value) => *value += 1, _ => (), } } public fun incr_enum_variant2(simple_enum: &mut SimpleEnum) { - match simple_enum { + match (simple_enum) { SimpleEnum::Variant2(mut value) => *value += 1, _ => (), } @@ -299,8 +299,8 @@ module a::m { public enum X { Variant { x: u64 } } public fun bad(x: X) { - match x { - _ => () + match (x) { + _ => (), // ^ ERROR! value of type `X` is not consumed or destructured in this match arm } } @@ -315,9 +315,9 @@ module a::m { public enum X { Variant { x: u64 } } public fun good(x: X) { - match x { + match (x) { // OK! Compiles since the value is destructured - X::Variant { x: _ } => () + X::Variant { x: _ } => (), } } }