Inline BadType::BadTypeArguments in canonicalization errors

This commit is contained in:
Ayaz Hafiz 2022-11-08 13:44:07 -06:00
parent 98464984dd
commit 8dfc9c0367
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
3 changed files with 51 additions and 54 deletions

View File

@ -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;
}

View File

@ -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,
}
}
}

View File

@ -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;
}
};