Compile opaque patterns all the way, and add repl test

This commit is contained in:
ayazhafiz 2022-02-24 22:50:32 -05:00
parent 68d28349ed
commit 4e27cdd21d
3 changed files with 44 additions and 6 deletions

View file

@ -711,10 +711,32 @@ fn to_relevant_branch_help<'a>(
_ => None, _ => None,
}, },
OpaqueUnwrap { OpaqueUnwrap { opaque, argument } => match test {
opaque: _, IsCtor {
argument, tag_name: test_opaque_tag_name,
} => to_relevant_branch_help(test, path, start, end, branch, (*argument).0), tag_id,
..
} => {
debug_assert_eq!(test_opaque_tag_name, &TagName::Private(opaque));
let (argument, _) = *argument;
let mut new_path = path.to_vec();
new_path.push(PathInstruction {
index: 0,
tag_id: *tag_id,
});
start.push((new_path, argument));
start.extend(end);
Some(Branch {
goal: branch.goal,
guard: branch.guard.clone(),
patterns: start,
})
}
_ => None,
},
NewtypeDestructure { NewtypeDestructure {
tag_name, tag_name,

View file

@ -10,7 +10,6 @@ use bumpalo::Bump;
use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_builtins::bitcode::{FloatWidth, IntWidth};
use roc_can::expr::{ClosureData, IntValue}; use roc_can::expr::{ClosureData, IntValue};
use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap};
use roc_error_macros::todo_opaques;
use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_module::symbol::{IdentIds, ModuleId, Symbol};
@ -2021,7 +2020,7 @@ fn pattern_to_when<'a>(
(env.unique_symbol(), Loc::at_zero(RuntimeError(error))) (env.unique_symbol(), Loc::at_zero(RuntimeError(error)))
} }
AppliedTag { .. } | RecordDestructure { .. } => { AppliedTag { .. } | RecordDestructure { .. } | UnwrappedOpaque { .. } => {
let symbol = env.unique_symbol(); let symbol = env.unique_symbol();
let wrapped_body = When { let wrapped_body = When {
@ -2040,6 +2039,7 @@ fn pattern_to_when<'a>(
} }
UnwrappedOpaque { .. } => todo_opaques!(), UnwrappedOpaque { .. } => todo_opaques!(),
IntLiteral(..) IntLiteral(..)
| NumLiteral(..) | NumLiteral(..)
| FloatLiteral(..) | FloatLiteral(..)

View file

@ -1048,3 +1048,19 @@ fn opaque_apply_polymorphic() {
r#"Package "" { a: "" } : F Str { a : Str }"#, r#"Package "" { a: "" } : F Str { a : Str }"#,
) )
} }
#[test]
fn opaque_pattern_and_call() {
expect_success(
indoc!(
r#"
F t u := [ Package t u ]
f = \$F (Package A {}) -> $F (Package {} A)
f ($F (Package A {}))
"#
),
r#"Package {} A : F {} [ A ]*"#,
)
}