Merge pull request #232 from erg-lang/split-err-msg

Split error messages
This commit is contained in:
Shunsuke Shibayama 2022-11-23 15:55:19 +09:00 committed by GitHub
commit 2caa6b6ec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 1652 additions and 1006 deletions

View file

@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use erg_common::config::Input;
use erg_common::env::erg_pystd_path;
use erg_common::error::{ErrorCore, ErrorKind, Location};
use erg_common::error::{ErrorCore, ErrorKind, Location, SubMessage};
use erg_common::levenshtein::get_similar_name;
use erg_common::set::Set;
use erg_common::traits::{Locational, Stream};
@ -756,13 +756,21 @@ impl Context {
TyCheckErrors::new(
errs.into_iter()
.map(|e| {
// HACK: dname.loc()はダミーLocationしか返さないので、エラーならop.loc()で上書きする
let mut sub_msges = Vec::new();
for sub_msg in e.core.sub_messages {
sub_msges.push(SubMessage::ambiguous_new(
// HACK: dname.loc()はダミーLocationしか返さないので、エラーならop.loc()で上書きする
bin.loc(),
vec![],
sub_msg.get_hint(),
));
}
let core = ErrorCore::new(
sub_msges,
e.core.main_message,
e.core.errno,
e.core.kind,
bin.loc(),
e.core.desc,
e.core.hint,
e.core.loc,
);
TyCheckError::new(core, self.cfg.input.clone(), e.caused_by)
})
@ -797,12 +805,20 @@ impl Context {
TyCheckErrors::new(
errs.into_iter()
.map(|e| {
let mut sub_msges = Vec::new();
for sub_msg in e.core.sub_messages {
sub_msges.push(SubMessage::ambiguous_new(
unary.loc(),
vec![],
sub_msg.get_hint(),
));
}
let core = ErrorCore::new(
sub_msges,
e.core.main_message,
e.core.errno,
e.core.kind,
unary.loc(),
e.core.desc,
e.core.hint,
e.core.loc,
);
TyCheckError::new(core, self.cfg.input.clone(), e.caused_by)
})
@ -1052,7 +1068,8 @@ impl Context {
TyCheckError::type_mismatch_error(
self.cfg.input.clone(),
line!() as usize,
e.core.loc,
// TODO: Is it possible to get 0?
e.core.sub_messages.get(0).unwrap().loc,
e.caused_by,
&name[..],
Some(nth),
@ -1107,7 +1124,8 @@ impl Context {
TyCheckError::type_mismatch_error(
self.cfg.input.clone(),
line!() as usize,
e.core.loc,
// TODO: Is it possible to get 0?
e.core.sub_messages.get(0).unwrap().loc,
e.caused_by,
&name[..],
Some(nth),
@ -1164,7 +1182,8 @@ impl Context {
TyCheckError::type_mismatch_error(
self.cfg.input.clone(),
line!() as usize,
e.core.loc,
// TODO: Is it possible to get 0?
e.core.sub_messages.get(0).unwrap().loc,
e.caused_by,
&name[..],
Some(nth),