From d3cb5d6e52aa7f06acfaab9b28d5a6081c91bbc4 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 22 Feb 2022 17:20:11 +0800 Subject: [PATCH] Fixed type error messages --- nac3artiq/src/lib.rs | 2 +- nac3core/src/typecheck/type_error.rs | 2 +- nac3core/src/typecheck/type_inferencer/mod.rs | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index d13fc9634..6fbce6eb7 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -371,7 +371,7 @@ impl Nac3 { .extract() .unwrap(), exception: id_fn - .call1((builtins_mod.getattr("tuple").unwrap(),)) + .call1((builtins_mod.getattr("Exception").unwrap(),)) .unwrap() .extract() .unwrap(), diff --git a/nac3core/src/typecheck/type_error.rs b/nac3core/src/typecheck/type_error.rs index bf963967b..a12098934 100644 --- a/nac3core/src/typecheck/type_error.rs +++ b/nac3core/src/typecheck/type_error.rs @@ -155,7 +155,7 @@ impl<'a> Display for DisplayTypeError<'a> { } NoSuchField(name, t) => { let t = self.unifier.stringify_with_notes(*t, &mut notes); - write!(f, "`{}::{}` field does not exist", t, name) + write!(f, "`{}::{}` field/method does not exist", t, name) } TupleIndexOutOfBounds { index, len } => { write!( diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index 4abcb9d03..4a737761c 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -925,7 +925,10 @@ impl<'a> Inferencer<'a> { (Some((_, false)), true) => { report_error(&format!("Field {} should be immutable", attr), value.location) } - (None, _) => report_error(&format!("No such field {}", attr), value.location), + (None, _) => { + let t = self.unifier.stringify(ty); + report_error(&format!("`{}::{}` field/method does not exist", t, attr), value.location) + }, } } else { let attr_ty = self.unifier.get_dummy_var().0;