-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typechecker: Add is variant bindings to return/match pattern expressions
Currently `expand_context_for_bindings` is only used with if/ guard conditions. It is also useful to have though in expressions where there is no block but the binding can be used as part of the expression. There are probably other places where it would make sense in future.
- Loading branch information
1 parent
9743d97
commit abab871
Showing
3 changed files
with
56 additions
and
16 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,18 @@ | ||
/// Expect: | ||
/// - output: "1\n" | ||
|
||
enum Foo { | ||
Bar(i64) | ||
Baz(m: String) | ||
} | ||
|
||
function main() { | ||
let foo = Foo::Baz(m: "Hello") | ||
|
||
let result = match true { | ||
(foo is Baz(m: n) and n == "Hello") => 1 | ||
else => 2 | ||
} | ||
|
||
println("{}", result) | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/typechecker/is_variant_binding_return_statement.jakt
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,15 @@ | ||
/// Expect: | ||
/// - output: "true\n" | ||
|
||
enum Foo { | ||
Bar(i64) | ||
Baz(m: String) | ||
} | ||
|
||
function match_foo(foo: Foo) => foo is Baz(m: n) and n == "Hello" | ||
|
||
function main() { | ||
let foo = Foo::Baz(m: "Hello") | ||
|
||
println("{}", match_foo(foo)) | ||
} |