diff --git a/crates/erg_compiler/context/initialize/funcs.rs b/crates/erg_compiler/context/initialize/funcs.rs index 5e9929c90..e3b4888fc 100644 --- a/crates/erg_compiler/context/initialize/funcs.rs +++ b/crates/erg_compiler/context/initialize/funcs.rs @@ -5,7 +5,7 @@ use erg_common::log; use crate::ty::constructors::*; use crate::ty::typaram::TyParam; use crate::ty::value::ValueObj; -use crate::ty::{CastTarget, Field, GuardType, Type, Visibility}; +use crate::ty::{CastTarget, Field, Type, Visibility}; use Type::*; use crate::context::initialize::*; @@ -108,14 +108,14 @@ impl Context { poly(ENUMERATE, vec![ty_tp(T.clone())]), ) .quantify(); - let guard = Type::Guard(GuardType::new( + let grd = guard( "".into(), CastTarget::arg(0, "x".into(), Location::Unknown), U.clone(), - )); + ); let t_filter = nd_func( vec![ - kw(KW_FUNC, nd_func(vec![kw("x", T.clone())], None, guard)), + kw(KW_FUNC, nd_func(vec![kw("x", T.clone())], None, grd)), kw(KW_ITERABLE, poly(ITERABLE, vec![ty_tp(T.clone())])), ], None, diff --git a/crates/erg_compiler/context/initialize/traits.rs b/crates/erg_compiler/context/initialize/traits.rs index 23f1cf094..fd2b6fe35 100644 --- a/crates/erg_compiler/context/initialize/traits.rs +++ b/crates/erg_compiler/context/initialize/traits.rs @@ -3,7 +3,7 @@ use erg_common::log; use crate::ty::constructors::*; use crate::ty::value::ValueObj; -use crate::ty::{Type, Visibility}; +use crate::ty::{CastTarget, Type, Visibility}; use ParamSpec as PS; use Type::*; @@ -249,12 +249,23 @@ impl Context { Visibility::BUILTIN_PUBLIC, Some("Function::iterable_map"), ); + let grd = guard( + "".into(), + CastTarget::arg(0, "x".into(), Location::Unknown), + U.clone(), + ); let t_filter = fn1_met( Slf.clone(), - func1(T.clone(), Bool), - poly(FILTER, vec![ty_tp(T.clone())]), + nd_func(vec![kw("x", T.clone())], None, grd), + poly(FILTER, vec![ty_tp(T.clone() & U.clone())]), ) - .quantify(); + .quantify() + & fn1_met( + Slf.clone(), + func1(T.clone(), Bool), + poly(FILTER, vec![ty_tp(T.clone())]), + ) + .quantify(); iterable.register_builtin_decl( FUNC_FILTER, t_filter,