mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 18:29:00 +00:00
feat: support inherited refinement types
This commit is contained in:
parent
678c02faf9
commit
a6336fa896
6 changed files with 125 additions and 26 deletions
|
@ -100,9 +100,9 @@ pub fn module_from_path<P: Into<PathBuf>>(path: P) -> Type {
|
|||
module(TyParam::Value(s))
|
||||
}
|
||||
|
||||
pub fn v_enum(s: Set<ValueObj>) -> Type {
|
||||
pub fn try_v_enum(s: Set<ValueObj>) -> Result<Type, Set<ValueObj>> {
|
||||
if !is_homogeneous(&s) {
|
||||
panic!("{s} is not homogeneous");
|
||||
return Err(s);
|
||||
}
|
||||
let name = FRESH_GEN.fresh_varname();
|
||||
let t = inner_class(&s);
|
||||
|
@ -111,7 +111,11 @@ pub fn v_enum(s: Set<ValueObj>) -> Type {
|
|||
.map(|o| Predicate::eq(name.clone(), TyParam::value(o)))
|
||||
.fold(Predicate::FALSE, |acc, p| acc | p);
|
||||
let refine = RefinementType::new(name, t, preds);
|
||||
Type::Refinement(refine)
|
||||
Ok(Type::Refinement(refine))
|
||||
}
|
||||
|
||||
pub fn v_enum(s: Set<ValueObj>) -> Type {
|
||||
try_v_enum(s).unwrap_or_else(|set| panic!("not homogeneous: {}", set))
|
||||
}
|
||||
|
||||
pub fn tp_enum(ty: Type, s: Set<TyParam>) -> Type {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue