Skip to content

Commit fdcb8c0

Browse files
committed
Merge #230: fix(lsp): update documentation for unwraps
ac7f280 fix(lsp): update documentation for unwraps (Volodymyr Herashchenko) Pull request description: There was an error in the function signatures for `unwrap_left` and `unwrap_right` in the LSP documentation where the expected `Either` generic types were swapped. Also make it clearer exactly which type is used when we are unwrapping these values. ACKs for top commit: KyrylR: ACK ac7f280; ran tests locally Tree-SHA512: ed01116363fd8b72e0c436815e4be0c353b16b355afccdd456606908e8de3601845414cf221cf89744b9eaa1050200170d64caf2169340b839bc9ff3bd92ba03
2 parents 2020309 + ac7f280 commit fdcb8c0

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

lsp/src/completion/builtin.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn match_callname(call: &CallName) -> Option<FunctionTemplate> {
4343
Some(FunctionTemplate::new(
4444
"unwrap_left",
4545
vec![format!("{ty}")],
46-
vec![format!("Either<{ty}, U>")],
46+
vec![format!("Either<T, {ty}>")],
4747
ty,
4848
doc,
4949
))
@@ -53,7 +53,7 @@ pub fn match_callname(call: &CallName) -> Option<FunctionTemplate> {
5353
Some(FunctionTemplate::new(
5454
"unwrap_right",
5555
vec![format!("{ty}")],
56-
vec![format!("Either<T, {ty}>")],
56+
vec![format!("Either<{ty}, U>")],
5757
ty,
5858
doc,
5959
))
@@ -136,15 +136,17 @@ fn builtin_documentation(call: &CallName) -> String {
136136
"Extracts the left variant of an `Either` value.\n
137137
Returns the left-side value if it exists, otherwise panics.\n
138138
```simplicityhl
139-
let x: Either<u8, u8> = Left(42);
140-
let y: u8 = unwrap_left::<u8>(x); // 42
139+
let x: Either<u8, u32> = Left(42);
140+
// We must specify the type of the right variant so the compiler knows the full type.
141+
let y: u8 = unwrap_left::<u32>(x); // 42
141142
```",
142143
CallName::UnwrapRight(_) =>
143144
"Extracts the right variant of an `Either` value.\n
144145
Returns the right-side value if it exists, otherwise panics.\n
145146
```simplicityhl
146-
let x: Either<u8, u8> = Right(128);
147-
let y: u8 = unwrap_right::<u8>(x); // 128
147+
let x: Either<u8, u32> = Right(128);
148+
// We must specify the type of the left variant so the compiler knows the full type.
149+
let y: u32 = unwrap_right::<u8>(x); // 128
148150
```",
149151
CallName::Unwrap =>
150152
"Unwraps an `Option` value, panicking if it is `None`.\n

0 commit comments

Comments
 (0)