mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 00:09:33 +03:00
Inline BadType::BadTypeArguments in canonicalization errors
This commit is contained in:
parent
98464984dd
commit
8dfc9c0367
@ -625,15 +625,13 @@ fn can_annotation_help(
|
||||
// use a known alias
|
||||
|
||||
if alias.type_variables.len() != args.len() {
|
||||
env.problem(roc_problem::can::Problem::BadType(
|
||||
Problem::BadTypeArguments {
|
||||
symbol,
|
||||
region,
|
||||
alias_needs: alias.type_variables.len() as u8,
|
||||
type_got: args.len() as u8,
|
||||
alias_kind: alias.kind,
|
||||
},
|
||||
));
|
||||
env.problem(roc_problem::can::Problem::BadTypeArguments {
|
||||
symbol,
|
||||
region,
|
||||
alias_needs: alias.type_variables.len() as u8,
|
||||
type_got: args.len() as u8,
|
||||
alias_kind: alias.kind,
|
||||
});
|
||||
return Type::Erroneous;
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,13 @@ pub enum Problem {
|
||||
MultipleListRestPattern {
|
||||
region: Region,
|
||||
},
|
||||
BadType(roc_types::types::Problem),
|
||||
BadTypeArguments {
|
||||
symbol: Symbol,
|
||||
region: Region,
|
||||
alias_needs: u8,
|
||||
type_got: u8,
|
||||
alias_kind: AliasKind,
|
||||
},
|
||||
}
|
||||
|
||||
impl Problem {
|
||||
@ -318,6 +324,7 @@ impl Problem {
|
||||
..
|
||||
}
|
||||
| Problem::MultipleListRestPattern { region }
|
||||
| Problem::BadTypeArguments { region, .. }
|
||||
| Problem::UnnecessaryOutputWildcard { region } => Some(*region),
|
||||
Problem::RuntimeError(RuntimeError::CircularDef(cycle_entries))
|
||||
| Problem::BadRecursion(cycle_entries) => {
|
||||
@ -331,7 +338,6 @@ impl Problem {
|
||||
| Problem::RuntimeError(RuntimeError::ExposedButNotDefined(_))
|
||||
| Problem::RuntimeError(RuntimeError::NoImplementationNamed { .. })
|
||||
| Problem::ExposedButNotDefined(_) => None,
|
||||
Problem::BadType(..) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1037,53 +1037,46 @@ pub fn can_problem<'b>(
|
||||
title = "MULTIPLE LIST REST PATTERNS".to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
Problem::BadType(type_problem) => {
|
||||
use roc_types::types::Problem::*;
|
||||
match type_problem {
|
||||
BadTypeArguments {
|
||||
symbol,
|
||||
region,
|
||||
type_got,
|
||||
alias_needs,
|
||||
alias_kind,
|
||||
} => {
|
||||
let needed_arguments = if alias_needs == 1 {
|
||||
alloc.reflow("1 type argument")
|
||||
} else {
|
||||
alloc
|
||||
.text(alias_needs.to_string())
|
||||
.append(alloc.reflow(" type arguments"))
|
||||
};
|
||||
Problem::BadTypeArguments {
|
||||
symbol,
|
||||
region,
|
||||
type_got,
|
||||
alias_needs,
|
||||
alias_kind,
|
||||
} => {
|
||||
let needed_arguments = if alias_needs == 1 {
|
||||
alloc.reflow("1 type argument")
|
||||
} else {
|
||||
alloc
|
||||
.text(alias_needs.to_string())
|
||||
.append(alloc.reflow(" type arguments"))
|
||||
};
|
||||
|
||||
let found_arguments = alloc.text(type_got.to_string());
|
||||
let found_arguments = alloc.text(type_got.to_string());
|
||||
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.reflow("The "),
|
||||
alloc.symbol_unqualified(symbol),
|
||||
alloc.reflow(" "),
|
||||
alloc.reflow(alias_kind.as_str()),
|
||||
alloc.reflow(" expects "),
|
||||
needed_arguments,
|
||||
alloc.reflow(", but it got "),
|
||||
found_arguments,
|
||||
alloc.reflow(" instead:"),
|
||||
]),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
alloc.reflow("Are there missing parentheses?"),
|
||||
]);
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.reflow("The "),
|
||||
alloc.symbol_unqualified(symbol),
|
||||
alloc.reflow(" "),
|
||||
alloc.reflow(alias_kind.as_str()),
|
||||
alloc.reflow(" expects "),
|
||||
needed_arguments,
|
||||
alloc.reflow(", but it got "),
|
||||
found_arguments,
|
||||
alloc.reflow(" instead:"),
|
||||
]),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
alloc.reflow("Are there missing parentheses?"),
|
||||
]);
|
||||
|
||||
title = if type_got > alias_needs {
|
||||
"TOO MANY TYPE ARGUMENTS".to_string()
|
||||
} else {
|
||||
"TOO FEW TYPE ARGUMENTS".to_string()
|
||||
};
|
||||
title = if type_got > alias_needs {
|
||||
"TOO MANY TYPE ARGUMENTS".to_string()
|
||||
} else {
|
||||
"TOO FEW TYPE ARGUMENTS".to_string()
|
||||
};
|
||||
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
|
||||
other => panic!("unhandled bad type: {:?}", other),
|
||||
}
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user