Infer ranged number for chars in patterns

This commit is contained in:
Ayaz Hafiz 2022-10-03 15:57:54 -05:00
parent 811c8554ac
commit 619cd2f629
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
8 changed files with 48 additions and 17 deletions

View file

@ -71,7 +71,7 @@ fn headers_from_annotation_help(
| NumLiteral(..)
| IntLiteral(..)
| FloatLiteral(..)
| SingleQuote(_)
| SingleQuote(..)
| StrLiteral(_) => true,
RecordDestructure { destructs, .. } => match annotation.value.shallow_dealias() {
@ -320,9 +320,32 @@ pub fn constrain_pattern(
));
}
SingleQuote(_) => {
&SingleQuote(num_var, precision_var, _, bound) => {
// First constraint on the free num var; this improves the resolved type quality in
// case the bound is an alias.
let num_type = builtins::add_numeric_bound_constr(
constraints,
&mut state.constraints,
num_var,
num_var,
bound,
region,
Category::Int,
);
// Link the free num var with the int var and our expectation.
let int_type = builtins::num_int(Type::Variable(precision_var));
state.constraints.push(constraints.equal_types(
num_type.clone(), // TODO check me if something breaks!
Expected::NoExpectation(int_type),
Category::Int,
region,
));
// Also constrain the pattern against the num var, again to reuse aliases if they're present.
state.constraints.push(constraints.equal_pattern_types(
builtins::num_u32(),
num_type,
expected,
PatternCategory::Character,
region,