mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
Merge branch 'main' into remove-old-record-builder
This commit is contained in:
commit
2ea6a5d79c
6 changed files with 65 additions and 13 deletions
|
@ -1187,17 +1187,7 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a
|
|||
Apply(tag, desugared_arg_patterns.into_bump_slice())
|
||||
}
|
||||
RecordDestructure(field_patterns) => {
|
||||
let mut allocated = Vec::with_capacity_in(field_patterns.len(), env.arena);
|
||||
for field_pattern in field_patterns.iter() {
|
||||
let value = desugar_pattern(env, scope, field_pattern.value);
|
||||
allocated.push(Loc {
|
||||
value,
|
||||
region: field_pattern.region,
|
||||
});
|
||||
}
|
||||
let field_patterns = field_patterns.replace_items(allocated.into_bump_slice());
|
||||
|
||||
RecordDestructure(field_patterns)
|
||||
RecordDestructure(desugar_record_destructures(env, scope, field_patterns))
|
||||
}
|
||||
RequiredField(name, field_pattern) => {
|
||||
RequiredField(name, desugar_loc_pattern(env, scope, field_pattern))
|
||||
|
@ -1235,6 +1225,23 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a
|
|||
}
|
||||
}
|
||||
|
||||
pub fn desugar_record_destructures<'a>(
|
||||
env: &mut Env<'a>,
|
||||
scope: &mut Scope,
|
||||
field_patterns: Collection<'a, Loc<Pattern<'a>>>,
|
||||
) -> Collection<'a, Loc<Pattern<'a>>> {
|
||||
let mut allocated = Vec::with_capacity_in(field_patterns.len(), env.arena);
|
||||
for field_pattern in field_patterns.iter() {
|
||||
let value = desugar_pattern(env, scope, field_pattern.value);
|
||||
allocated.push(Loc {
|
||||
value,
|
||||
region: field_pattern.region,
|
||||
});
|
||||
}
|
||||
|
||||
field_patterns.replace_items(allocated.into_bump_slice())
|
||||
}
|
||||
|
||||
/// Desugars a `dbg expr` expression into a statement block that prints and returns the
|
||||
/// value produced by `expr`. Essentially:
|
||||
/// (
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::path::Path;
|
|||
use crate::abilities::{AbilitiesStore, ImplKey, PendingAbilitiesStore, ResolvedImpl};
|
||||
use crate::annotation::{canonicalize_annotation, AnnotationFor};
|
||||
use crate::def::{canonicalize_defs, report_unused_imports, Def};
|
||||
use crate::desugar::desugar_record_destructures;
|
||||
use crate::env::Env;
|
||||
use crate::expr::{
|
||||
ClosureData, DbgLookup, Declarations, ExpectLookup, Expr, Output, PendingDerives,
|
||||
|
@ -326,13 +327,16 @@ pub fn canonicalize_module_defs<'a>(
|
|||
before_arrow: _,
|
||||
after_arrow: _,
|
||||
}| {
|
||||
let desugared_patterns =
|
||||
desugar_record_destructures(&mut env, &mut scope, pattern.value);
|
||||
|
||||
let (destructs, _) = canonicalize_record_destructs(
|
||||
&mut env,
|
||||
var_store,
|
||||
&mut scope,
|
||||
&mut output,
|
||||
PatternType::ModuleParams,
|
||||
&pattern.value,
|
||||
&desugared_patterns,
|
||||
pattern.region,
|
||||
PermitShadows(false),
|
||||
);
|
||||
|
|
|
@ -914,7 +914,10 @@ pub fn canonicalize_record_destructs<'a>(
|
|||
}
|
||||
};
|
||||
}
|
||||
_ => unreachable!("Any other pattern should have given a parse error"),
|
||||
_ => unreachable!(
|
||||
"Any other pattern should have given a parse error: {:?}",
|
||||
loc_pattern.value
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue