Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: fix return with option on orexpr (#20728)
- Loading branch information
Showing
2 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fn find_startswith_string(a []string, search string) ?string { | ||
for s in a { | ||
if s.starts_with(search) { | ||
return s | ||
} | ||
} | ||
return none | ||
} | ||
|
||
fn find_any_startswith_string(a []string, b []string, search string) ?string { | ||
// cannot convert 'struct _option_string' to 'struct string' | ||
// V wants the or {} block to return a string, but find_startswith_string returns ?string | ||
return find_startswith_string(a, search) or { find_startswith_string(b, search) } | ||
} | ||
|
||
fn test_main() { | ||
deadbeef := find_any_startswith_string(['foobar', 'barfoo'], ['deadbeef', 'beefdead'], | ||
'dead') | ||
assert deadbeef or { panic('unreachable') } == 'deadbeef' | ||
} |