diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 38f5d99b63..ee5369dd4f 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -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( diff --git a/compiler/can/src/effect_module.rs b/compiler/can/src/effect_module.rs index 92fd123ab4..1c2f76d951 100644 --- a/compiler/can/src/effect_module.rs +++ b/compiler/can/src/effect_module.rs @@ -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, ) } diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 2cbdac3fa5..fcd58f2f0e 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -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;