mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
remove UnsupportedPattern variant in mono patterns
This commit is contained in:
parent
fefb1f3739
commit
f8e04619b8
5 changed files with 31 additions and 25 deletions
|
@ -1786,4 +1786,21 @@ mod gen_primitives {
|
||||||
i64
|
i64
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
#[should_panic(expected = "")]
|
||||||
|
fn unsupported_pattern_str_interp() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
{ x: 4 } = { x : 4 }
|
||||||
|
|
||||||
|
x
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
i64
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,11 +64,14 @@ pub fn helper<'a>(
|
||||||
debug_assert_eq!(exposed_to_host.len(), 1);
|
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||||
let main_fn_symbol = exposed_to_host.keys().copied().nth(0).unwrap();
|
let main_fn_symbol = exposed_to_host.keys().copied().nth(0).unwrap();
|
||||||
|
|
||||||
let (_, main_fn_layout) = procedures
|
let (_, main_fn_layout) = match procedures.keys().find(|(s, _)| *s == main_fn_symbol) {
|
||||||
.keys()
|
Some(found) => found.clone(),
|
||||||
.find(|(s, _)| *s == main_fn_symbol)
|
None => panic!(
|
||||||
.unwrap()
|
"The main function symbol {:?} does not have a procedure in {:?}",
|
||||||
.clone();
|
main_fn_symbol,
|
||||||
|
&procedures.keys()
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
let target = target_lexicon::Triple::host();
|
let target = target_lexicon::Triple::host();
|
||||||
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;
|
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;
|
||||||
|
|
|
@ -379,7 +379,7 @@ fn test_at_path<'a>(selected_path: &Path, branch: &Branch<'a>, all_tests: &mut V
|
||||||
|
|
||||||
match pattern {
|
match pattern {
|
||||||
// TODO use guard!
|
// TODO use guard!
|
||||||
Identifier(_) | Underscore | UnsupportedPattern(_) => {
|
Identifier(_) | Underscore => {
|
||||||
if let Guard::Guard { symbol, id, stmt } = guard {
|
if let Guard::Guard { symbol, id, stmt } = guard {
|
||||||
all_tests.push(Guarded {
|
all_tests.push(Guarded {
|
||||||
opt_test: None,
|
opt_test: None,
|
||||||
|
@ -531,7 +531,7 @@ fn to_relevant_branch_help<'a>(
|
||||||
use Test::*;
|
use Test::*;
|
||||||
|
|
||||||
match pattern {
|
match pattern {
|
||||||
Identifier(_) | Underscore | UnsupportedPattern(_) => Some(branch.clone()),
|
Identifier(_) | Underscore => Some(branch.clone()),
|
||||||
|
|
||||||
RecordDestructure(destructs, _) => match test {
|
RecordDestructure(destructs, _) => match test {
|
||||||
IsCtor {
|
IsCtor {
|
||||||
|
@ -742,7 +742,7 @@ fn needs_tests<'a>(pattern: &Pattern<'a>) -> bool {
|
||||||
use Pattern::*;
|
use Pattern::*;
|
||||||
|
|
||||||
match pattern {
|
match pattern {
|
||||||
Identifier(_) | Underscore | UnsupportedPattern(_) => false,
|
Identifier(_) | Underscore => false,
|
||||||
|
|
||||||
RecordDestructure(_, _)
|
RecordDestructure(_, _)
|
||||||
| AppliedTag { .. }
|
| AppliedTag { .. }
|
||||||
|
|
|
@ -84,12 +84,6 @@ fn simplify<'a>(pattern: &crate::ir::Pattern<'a>) -> Pattern {
|
||||||
Ctor(union, tag_id, patterns)
|
Ctor(union, tag_id, patterns)
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsupportedPattern(_region) => {
|
|
||||||
// Treat as an Anything
|
|
||||||
// code-gen will make a runtime error out of the branch
|
|
||||||
Anything
|
|
||||||
}
|
|
||||||
|
|
||||||
AppliedTag {
|
AppliedTag {
|
||||||
tag_id,
|
tag_id,
|
||||||
arguments,
|
arguments,
|
||||||
|
|
|
@ -4699,10 +4699,6 @@ fn store_pattern<'a>(
|
||||||
RecordDestructure(_, _) => {
|
RecordDestructure(_, _) => {
|
||||||
unreachable!("a record destructure must always occur on a struct layout");
|
unreachable!("a record destructure must always occur on a struct layout");
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsupportedPattern(_region) => {
|
|
||||||
return Err(&"unsupported pattern");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(stmt)
|
Ok(stmt)
|
||||||
|
@ -5466,11 +5462,6 @@ pub enum Pattern<'a> {
|
||||||
layout: Layout<'a>,
|
layout: Layout<'a>,
|
||||||
union: crate::exhaustive::Union,
|
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)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
@ -5512,10 +5503,11 @@ pub fn from_can_pattern<'a>(
|
||||||
original_region: *region,
|
original_region: *region,
|
||||||
shadow: ident.clone(),
|
shadow: ident.clone(),
|
||||||
}),
|
}),
|
||||||
UnsupportedPattern(region) => Ok(Pattern::UnsupportedPattern(*region)),
|
UnsupportedPattern(region) => Err(RuntimeError::UnsupportedPattern(*region)),
|
||||||
|
|
||||||
MalformedPattern(_problem, region) => {
|
MalformedPattern(_problem, region) => {
|
||||||
// TODO preserve malformed problem information here?
|
// 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) {
|
NumLiteral(var, num) => match num_argument_to_int_or_float(env.subs, *var) {
|
||||||
IntOrFloat::IntType => Ok(Pattern::IntLiteral(*num)),
|
IntOrFloat::IntType => Ok(Pattern::IntLiteral(*num)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue