mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Suggest binding type variables to an ability when they're unsatisfied
This commit is contained in:
parent
df7f57e4a3
commit
7c3a0807c2
2 changed files with 35 additions and 2 deletions
|
@ -502,7 +502,7 @@ trait DerivableVisitor {
|
|||
if abilities != [Self::ABILITY] {
|
||||
Err(NotDerivable {
|
||||
var,
|
||||
context: NotDerivableContext::NoContext,
|
||||
context: NotDerivableContext::UnboundVar,
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
|
@ -634,7 +634,7 @@ trait DerivableVisitor {
|
|||
RigidVar(_) => {
|
||||
return Err(NotDerivable {
|
||||
var,
|
||||
context: NotDerivableContext::NoContext,
|
||||
context: NotDerivableContext::UnboundVar,
|
||||
})
|
||||
}
|
||||
FlexAbleVar(opt_name, abilities) => {
|
||||
|
|
|
@ -12446,4 +12446,37 @@ All branches in an `if` must have the same type!
|
|||
to be more general?
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
suggest_binding_rigid_var_to_ability,
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [f] to "./p"
|
||||
|
||||
f : List e -> List e
|
||||
f = \l -> if l == l then l else l
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
This expression has a type that does not implement the abilities it's expected to:
|
||||
|
||||
4│ f = \l -> if l == l then l else l
|
||||
^
|
||||
|
||||
I can't generate an implementation of the `Eq` ability for
|
||||
|
||||
List e
|
||||
|
||||
In particular, an implementation for
|
||||
|
||||
e
|
||||
|
||||
cannot be generated.
|
||||
|
||||
Tip: This type variable is not bound to `Eq`. Consider adding a `has`
|
||||
clause to bind the type variable, like `| e has Bool.Eq`
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue