parent
ce65236514
commit
4459fdb360
|
@ -18,7 +18,7 @@ use crate::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
error::{Error, Warning},
|
||||
error::{Error, Snippet, Warning},
|
||||
hydrator::Hydrator,
|
||||
AccessorsMap, PatternConstructor, RecordAccessor, Type, TypeConstructor, TypeInfo, TypeVar,
|
||||
ValueConstructor, ValueConstructorVariant,
|
||||
|
@ -867,26 +867,41 @@ impl<'a> Environment<'a> {
|
|||
Some(e) => {
|
||||
let known_types_after = names.keys().copied().collect::<Vec<_>>();
|
||||
if known_types_before == known_types_after {
|
||||
let cycle = remaining_definitions
|
||||
let unknown_name = match e {
|
||||
Error::UnknownType { ref name, .. } => name,
|
||||
_ => "",
|
||||
};
|
||||
let mut is_cyclic = false;
|
||||
let unknown_types = remaining_definitions
|
||||
.into_iter()
|
||||
.filter_map(|def| match def {
|
||||
Definition::TypeAlias(TypeAlias {
|
||||
alias, location, ..
|
||||
}) => Some((alias.to_owned(), location.to_owned())),
|
||||
_ => None,
|
||||
}) => {
|
||||
is_cyclic = is_cyclic || alias == unknown_name;
|
||||
Some(Snippet {
|
||||
location: location.to_owned(),
|
||||
})
|
||||
}
|
||||
Definition::DataType(DataType { name, location, .. }) => {
|
||||
is_cyclic = is_cyclic || name == unknown_name;
|
||||
Some(Snippet {
|
||||
location: location.to_owned(),
|
||||
})
|
||||
}
|
||||
Definition::Fn { .. }
|
||||
| Definition::Use { .. }
|
||||
| Definition::ModuleConstant { .. }
|
||||
| Definition::Test { .. } => None,
|
||||
})
|
||||
.collect::<Vec<(String, Span)>>();
|
||||
match cycle.first() {
|
||||
None => Err(e),
|
||||
Some((alias, location)) => {
|
||||
let mut types =
|
||||
cycle.iter().map(|def| def.0.clone()).collect::<Vec<_>>();
|
||||
types.push(alias.clone());
|
||||
Err(Error::CyclicTypeDefinitions {
|
||||
location: *location,
|
||||
types,
|
||||
})
|
||||
}
|
||||
.collect::<Vec<Snippet>>();
|
||||
|
||||
if is_cyclic {
|
||||
Err(Error::CyclicTypeDefinitions {
|
||||
errors: unknown_types,
|
||||
})
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
} else {
|
||||
self.register_types(remaining_definitions, module, hydrators, names)
|
||||
|
|
Loading…
Reference in New Issue