mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 12:24:45 +00:00
Add SetTypeSpec
This commit is contained in:
parent
3112fb31a9
commit
2cf4b5aba8
6 changed files with 85 additions and 12 deletions
|
@ -785,7 +785,7 @@ impl Context {
|
|||
let mut module = Self::builtin_poly_class("Module", vec![PS::named_nd("Path", Str)], 2);
|
||||
module.register_superclass(g_module_t.clone(), &generic_module);
|
||||
|
||||
// *** Array *** //
|
||||
/* Array */
|
||||
let mut array_ =
|
||||
Self::builtin_poly_class("Array", vec![PS::t_nd("T"), PS::named_nd("N", Nat)], 10);
|
||||
array_.register_superclass(Obj, &obj);
|
||||
|
@ -833,15 +833,14 @@ impl Context {
|
|||
Public,
|
||||
);
|
||||
array_.register_trait(array_t, builtin_mono("Show"), array_show);
|
||||
|
||||
// *** Set *** //
|
||||
/* Set */
|
||||
let mut set_ =
|
||||
Self::builtin_poly_class("Set", vec![PS::t_nd("T"), PS::named_nd("N", Nat)], 10);
|
||||
set_.register_superclass(Obj, &obj);
|
||||
set_.register_marker_trait(builtin_poly("output", vec![ty_tp(mono_q("T"))]));
|
||||
let n = mono_q_tp("N");
|
||||
let m = mono_q_tp("M");
|
||||
let set_t = array(mono_q("T"), n.clone());
|
||||
set_.register_superclass(Obj, &obj);
|
||||
set_.register_marker_trait(builtin_poly("Output", vec![ty_tp(mono_q("T"))]));
|
||||
let t = fn_met(
|
||||
set_t.clone(),
|
||||
vec![kw("rhs", array(mono_q("T"), m.clone()))],
|
||||
|
@ -866,7 +865,7 @@ impl Context {
|
|||
Const,
|
||||
Public,
|
||||
);
|
||||
array_.register_trait(
|
||||
set_.register_trait(
|
||||
set_t.clone(),
|
||||
builtin_poly("Eq", vec![ty_tp(set_t.clone())]),
|
||||
set_eq,
|
||||
|
|
|
@ -1304,7 +1304,9 @@ impl Context {
|
|||
) -> Option<impl Iterator<Item = (&'a Type, &'a Context)>> {
|
||||
let (_ctx_t, ctx) = self.get_nominal_type_ctx(t)?;
|
||||
Some(ctx.super_traits.iter().map(|sup| {
|
||||
let (_t, sup_ctx) = self.get_nominal_type_ctx(sup).unwrap();
|
||||
let (_t, sup_ctx) = self
|
||||
.get_nominal_type_ctx(sup)
|
||||
.unwrap_or_else(|| todo!("{} not found", sup));
|
||||
(sup, sup_ctx)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -784,6 +784,11 @@ impl Context {
|
|||
let len = self.instantiate_const_expr(&arr.len);
|
||||
Ok(array(elem_t, len))
|
||||
}
|
||||
TypeSpec::Set(set) => {
|
||||
let elem_t = self.instantiate_typespec(&set.ty, opt_decl_t, tmp_tv_ctx, mode)?;
|
||||
let len = self.instantiate_const_expr(&set.len);
|
||||
Ok(erg_type::constructors::set(elem_t, len))
|
||||
}
|
||||
// FIXME: unwrap
|
||||
TypeSpec::Tuple(tys) => Ok(tuple(
|
||||
tys.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue