remove UnsupportedPattern variant in mono patterns

This commit is contained in:
Folkert 2020-12-29 00:48:56 +01:00
parent fefb1f3739
commit f8e04619b8
5 changed files with 31 additions and 25 deletions

View file

@ -1786,4 +1786,21 @@ mod gen_primitives {
i64
);
}
#[test]
#[ignore]
#[should_panic(expected = "")]
fn unsupported_pattern_str_interp() {
assert_evals_to!(
indoc!(
r#"
{ x: 4 } = { x : 4 }
x
"#
),
0,
i64
);
}
}

View file

@ -64,11 +64,14 @@ pub fn helper<'a>(
debug_assert_eq!(exposed_to_host.len(), 1);
let main_fn_symbol = exposed_to_host.keys().copied().nth(0).unwrap();
let (_, main_fn_layout) = procedures
.keys()
.find(|(s, _)| *s == main_fn_symbol)
.unwrap()
.clone();
let (_, main_fn_layout) = match procedures.keys().find(|(s, _)| *s == main_fn_symbol) {
Some(found) => found.clone(),
None => panic!(
"The main function symbol {:?} does not have a procedure in {:?}",
main_fn_symbol,
&procedures.keys()
),
};
let target = target_lexicon::Triple::host();
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;

View file

@ -379,7 +379,7 @@ fn test_at_path<'a>(selected_path: &Path, branch: &Branch<'a>, all_tests: &mut V
match pattern {
// TODO use guard!
Identifier(_) | Underscore | UnsupportedPattern(_) => {
Identifier(_) | Underscore => {
if let Guard::Guard { symbol, id, stmt } = guard {
all_tests.push(Guarded {
opt_test: None,
@ -531,7 +531,7 @@ fn to_relevant_branch_help<'a>(
use Test::*;
match pattern {
Identifier(_) | Underscore | UnsupportedPattern(_) => Some(branch.clone()),
Identifier(_) | Underscore => Some(branch.clone()),
RecordDestructure(destructs, _) => match test {
IsCtor {
@ -742,7 +742,7 @@ fn needs_tests<'a>(pattern: &Pattern<'a>) -> bool {
use Pattern::*;
match pattern {
Identifier(_) | Underscore | UnsupportedPattern(_) => false,
Identifier(_) | Underscore => false,
RecordDestructure(_, _)
| AppliedTag { .. }

View file

@ -84,12 +84,6 @@ fn simplify<'a>(pattern: &crate::ir::Pattern<'a>) -> Pattern {
Ctor(union, tag_id, patterns)
}
UnsupportedPattern(_region) => {
// Treat as an Anything
// code-gen will make a runtime error out of the branch
Anything
}
AppliedTag {
tag_id,
arguments,

View file

@ -4699,10 +4699,6 @@ fn store_pattern<'a>(
RecordDestructure(_, _) => {
unreachable!("a record destructure must always occur on a struct layout");
}
UnsupportedPattern(_region) => {
return Err(&"unsupported pattern");
}
}
Ok(stmt)
@ -5466,11 +5462,6 @@ pub enum Pattern<'a> {
layout: Layout<'a>,
union: crate::exhaustive::Union,
},
// Runtime Exceptions
// Shadowed(Region, Located<Ident>),
// Example: (5 = 1 + 2) is an unsupported pattern in an assignment; Int patterns aren't allowed in assignments!
UnsupportedPattern(Region),
}
#[derive(Clone, Debug, PartialEq)]
@ -5512,10 +5503,11 @@ pub fn from_can_pattern<'a>(
original_region: *region,
shadow: ident.clone(),
}),
UnsupportedPattern(region) => Ok(Pattern::UnsupportedPattern(*region)),
UnsupportedPattern(region) => Err(RuntimeError::UnsupportedPattern(*region)),
MalformedPattern(_problem, region) => {
// TODO preserve malformed problem information here?
Ok(Pattern::UnsupportedPattern(*region))
Err(RuntimeError::UnsupportedPattern(*region))
}
NumLiteral(var, num) => match num_argument_to_int_or_float(env.subs, *var) {
IntOrFloat::IntType => Ok(Pattern::IntLiteral(*num)),