Fix match crashes

This commit is contained in:
Shunsuke Shibayama 2022-12-04 11:43:39 +09:00
parent 85370fb051
commit 48f91f969b
5 changed files with 137 additions and 20 deletions

View file

@ -554,6 +554,79 @@ impl TyCheckError {
)
}
pub fn param_error(
input: Input,
errno: usize,
loc: Location,
caused_by: String,
expect: usize,
found: usize,
) -> Self {
let mut expct = StyledStrings::default();
switch_lang!(
"japanese" => expct.push_str("予期した個数: "),
"simplified_chinese" =>expct.push_str("预期: "),
"traditional_chinese" => expct.push_str("預期: "),
"english" => expct.push_str("expected: "),
);
expct.push_str_with_color_and_attribute(format!("{}", expect), HINT, ATTR);
let mut fnd = StyledStrings::default();
switch_lang!(
"japanese" => fnd.push_str("与えられた個数: "),
"simplified_chinese" => fnd.push_str("但找到: "),
"traditional_chinese" => fnd.push_str("但找到: "),
"english" =>fnd.push_str("but found: "),
);
fnd.push_str_with_color_and_attribute(format!("{}", found), ERR, ATTR);
Self::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(
loc,
vec![expct.to_string(), fnd.to_string()],
None,
)],
switch_lang!(
"japanese" => format!("引数の数が違います"),
"simplified_chinese" => format!("参数的数量不匹配"),
"traditional_chinese" => format!("參數的數量不匹配"),
"english" => format!("the number of parameters is mismatched"),
),
errno,
TypeError,
loc,
),
input,
caused_by,
)
}
pub fn default_param_error(
input: Input,
errno: usize,
loc: Location,
caused_by: String,
name: &str,
) -> Self {
Self::new(
ErrorCore::new(
vec![],
switch_lang!(
"japanese" => format!("{name}はデフォルト引数を受け取りません"),
"simplified_chinese" => format!("{name}不接受默认参数"),
"traditional_chinese" => format!("{name}不接受預設參數"),
"english" => format!("{name} does not accept default parameters"),
),
errno,
TypeError,
loc,
),
input,
caused_by,
)
}
pub fn match_error(
input: Input,
errno: usize,