Restrict usages of type variables in non-generalized contexts

Type variables can only be used on functions (and in number literals as
a carve-out for now). In all other cases, a type variable takes on a
single, concrete type based on later usages. This check emits errors
when this is violated.

The implementation is to check the rank of a variable after it could be
generalized. If the variable is not generalized but annotated as a type
variable, emit an error.
This commit is contained in:
Ayaz Hafiz 2025-01-02 14:26:37 -06:00
parent f5961cbb22
commit a0461679dd
13 changed files with 230 additions and 114 deletions

View file

@ -356,9 +356,9 @@ fn unify_help<M: MetaCollector>(
}
} else {
let error_context = if mismatches.contains(&Mismatch::TypeNotInRange) {
ErrorTypeContext::ExpandRanges
ErrorTypeContext::EXPAND_RANGES
} else {
ErrorTypeContext::None
ErrorTypeContext::empty()
};
let type1 = env.var_to_error_type_contextual(var1, error_context, observed_pol);