forked from M-Labs/nac3
1
0
Fork 0

nac3core: fix #46, better toplevel return type error msg

This commit is contained in:
ychenfo 2021-10-03 18:01:36 +08:00
parent 24b2111c64
commit 4fcb54e463
1 changed files with 10 additions and 3 deletions

View File

@ -1615,14 +1615,21 @@ impl TopLevelComposer {
inferencer.check_block(fun_body.as_slice(), &mut identifiers)?; inferencer.check_block(fun_body.as_slice(), &mut identifiers)?;
if !self.unifier.unioned(inst_ret, self.primitives_ty.none) && !returned { 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( let ret_str = self.unifier.stringify(
inst_ret, 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), &mut |id| format!("tvar{}", id),
); );
return Err(format!( return Err(format!(
"expected return type of {} in function `{}`", "expected return type of `{}` in function `{}` at {}",
ret_str, name ret_str, name, ast.as_ref().unwrap().location
)); ));
} }