mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
single element record pattern
This commit is contained in:
parent
a94f597e1e
commit
2ceb50bd02
1 changed files with 21 additions and 25 deletions
|
@ -5631,25 +5631,30 @@ fn store_pattern_help<'a>(
|
||||||
| StrLiteral(_) => {
|
| StrLiteral(_) => {
|
||||||
return StorePattern::NotProductive(stmt);
|
return StorePattern::NotProductive(stmt);
|
||||||
}
|
}
|
||||||
NewtypeDestructure { arguments, .. } => {
|
NewtypeDestructure { arguments, .. } => match arguments.as_slice() {
|
||||||
let mut fields = Vec::with_capacity_in(arguments.len(), env.arena);
|
[single] => {
|
||||||
fields.extend(arguments.iter().map(|x| x.1));
|
return store_pattern_help(env, procs, layout_cache, &single.0, outer_symbol, stmt);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let mut fields = Vec::with_capacity_in(arguments.len(), env.arena);
|
||||||
|
fields.extend(arguments.iter().map(|x| x.1));
|
||||||
|
|
||||||
let layout = Layout::Struct(fields.into_bump_slice());
|
let layout = Layout::Struct(fields.into_bump_slice());
|
||||||
|
|
||||||
let wrapped = Wrapped::from_layout(&layout);
|
let wrapped = Wrapped::from_layout(&layout);
|
||||||
|
|
||||||
return store_newtype_pattern(
|
return store_newtype_pattern(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
outer_symbol,
|
outer_symbol,
|
||||||
&layout,
|
&layout,
|
||||||
&arguments,
|
&arguments,
|
||||||
wrapped,
|
wrapped,
|
||||||
stmt,
|
stmt,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
AppliedTag {
|
AppliedTag {
|
||||||
arguments,
|
arguments,
|
||||||
layout,
|
layout,
|
||||||
|
@ -5798,23 +5803,14 @@ fn store_newtype_pattern<'a>(
|
||||||
) -> StorePattern<'a> {
|
) -> StorePattern<'a> {
|
||||||
use Pattern::*;
|
use Pattern::*;
|
||||||
|
|
||||||
let write_tag = false;
|
|
||||||
|
|
||||||
let mut arg_layouts = Vec::with_capacity_in(arguments.len(), env.arena);
|
let mut arg_layouts = Vec::with_capacity_in(arguments.len(), env.arena);
|
||||||
let mut is_productive = false;
|
let mut is_productive = false;
|
||||||
|
|
||||||
if write_tag {
|
|
||||||
// add an element for the tag discriminant
|
|
||||||
arg_layouts.push(Layout::Builtin(TAG_SIZE));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (_, layout) in arguments {
|
for (_, layout) in arguments {
|
||||||
arg_layouts.push(*layout);
|
arg_layouts.push(*layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index, (argument, arg_layout)) in arguments.iter().enumerate().rev() {
|
for (index, (argument, arg_layout)) in arguments.iter().enumerate().rev() {
|
||||||
let index = if write_tag { index + 1 } else { index };
|
|
||||||
|
|
||||||
let mut arg_layout = *arg_layout;
|
let mut arg_layout = *arg_layout;
|
||||||
|
|
||||||
if let Layout::RecursivePointer = arg_layout {
|
if let Layout::RecursivePointer = arg_layout {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue