forked from M-Labs/nac3
1
0
Fork 0

core/type_inferencer: Include location info if inferencer fails

This commit is contained in:
David Mak 2024-04-05 13:22:35 +08:00
parent a920fe0501
commit 876ad6c59c
1 changed files with 9 additions and 2 deletions

View File

@ -4,7 +4,7 @@ use std::iter::once;
use std::{cell::RefCell, sync::Arc}; use std::{cell::RefCell, sync::Arc};
use super::typedef::{Call, FunSignature, FuncArg, RecordField, Type, TypeEnum, Unifier, VarMap}; 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::{ use crate::{
symbol_resolver::{SymbolResolver, SymbolValue}, symbol_resolver::{SymbolResolver, SymbolValue},
toplevel::{ toplevel::{
@ -628,7 +628,14 @@ impl<'a> Inferencer<'a> {
loc: Some(location), loc: Some(location),
}; };
if let Some(ret) = ret { 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 let required: Vec<_> = sign
.args .args