fix: error msg for illegal use of Self type

This commit is contained in:
Shunsuke Shibayama 2023-06-23 20:30:35 +09:00
parent e7072bdb84
commit 456cc458fe
2 changed files with 23 additions and 3 deletions

View file

@ -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(

View file

@ -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,
)
}
}