can for normal (no-list) as

This commit is contained in:
Folkert 2022-12-31 15:46:11 +01:00
parent 06cfdd71cc
commit 905341d849
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
9 changed files with 98 additions and 19 deletions

View file

@ -22,6 +22,7 @@ use roc_types::types::{LambdaSet, OptAbleVar, PatternCategory, Type};
#[derive(Clone, Debug)]
pub enum Pattern {
Identifier(Symbol),
As(Box<Loc<Pattern>>, Symbol),
AppliedTag {
whole_var: Variable,
ext_var: Variable,
@ -94,6 +95,7 @@ impl Pattern {
use Pattern::*;
match self {
Identifier(_) => None,
As(pattern, _) => pattern.value.opt_var(),
AppliedTag { whole_var, .. } => Some(*whole_var),
UnwrappedOpaque { whole_var, .. } => Some(*whole_var),
@ -129,6 +131,7 @@ impl Pattern {
| MalformedPattern(..)
| AbilityMemberSpecialization { .. } => true,
RecordDestructure { destructs, .. } => destructs.is_empty(),
As(pattern, _identifier) => pattern.value.surely_exhaustive(),
List { patterns, .. } => patterns.surely_exhaustive(),
AppliedTag { .. }
| NumLiteral(..)
@ -151,6 +154,7 @@ impl Pattern {
match self {
Identifier(_) => C::PatternDefault,
As(pattern, _) => pattern.value.category(),
AppliedTag { tag_name, .. } => C::Ctor(tag_name.clone()),
UnwrappedOpaque { opaque, .. } => C::Opaque(*opaque),
@ -832,6 +836,10 @@ impl<'a> BindingsFromPattern<'a> {
} => {
return Some((*symbol, loc_pattern.region));
}
As(pattern, symbol) => {
stack.push(Pattern(pattern));
return Some((*symbol, loc_pattern.region));
}
AppliedTag {
arguments: loc_args,
..