From 4fcb54e463f3c91f5a6600953b724b4badb5ce69 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sun, 3 Oct 2021 18:01:36 +0800 Subject: [PATCH] nac3core: fix #46, better toplevel return type error msg --- nac3core/src/toplevel/composer.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index c3197762e..9a9a20970 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -1615,14 +1615,21 @@ impl TopLevelComposer { inferencer.check_block(fun_body.as_slice(), &mut identifiers)?; if !self.unifier.unioned(inst_ret, self.primitives_ty.none) && !returned { + let def_ast_list = &self.definition_ast_list; let ret_str = self.unifier.stringify( inst_ret, - &mut |id| format!("class{}", id), + &mut |id| { + if let TopLevelDef::Class { name, .. } = &*def_ast_list[id].0.read() { + name.to_string() + } else { + unreachable!("must be class id here") + } + }, &mut |id| format!("tvar{}", id), ); return Err(format!( - "expected return type of {} in function `{}`", - ret_str, name + "expected return type of `{}` in function `{}` at {}", + ret_str, name, ast.as_ref().unwrap().location )); }