Revert "Include annotation type signatures in Expected struct"

This reverts commit 6e4fd5f06a1ae6138659b0073b4e2b375a499588.

This idea didn't work out because cloning the type and storing it on a
variable still resulted in the solver trying to uify the variable with
the type. When there were errors, which there certainly would be if we
tried to unify the variable with a structure that had nested flex/rigid
vars, the nested flex/rigid vars would inherit those errors, and the
program wouldn't typecheck.

Since the motivation here was to expose the signature type to
`reporting` so that we could modify it with suggestions, we should
instead pass that information along in something analogous to the
`Expected` struct.
This commit is contained in:
ayazhafiz 2021-11-25 13:08:18 -05:00
parent a8e38172ac
commit d352d2cdf8
16 changed files with 64 additions and 204 deletions

View file

@ -1107,61 +1107,28 @@ pub enum PReason {
OptionalField,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum AnnotationSource<Annot> {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnnotationSource {
TypedIfBranch {
index: Index,
num_branches: usize,
annotation: Located<Annot>,
region: Region,
},
TypedWhenBranch {
index: Index,
annotation: Located<Annot>,
region: Region,
},
TypedBody {
annotation: Located<Annot>,
region: Region,
},
}
impl<Annot> AnnotationSource<Annot> {
impl AnnotationSource {
pub fn region(&self) -> Region {
match self {
Self::TypedIfBranch { annotation, .. }
| Self::TypedWhenBranch { annotation, .. }
| Self::TypedBody { annotation, .. } => annotation.region,
}
}
pub fn annotation(&self) -> &Located<Annot> {
match self {
Self::TypedIfBranch { annotation, .. }
| Self::TypedWhenBranch { annotation, .. }
| Self::TypedBody { annotation, .. } => annotation,
}
}
pub fn replace_with<Annot2, F>(self, create_new_annotation: F) -> AnnotationSource<Annot2>
where
F: FnOnce(Annot) -> Annot2,
{
use AnnotationSource::*;
match self {
TypedIfBranch {
index,
num_branches,
annotation,
} => TypedIfBranch {
index,
num_branches,
annotation: annotation.map_in_place(create_new_annotation),
},
TypedWhenBranch { index, annotation } => TypedWhenBranch {
index,
annotation: annotation.map_in_place(create_new_annotation),
},
TypedBody { annotation } => TypedBody {
annotation: annotation.map_in_place(create_new_annotation),
},
&Self::TypedIfBranch { region, .. }
| &Self::TypedWhenBranch { region, .. }
| &Self::TypedBody { region, .. } => region,
}
}
}