mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix: error msg for illegal use of Self
type
This commit is contained in:
parent
e7072bdb84
commit
456cc458fe
2 changed files with 23 additions and 3 deletions
|
@ -518,10 +518,11 @@ impl Context {
|
|||
"TraitType" => Ok(Type::TraitType),
|
||||
"Type" => Ok(Type::Type),
|
||||
"Self" => self.rec_get_self_t().ok_or_else(|| {
|
||||
TyCheckErrors::from(TyCheckError::unreachable(
|
||||
TyCheckErrors::from(TyCheckError::self_type_error(
|
||||
self.cfg.input.clone(),
|
||||
erg_common::fn_name_full!(),
|
||||
line!(),
|
||||
line!() as usize,
|
||||
ident.loc(),
|
||||
self.caused_by(),
|
||||
))
|
||||
}),
|
||||
"True" | "False" | "None" => Err(TyCheckErrors::from(TyCheckError::not_a_type_error(
|
||||
|
|
|
@ -1326,4 +1326,23 @@ passed keyword args: {kw_args_len}"
|
|||
caused_by,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn self_type_error(input: Input, errno: usize, loc: Location, caused_by: String) -> Self {
|
||||
Self::new(
|
||||
ErrorCore::new(
|
||||
vec![SubMessage::only_loc(loc)],
|
||||
switch_lang!(
|
||||
"japanese" => format!("`Self`型はこの場所では使えません"),
|
||||
"simplified_chinese" => format!("`Self`类型不能用于此处"),
|
||||
"traditional_chinese" => format!("`Self`類型不能用於此處"),
|
||||
"english" => format!("`Self` type cannot be used here"),
|
||||
),
|
||||
errno,
|
||||
TypeError,
|
||||
loc,
|
||||
),
|
||||
input,
|
||||
caused_by,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue