implement can crate

This commit is contained in:
Folkert 2022-03-17 19:04:24 +01:00
parent 4545e76b76
commit 34e566965d
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 19 additions and 10 deletions

View file

@ -7,7 +7,7 @@ use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_parse::ast::{AssignedField, Pattern, Tag, TypeAnnotation, TypeHeader};
use roc_region::all::{Loc, Region};
use roc_types::subs::{VarStore, Variable};
use roc_types::types::{Alias, AliasKind, LambdaSet, Problem, RecordField, Type};
use roc_types::types::{Alias, AliasKind, LambdaSet, Problem, RecordField, Type, TypeExtension};
#[derive(Clone, Debug, PartialEq)]
pub struct Annotation {
@ -542,7 +542,7 @@ fn can_annotation_help(
// just `a` does not mean the same as `{}a`, so even
// if there are no fields, still make this a `Record`,
// not an EmptyRec
Type::Record(Default::default(), Box::new(ext_type))
Type::Record(Default::default(), TypeExtension::from_type(ext_type))
}
None => Type::EmptyRec,
@ -559,7 +559,7 @@ fn can_annotation_help(
references,
);
Type::Record(field_types, Box::new(ext_type))
Type::Record(field_types, TypeExtension::from_type(ext_type))
}
}
TagUnion { tags, ext, .. } => {
@ -580,7 +580,7 @@ fn can_annotation_help(
// just `a` does not mean the same as `{}a`, so even
// if there are no fields, still make this a `Record`,
// not an EmptyRec
Type::TagUnion(Default::default(), Box::new(ext_type))
Type::TagUnion(Default::default(), TypeExtension::from_type(ext_type))
}
None => Type::EmptyTagUnion,
@ -602,7 +602,7 @@ fn can_annotation_help(
// in theory we save a lot of time by sorting once here
insertion_sort_by(&mut tag_types, |a, b| a.0.cmp(&b.0));
Type::TagUnion(tag_types, Box::new(ext_type))
Type::TagUnion(tag_types, TypeExtension::from_type(ext_type))
}
}
SpaceBefore(nested, _) | SpaceAfter(nested, _) => can_annotation_help(

View file

@ -10,7 +10,7 @@ use roc_module::ident::TagName;
use roc_module::symbol::Symbol;
use roc_region::all::{Loc, Region};
use roc_types::subs::{VarStore, Variable};
use roc_types::types::{AliasKind, Type};
use roc_types::types::{AliasKind, Type, TypeExtension};
#[derive(Default, Clone, Copy)]
pub(crate) struct HostedGeneratedFunctions {
@ -1111,7 +1111,7 @@ fn build_effect_loop(
(step_tag_name, vec![Type::Variable(var_a)]),
(done_tag_name, vec![Type::Variable(var_b)]),
],
Box::new(Type::EmptyTagUnion),
TypeExtension::Closed,
)
};
@ -1129,7 +1129,7 @@ fn build_effect_loop(
Box::new(state_type.clone()),
)],
)],
Box::new(Type::EmptyTagUnion),
TypeExtension::Closed,
)
};
@ -1571,7 +1571,7 @@ fn build_effect_alias(
Box::new(a_type),
)],
)],
Box::new(Type::EmptyTagUnion),
TypeExtension::Closed,
)
};
@ -1600,7 +1600,7 @@ pub fn build_effect_actual(
Box::new(a_type),
)],
)],
Box::new(Type::EmptyTagUnion),
TypeExtension::Closed,
)
}

View file

@ -219,6 +219,15 @@ pub enum TypeExtension {
Closed,
}
impl TypeExtension {
pub fn from_type(typ: Type) -> Self {
match typ {
Type::EmptyTagUnion | Type::EmptyRec => Self::Closed,
_ => Self::Open(Box::new(typ)),
}
}
}
impl IntoIterator for TypeExtension {
type Item = Box<Type>;