From d0a3ab6bd8270fa72518f0234e06af299c619b2c Mon Sep 17 00:00:00 2001 From: ychenfo Date: Mon, 27 Dec 2021 04:52:04 +0800 Subject: [PATCH] nac3core: remove previously added redundant file name information in error message --- nac3core/src/toplevel/composer.rs | 28 +++++++++++----------------- nac3core/src/toplevel/test.rs | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 213c0ac7..fb748fe2 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -163,9 +163,8 @@ impl TopLevelComposer { ast::StmtKind::ClassDef { name: class_name, body, .. } => { if self.keyword_list.contains(class_name) { return Err(format!( - "cannot use keyword `{}` as a class name ({} at {})", + "cannot use keyword `{}` as a class name (at {})", class_name, - mod_path, ast.location )); } @@ -175,9 +174,8 @@ impl TopLevelComposer { n }) { return Err(format!( - "duplicate definition of class `{}` ({} at {})", + "duplicate definition of class `{}` (at {})", class_name, - mod_path, ast.location )); } @@ -223,9 +221,8 @@ impl TopLevelComposer { } if self.keyword_list.contains(method_name) { return Err(format!( - "cannot use keyword `{}` as a method name ({} at {})", + "cannot use keyword `{}` as a method name (at {})", method_name, - mod_path, b.location )); } @@ -242,9 +239,8 @@ impl TopLevelComposer { }; if !defined_names.insert(global_class_method_name.clone()) { return Err(format!( - "class method `{}` defined twice ({} at {})", + "class method `{}` defined twice (at {})", &global_class_method_name[mod_path.len()..], - mod_path, b.location )); } @@ -309,9 +305,8 @@ impl TopLevelComposer { }; if !defined_names.insert(global_fun_name.clone()) { return Err(format!( - "top level function `{}` defined twice ({} at {})", + "top level function `{}` defined twice (at {})", &global_fun_name[mod_path.len()..], - mod_path, ast.location )); } @@ -340,8 +335,7 @@ impl TopLevelComposer { } _ => Err(format!( - "registrations of constructs other than top level classes/functions are not supported ({} at {})", - mod_path, + "registrations of constructs other than top level classes/functions are not supported (at {})", ast.location )), } @@ -794,7 +788,7 @@ impl TopLevelComposer { &type_annotation, primitives_store, unifier - ).map_err(|err| format!("{} at {}", err, x.location))?; + ).map_err(|err| format!("{} (at {})", err, x.location))?; v }) } @@ -865,7 +859,7 @@ impl TopLevelComposer { )); unifier .unify(*dummy_ty, function_ty) - .map_err(|old| format!("{} at {}", old, function_ast.location))?; + .map_err(|old| format!("{} (at {})", old, function_ast.location))?; } else { unreachable!("must be both function"); } @@ -1028,7 +1022,7 @@ impl TopLevelComposer { Some({ let v = Self::parse_parameter_default_value(default, class_resolver)?; Self::check_default_param_type(&v, &type_ann, primitives, unifier) - .map_err(|err| format!("{} at {}", err, x.location))?; + .map_err(|err| format!("{} (at {})", err, x.location))?; v }) } @@ -1351,7 +1345,7 @@ impl TopLevelComposer { )); self.unifier .unify(constructor.unwrap(), contor_type) - .map_err(|old| format!("{} at {}", old, ast.as_ref().unwrap().location))?; + .map_err(|old| format!("{} (at {})", old, ast.as_ref().unwrap().location))?; // class field instantiation check if let (Some(init_id), false) = (init_id, fields.is_empty()) { @@ -1568,7 +1562,7 @@ impl TopLevelComposer { &mut |id| format!("tvar{}", id), ); return Err(format!( - "expected return type of `{}` in function `{}` at {}", + "expected return type of `{}` in function `{}` (at {})", ret_str, name, ast.as_ref().unwrap().location diff --git a/nac3core/src/toplevel/test.rs b/nac3core/src/toplevel/test.rs index f888fa0d..97d1a9c3 100644 --- a/nac3core/src/toplevel/test.rs +++ b/nac3core/src/toplevel/test.rs @@ -479,7 +479,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s pass "} ], - vec!["duplicate definition of class `A` ( at unknown:1:1)"]; + vec!["duplicate definition of class `A` (at unknown:1:1)"]; "class same name" )] fn test_analyze(source: Vec<&str>, res: Vec<&str>) {