treat wildcards as rigids

This commit is contained in:
Folkert 2021-05-03 20:39:06 +02:00
parent 84c46b94e2
commit 9b0e14ef4c
2 changed files with 57 additions and 9 deletions

View file

@ -155,8 +155,12 @@ where
} }
} }
for (var, lowercase) in output.introduced_variables.name_by_var.clone() { for (var, lowercase) in output.introduced_variables.name_by_var {
rigid_variables.insert(var, lowercase); rigid_variables.insert(var, lowercase.clone());
}
for var in output.introduced_variables.wildcards {
rigid_variables.insert(var, "*".into());
} }
let mut references = MutSet::default(); let mut references = MutSet::default();

View file

@ -71,6 +71,10 @@ mod test_reporting {
subs.rigid_var(var, name); subs.rigid_var(var, name);
} }
for var in output.introduced_variables.wildcards {
subs.rigid_var(var, "*".into());
}
let mut unify_problems = Vec::new(); let mut unify_problems = Vec::new();
let (_content, mut subs) = infer_expr(subs, &mut unify_problems, &constraint, var); let (_content, mut subs) = infer_expr(subs, &mut unify_problems, &constraint, var);
@ -6348,9 +6352,9 @@ mod test_reporting {
indoc!( indoc!(
r#" r#"
SYNTAX PROBLEM SYNTAX PROBLEM
Underscore patterns are not allowed in definitions Underscore patterns are not allowed in definitions
1 _ = 3 1 _ = 3
^ ^
"# "#
@ -6371,20 +6375,60 @@ mod test_reporting {
indoc!( indoc!(
r#" r#"
TYPE MISMATCH TYPE MISMATCH
This `expect` condition needs to be a Bool: This `expect` condition needs to be a Bool:
1 expect "foobar" 1 expect "foobar"
^^^^^^^^ ^^^^^^^^
Right now its a string of type: Right now its a string of type:
Str Str
But I need every `expect` condition to evaluate to a Booleither `True` But I need every `expect` condition to evaluate to a Booleither `True`
or `False`. or `False`.
"# "#
), ),
) )
} }
#[test]
fn num_too_general_wildcard() {
report_problem_as(
indoc!(
r#"
mult : Num *, F64 -> F64
mult = \a, b -> a * b
{}
"#
),
indoc!(
r#"
TYPE MISMATCH
"#
),
)
}
#[test]
fn num_too_general_named() {
report_problem_as(
indoc!(
r#"
mult : Num a, F64 -> F64
mult = \a, b -> a * b
{}
"#
),
indoc!(
r#"
TYPE MISMATCH
"#
),
)
}
} }