mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
chore: improve overload error msg
This commit is contained in:
parent
5cf3acbf16
commit
22cd07a414
6 changed files with 52 additions and 13 deletions
|
@ -494,7 +494,20 @@ impl Context {
|
|||
int.register_trait(self, mono(NUM)).unwrap();
|
||||
// class("Rational"),
|
||||
// class("Integral"),
|
||||
int.register_py_builtin(FUNC_ABS, fn0_met(Int, Nat), Some(OP_ABS), 11);
|
||||
let i_abs = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||
FUNC_ABS,
|
||||
int_abs,
|
||||
fn0_met(Int, Nat),
|
||||
None,
|
||||
)));
|
||||
int.register_py_builtin_const(
|
||||
FUNC_ABS,
|
||||
Visibility::BUILTIN_PUBLIC,
|
||||
Some(fn0_met(Int, Nat)),
|
||||
i_abs,
|
||||
Some(OP_ABS),
|
||||
Some(11),
|
||||
);
|
||||
int.register_py_builtin(FUNC_SUCC, fn0_met(Int, Int), Some(FUNC_SUCC), 54);
|
||||
int.register_py_builtin(FUNC_PRED, fn0_met(Int, Int), Some(FUNC_PRED), 47);
|
||||
int.register_py_builtin(
|
||||
|
@ -1732,12 +1745,12 @@ impl Context {
|
|||
Predicate::le(var, N.clone() - value(1usize)),
|
||||
);
|
||||
// __getitem__: |T, N|(self: [T; N], _: {I: Nat | I <= N}) -> T
|
||||
// and (self: [T; N], _: Range(Int)) -> [T; _]
|
||||
// and (self: [T; N], _: Range(Int) | Slice) -> [T; _]
|
||||
let list_getitem_t =
|
||||
(fn1_kw_met(list_t(T.clone(), N.clone()), anon(input.clone()), T.clone())
|
||||
& fn1_kw_met(
|
||||
list_t(T.clone(), N.clone()),
|
||||
anon(poly(RANGE, vec![ty_tp(Int)])),
|
||||
anon(poly(RANGE, vec![ty_tp(Int)]) | mono(SLICE)),
|
||||
unknown_len_list_t(T.clone()),
|
||||
))
|
||||
.quantify();
|
||||
|
|
|
@ -985,6 +985,16 @@ pub(crate) fn as_record(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<T
|
|||
Ok(ValueObj::builtin_type(Type::Record(dict)).into())
|
||||
}
|
||||
|
||||
pub(crate) fn int_abs(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult<TyParam> {
|
||||
let slf = args
|
||||
.remove_left_or_key("self")
|
||||
.ok_or_else(|| not_passed("self"))?;
|
||||
let Some(slf) = slf.as_int() else {
|
||||
return Err(type_mismatch("Int", slf, "self"));
|
||||
};
|
||||
Ok(ValueObj::Int(slf.abs()).into())
|
||||
}
|
||||
|
||||
pub(crate) fn str_endswith(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult<TyParam> {
|
||||
let slf = args
|
||||
.remove_left_or_key("self")
|
||||
|
|
|
@ -1203,13 +1203,21 @@ impl Context {
|
|||
let Type::Subr(subr_t) = input_t else {
|
||||
unreachable!()
|
||||
};
|
||||
let non_default_params = subr_t
|
||||
.non_default_params
|
||||
.iter()
|
||||
.map(|pt| pt.clone().map_type(|t| self.readable_type(t)));
|
||||
let default_params = subr_t
|
||||
.default_params
|
||||
.iter()
|
||||
.map(|pt| pt.clone().map_type(|t| self.readable_type(t)));
|
||||
Err(TyCheckError::overload_error(
|
||||
self.cfg.input.clone(),
|
||||
line!() as usize,
|
||||
loc.loc(),
|
||||
self.caused_by(),
|
||||
subr_t.non_default_params,
|
||||
subr_t.default_params,
|
||||
non_default_params,
|
||||
default_params,
|
||||
intersecs.iter(),
|
||||
))
|
||||
}
|
||||
|
@ -3530,7 +3538,7 @@ impl Context {
|
|||
attr,
|
||||
&candidates
|
||||
.iter()
|
||||
.map(|mp| mp.definition_type.clone())
|
||||
.map(|mp| self.readable_type(mp.definition_type.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
namespace.caused_by(),
|
||||
))
|
||||
|
|
|
@ -1346,18 +1346,18 @@ passed keyword args: {kw_args_len}"
|
|||
errno: usize,
|
||||
loc: Location,
|
||||
caused_by: String,
|
||||
pos_args: Vec<ParamTy>,
|
||||
kw_args: Vec<ParamTy>,
|
||||
pos_args: impl Iterator<Item = ParamTy>,
|
||||
kw_args: impl Iterator<Item = ParamTy>,
|
||||
found: impl Iterator<Item = &'a Type>,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
ErrorCore::new(
|
||||
vec![],
|
||||
switch_lang!(
|
||||
"japanese" => format!("オーバーロード解決に失敗しました\nオーバーロード型:\n* {}\n渡された位置引数: {}\n渡された名前付き引数: {}", fmt_iter_split_with(found, "\n* "), fmt_vec(&pos_args), fmt_vec(&kw_args)),
|
||||
"simplified_chinese" => format!("无法解析重载\n重载类型:\n* {}\n位置参数: {}\n命名参数: {}", fmt_iter_split_with(found, "\n* "), fmt_vec(&pos_args), fmt_vec(&kw_args)),
|
||||
"traditional_chinese" => format!("無法解析重載\n重載類型:\n* {}\n位置參數: {}\n命名參數: {}", fmt_iter_split_with(found, "\n* "), fmt_vec(&pos_args), fmt_vec(&kw_args)),
|
||||
"english" => format!("cannot resolve overload\noverloaded type:\n* {}\npassed positional arguments: {}\npassed named arguments: {}", fmt_iter_split_with(found, "\n* "), fmt_vec(&pos_args), fmt_vec(&kw_args)),
|
||||
"japanese" => format!("オーバーロード解決に失敗しました\nオーバーロード型:\n* {}\n渡された位置引数: {}\n渡された名前付き引数: {}", fmt_iter_split_with(found, "\n* "), fmt_iter(pos_args), fmt_iter(kw_args)),
|
||||
"simplified_chinese" => format!("无法解析重载\n重载类型:\n* {}\n位置参数: {}\n命名参数: {}", fmt_iter_split_with(found, "\n* "), fmt_iter(pos_args), fmt_iter(kw_args)),
|
||||
"traditional_chinese" => format!("無法解析重載\n重載類型:\n* {}\n位置參數: {}\n命名參數: {}", fmt_iter_split_with(found, "\n* "), fmt_iter(pos_args), fmt_iter(kw_args)),
|
||||
"english" => format!("cannot resolve overload\noverloaded type:\n* {}\npassed positional arguments: {}\npassed named arguments: {}", fmt_iter_split_with(found, "\n* "), fmt_iter(pos_args), fmt_iter(kw_args)),
|
||||
),
|
||||
errno,
|
||||
TypeError,
|
||||
|
|
|
@ -11,6 +11,13 @@
|
|||
.capwords: (s: Str, sep := Str) -> Str
|
||||
|
||||
.Template: ClassType
|
||||
.Template.
|
||||
template: Str
|
||||
__call__: (template: Str) -> .Template
|
||||
substitute: (self: .Template, mapping := {Str: Str}, **kws: Str) -> Str
|
||||
safe_substitute: (self: .Template, mapping := {Str: Str}, **kws: Str) -> Str
|
||||
is_valid: (self: .Template) -> Bool
|
||||
get_identifiers: (self: .Template) -> [Str; _]
|
||||
|
||||
FormatterIterator = 'formatteriterator': ClassType
|
||||
FormatterIterator <: Iterable [Str; _]
|
||||
|
|
|
@ -422,8 +422,9 @@ impl LimitedDisplay for TyParam {
|
|||
write!(f, "{attr}")
|
||||
}
|
||||
Self::ProjCall { obj, attr, args } => {
|
||||
write!(f, "(")?;
|
||||
obj.limited_fmt(f, limit - 1)?;
|
||||
write!(f, ".")?;
|
||||
write!(f, ").")?;
|
||||
write!(f, "{attr}")?;
|
||||
write!(f, "(")?;
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue