mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Support underscores in assignment patterns
This commit is contained in:
parent
569e90d682
commit
beccc92c87
4 changed files with 16 additions and 25 deletions
|
@ -384,10 +384,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
ptype => unsupported_pattern(env, ptype, region),
|
||||
},
|
||||
|
||||
Underscore(_) => match pattern_type {
|
||||
WhenBranch | FunctionArg => Pattern::Underscore,
|
||||
TopLevelDef | DefExpr => bad_underscore(env, region),
|
||||
},
|
||||
Underscore(_) => Pattern::Underscore,
|
||||
|
||||
&NumLiteral(str) => match pattern_type {
|
||||
WhenBranch => match finish_parsing_num(str) {
|
||||
|
@ -652,16 +649,6 @@ fn unsupported_pattern(env: &mut Env, pattern_type: PatternType, region: Region)
|
|||
Pattern::UnsupportedPattern(region)
|
||||
}
|
||||
|
||||
fn bad_underscore(env: &mut Env, region: Region) -> Pattern {
|
||||
use roc_problem::can::BadPattern;
|
||||
env.problem(Problem::UnsupportedPattern(
|
||||
BadPattern::UnderscoreInDef,
|
||||
region,
|
||||
));
|
||||
|
||||
Pattern::UnsupportedPattern(region)
|
||||
}
|
||||
|
||||
/// When we detect a malformed pattern like `3.X` or `0b5`,
|
||||
/// report it to Env and return an UnsupportedPattern runtime error pattern.
|
||||
fn malformed_pattern(env: &mut Env, problem: MalformedPatternProblem, region: Region) -> Pattern {
|
||||
|
|
|
@ -16,7 +16,6 @@ pub struct CycleEntry {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum BadPattern {
|
||||
UnderscoreInDef,
|
||||
Unsupported(PatternType),
|
||||
}
|
||||
|
||||
|
|
|
@ -7438,6 +7438,20 @@ mod solve_expr {
|
|||
"#
|
||||
),
|
||||
@r#"x : { a : [A { b : [B]* }*]* }*"#
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_type_with_underscore_destructure_assignment() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Pair x _ = Pair 0 1
|
||||
|
||||
x
|
||||
"#
|
||||
),
|
||||
"Num *",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,15 +192,6 @@ pub fn can_problem<'b>(
|
|||
title = SYNTAX_PROBLEM.to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
Problem::UnsupportedPattern(BadPattern::UnderscoreInDef, region) => {
|
||||
doc = alloc.stack([
|
||||
alloc.reflow("Underscore patterns are not allowed in definitions"),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
]);
|
||||
|
||||
title = SYNTAX_PROBLEM.to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
Problem::UnsupportedPattern(BadPattern::Unsupported(pattern_type), region) => {
|
||||
use roc_parse::pattern::PatternType::*;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue