mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
fix incorrect layout for Switch
This commit is contained in:
parent
d0da300042
commit
0f22cbbf7d
3 changed files with 11 additions and 10 deletions
|
@ -1329,15 +1329,14 @@ mod test_gen {
|
|||
);
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn pair_with_guard_pattern() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
when Pair 2 3 is
|
||||
Pair 4 _ -> 9
|
||||
Pair 3 _ -> 9
|
||||
Pair 4 _ -> 1
|
||||
Pair 3 _ -> 2
|
||||
Pair a b -> a + b
|
||||
"#
|
||||
),
|
||||
|
@ -1345,7 +1344,6 @@ mod test_gen {
|
|||
i64
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn result_with_guard_pattern() {
|
||||
|
|
|
@ -969,9 +969,9 @@ fn decide_to_branching<'a>(
|
|||
tests,
|
||||
fallback,
|
||||
} => {
|
||||
let cond = env
|
||||
.arena
|
||||
.alloc(path_to_expr(env, cond_symbol, &path, &cond_layout));
|
||||
// the cond_layout can change in the process. E.g. if the cond is a Tag, we actually
|
||||
// switch on the tag discriminant (currently an i64 value)
|
||||
let (cond, cond_layout) = path_to_expr_help(env, cond_symbol, &path, cond_layout);
|
||||
|
||||
let default_branch = env.arena.alloc(decide_to_branching(
|
||||
env,
|
||||
|
@ -1008,7 +1008,7 @@ fn decide_to_branching<'a>(
|
|||
|
||||
// make a jump table based on the tests
|
||||
Expr::Switch {
|
||||
cond,
|
||||
cond: env.arena.alloc(cond),
|
||||
cond_layout,
|
||||
branches: branches.into_bump_slice(),
|
||||
default_branch,
|
||||
|
|
|
@ -890,6 +890,7 @@ fn store_pattern<'a>(
|
|||
Underscore => {
|
||||
// ignore
|
||||
}
|
||||
IntLiteral(_) | FloatLiteral(_) | EnumLiteral { .. } | BitLiteral(_) => {}
|
||||
_ => {
|
||||
// store the field in a symbol, and continue matching on it
|
||||
let symbol = env.fresh_symbol();
|
||||
|
@ -927,6 +928,7 @@ fn store_record_destruct<'a>(
|
|||
struct_layout: Layout<'a>,
|
||||
stored: &mut Vec<'a, (Symbol, Layout<'a>, Expr<'a>)>,
|
||||
) -> Result<(), String> {
|
||||
use Pattern::*;
|
||||
let record = env.arena.alloc(Expr::Load(outer_symbol));
|
||||
let load = Expr::Access {
|
||||
label: destruct.label.clone(),
|
||||
|
@ -939,10 +941,10 @@ fn store_record_destruct<'a>(
|
|||
stored.push((destruct.symbol, destruct.layout.clone(), load));
|
||||
}
|
||||
Some(guard_pattern) => match &guard_pattern {
|
||||
Pattern::Identifier(symbol) => {
|
||||
Identifier(symbol) => {
|
||||
stored.push((*symbol, destruct.layout.clone(), load));
|
||||
}
|
||||
Pattern::Underscore => {
|
||||
Underscore => {
|
||||
// important that this is special-cased to do nothing: mono record patterns will extract all the
|
||||
// fields, but those not bound in the source code are guarded with the underscore
|
||||
// pattern. So given some record `{ x : a, y : b }`, a match
|
||||
|
@ -955,6 +957,7 @@ fn store_record_destruct<'a>(
|
|||
//
|
||||
// internally. But `y` is never used, so we must make sure it't not stored/loaded.
|
||||
}
|
||||
IntLiteral(_) | FloatLiteral(_) | EnumLiteral { .. } | BitLiteral(_) => {}
|
||||
_ => {
|
||||
let symbol = env.fresh_symbol();
|
||||
stored.push((symbol, destruct.layout.clone(), load));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue