From 876ad6c59c1be89efa49d5f77a7fddbbf04c4c5f Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 5 Apr 2024 13:22:35 +0800 Subject: [PATCH] core/type_inferencer: Include location info if inferencer fails --- nac3core/src/typecheck/type_inferencer/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index 6921b92c2..e345aa80e 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -4,7 +4,7 @@ use std::iter::once; use std::{cell::RefCell, sync::Arc}; use super::typedef::{Call, FunSignature, FuncArg, RecordField, Type, TypeEnum, Unifier, VarMap}; -use super::{magic_methods::*, typedef::CallId}; +use super::{magic_methods::*, type_error::TypeError, typedef::CallId}; use crate::{ symbol_resolver::{SymbolResolver, SymbolValue}, toplevel::{ @@ -628,7 +628,14 @@ impl<'a> Inferencer<'a> { loc: Some(location), }; if let Some(ret) = ret { - self.unifier.unify(sign.ret, ret).unwrap(); + self.unifier.unify(sign.ret, ret) + .map_err(|err| { + format!("Cannot unify {} <: {} - {:?}", + self.unifier.stringify(sign.ret), + self.unifier.stringify(ret), + TypeError::new(err.kind, Some(location))) + }) + .unwrap(); } let required: Vec<_> = sign .args