From d7ffb211a8c2c01bfc46eb8c482c30a4ffd4ead0 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Fri, 16 Sep 2022 00:35:58 +0900 Subject: [PATCH] let errors more readable --- compiler/erg_compiler/context/tyvar.rs | 5 +++-- compiler/erg_compiler/error.rs | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/erg_compiler/context/tyvar.rs b/compiler/erg_compiler/context/tyvar.rs index be06169f..18dcae83 100644 --- a/compiler/erg_compiler/context/tyvar.rs +++ b/compiler/erg_compiler/context/tyvar.rs @@ -256,13 +256,14 @@ impl Context { let constraint = fv.crack_constraint(); let (sub_t, super_t) = constraint.get_sub_sup().unwrap(); if self.level <= fv.level().unwrap() { + // REVIEW: Even if type constraints can be satisfied, implementation may not exist if self.subtype_of(sub_t, super_t) { Ok(sub_t.clone()) } else { Err(TyCheckError::subtyping_error( line!() as usize, - sub_t, - super_t, + &self.resolve_tyvar(sub_t.clone(), loc)?, + &self.resolve_tyvar(super_t.clone(), loc)?, None, Some(loc), self.caused_by(), diff --git a/compiler/erg_compiler/error.rs b/compiler/erg_compiler/error.rs index d9dde557..29468e76 100644 --- a/compiler/erg_compiler/error.rs +++ b/compiler/erg_compiler/error.rs @@ -934,10 +934,10 @@ passed keyword args: {RED}{kw_args_len}{RESET}" TypeError, loc, switch_lang!( - "japanese" => format!("部分型制約を満たせません:\nサブタイプ: {YELLOW}{sub_t}{RESET}\nスーパータイプ: {YELLOW}{sup_t}{RESET}"), - "simplified_chinese" => format!("无法满足子类型约束:\n子类型:{YELLOW}{sub_t}{RESET}\n超类型:{YELLOW}{sup_t}{RESET}"), - "traditional_chinese" => format!("無法滿足子類型約束:\n子類型:{YELLOW}{sub_t}{RESET}\n超類型:{YELLOW}{sup_t}{RESET}"), - "english" => format!("subtype constraints cannot be satisfied:\nsubtype: {YELLOW}{sub_t}{RESET}\nsupertype: {YELLOW}{sup_t}{RESET}"), + "japanese" => format!("この式の部分型制約を満たせません:\nサブタイプ: {YELLOW}{sub_t}{RESET}\nスーパータイプ: {YELLOW}{sup_t}{RESET}"), + "simplified_chinese" => format!("无法满足此表达式中的子类型约束:\n子类型:{YELLOW}{sub_t}{RESET}\n超类型:{YELLOW}{sup_t}{RESET}"), + "traditional_chinese" => format!("無法滿足此表達式中的子類型約束:\n子類型:{YELLOW}{sub_t}{RESET}\n超類型:{YELLOW}{sup_t}{RESET}"), + "english" => format!("the subtype constraint in this expression cannot be satisfied:\nsubtype: {YELLOW}{sub_t}{RESET}\nsupertype: {YELLOW}{sup_t}{RESET}"), ), None, ),