Add: Location moved to ErrorCore

This commit is contained in:
GreasySlug 2022-11-18 12:31:44 +09:00
parent 000124fea8
commit 4ae81aa05e
6 changed files with 80 additions and 6 deletions

View file

@ -501,6 +501,7 @@ pub struct ErrorCore {
pub main_message: AtomicStr, pub main_message: AtomicStr,
pub errno: usize, pub errno: usize,
pub kind: ErrorKind, pub kind: ErrorKind,
pub loc: Location,
theme: Theme, theme: Theme,
} }
@ -510,26 +511,25 @@ impl ErrorCore {
main_message: S, main_message: S,
errno: usize, errno: usize,
kind: ErrorKind, kind: ErrorKind,
loc: Location,
) -> Self { ) -> Self {
Self { Self {
sub_messages, sub_messages,
main_message: main_message.into(), main_message: main_message.into(),
errno, errno,
kind, kind,
loc,
theme: THEME, theme: THEME,
} }
} }
pub fn sub_messages(&self) -> &Vec<SubMessage> {
&self.sub_messages
}
pub fn dummy(errno: usize) -> Self { pub fn dummy(errno: usize) -> Self {
Self::new( Self::new(
vec![SubMessage::only_loc(Location::Line(errno as usize))], vec![SubMessage::only_loc(Location::Line(errno as usize))],
"<dummy>", "<dummy>",
errno, errno,
DummyError, DummyError,
Location::Line(errno as usize),
) )
} }
@ -555,6 +555,7 @@ impl ErrorCore {
&m_msg, &m_msg,
errno, errno,
CompilerSystemError, CompilerSystemError,
loc,
) )
} }

View file

@ -27,6 +27,7 @@ pub fn class_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<ValueOb
AtomicStr::from(format!("{REQ_ERR} is not passed")), AtomicStr::from(format!("{REQ_ERR} is not passed")),
line!() as usize, line!() as usize,
ErrorKind::TypeError, ErrorKind::TypeError,
Location::Unknown,
) )
})?; })?;
let Some(require) = require.as_type() else { let Some(require) = require.as_type() else {
@ -38,6 +39,7 @@ pub fn class_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<ValueOb
)), )),
line!() as usize, line!() as usize,
ErrorKind::TypeError, ErrorKind::TypeError,
Location::Unknown,
).into()); ).into());
}; };
let impls = args.remove_left_or_key("Impl"); let impls = args.remove_left_or_key("Impl");
@ -55,6 +57,7 @@ pub fn inherit_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<Value
AtomicStr::from(format!("{sup} is not passed")), AtomicStr::from(format!("{sup} is not passed")),
line!() as usize, line!() as usize,
ErrorKind::KeyError, ErrorKind::KeyError,
Location::Unknown,
) )
})?; })?;
let Some(sup) = sup.as_type() else { let Some(sup) = sup.as_type() else {
@ -66,6 +69,7 @@ pub fn inherit_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<Value
)), )),
line!() as usize, line!() as usize,
ErrorKind::TypeError, ErrorKind::TypeError,
Location::Unknown,
).into()); ).into());
}; };
let impls = args.remove_left_or_key("Impl"); let impls = args.remove_left_or_key("Impl");
@ -87,6 +91,7 @@ pub fn inheritable_func(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult<
AtomicStr::from(format!("{CLASS_ERR} is not passed")), AtomicStr::from(format!("{CLASS_ERR} is not passed")),
line!() as usize, line!() as usize,
ErrorKind::KeyError, ErrorKind::KeyError,
Location::Unknown,
) )
})?; })?;
match class { match class {
@ -118,6 +123,7 @@ pub fn trait_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<ValueOb
AtomicStr::from(format!("{REQ_ERR} is not passed")), AtomicStr::from(format!("{REQ_ERR} is not passed")),
line!() as usize, line!() as usize,
ErrorKind::KeyError, ErrorKind::KeyError,
Location::Unknown,
) )
})?; })?;
let Some(require) = require.as_type() else { let Some(require) = require.as_type() else {
@ -129,6 +135,7 @@ pub fn trait_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<ValueOb
)), )),
line!() as usize, line!() as usize,
ErrorKind::TypeError, ErrorKind::TypeError,
Location::Unknown,
).into()); ).into());
}; };
let impls = args.remove_left_or_key("Impl"); let impls = args.remove_left_or_key("Impl");
@ -145,6 +152,7 @@ pub fn subsume_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<Value
AtomicStr::from(format!("{SUP_ERR} is not passed")), AtomicStr::from(format!("{SUP_ERR} is not passed")),
line!() as usize, line!() as usize,
ErrorKind::KeyError, ErrorKind::KeyError,
Location::Unknown,
) )
})?; })?;
let Some(sup) = sup.as_type() else { let Some(sup) = sup.as_type() else {
@ -156,6 +164,7 @@ pub fn subsume_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<Value
)), )),
line!() as usize, line!() as usize,
ErrorKind::TypeError, ErrorKind::TypeError,
Location::Unknown,
).into()); ).into());
}; };
let impls = args.remove_left_or_key("Impl"); let impls = args.remove_left_or_key("Impl");
@ -186,6 +195,7 @@ pub fn __array_getitem__(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<
)), )),
line!() as usize, line!() as usize,
ErrorKind::IndexError, ErrorKind::IndexError,
Location::Unknown,
) )
.into()) .into())
} }
@ -219,6 +229,7 @@ pub fn __dict_getitem__(mut args: ValueArgs, ctx: &Context) -> EvalValueResult<V
AtomicStr::from(format!("{slf} has no key {index}",)), AtomicStr::from(format!("{slf} has no key {index}",)),
line!() as usize, line!() as usize,
ErrorKind::IndexError, ErrorKind::IndexError,
Location::Unknown,
) )
.into()) .into())
} }
@ -243,6 +254,7 @@ pub fn __range_getitem__(mut args: ValueArgs, _ctx: &Context) -> EvalValueResult
AtomicStr::from(format!("Index out of range: {}", index)), AtomicStr::from(format!("Index out of range: {}", index)),
line!() as usize, line!() as usize,
ErrorKind::IndexError, ErrorKind::IndexError,
Location::Unknown,
) )
.into()) .into())
} }

View file

@ -771,6 +771,7 @@ impl Context {
e.core.main_message, e.core.main_message,
e.core.errno, e.core.errno,
e.core.kind, e.core.kind,
e.core.loc,
); );
TyCheckError::new(core, self.cfg.input.clone(), e.caused_by) TyCheckError::new(core, self.cfg.input.clone(), e.caused_by)
}) })
@ -818,6 +819,7 @@ impl Context {
e.core.main_message, e.core.main_message,
e.core.errno, e.core.errno,
e.core.kind, e.core.kind,
e.core.loc,
); );
TyCheckError::new(core, self.cfg.input.clone(), e.caused_by) TyCheckError::new(core, self.cfg.input.clone(), e.caused_by)
}) })

View file

@ -177,6 +177,7 @@ impl CompileError {
), ),
errno, errno,
CompilerSystemError, CompilerSystemError,
loc,
), ),
input, input,
"".into(), "".into(),
@ -209,6 +210,7 @@ impl CompileError {
), ),
0, 0,
CompilerSystemError, CompilerSystemError,
loc,
), ),
input, input,
"".into(), "".into(),
@ -227,6 +229,7 @@ impl CompileError {
), ),
0, 0,
FeatureError, FeatureError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -245,6 +248,7 @@ impl CompileError {
), ),
0, 0,
SystemExit, SystemExit,
Location::Unknown,
), ),
Input::Dummy, Input::Dummy,
"".into(), "".into(),
@ -285,6 +289,7 @@ impl TyCheckError {
), ),
errno, errno,
CompilerSystemError, CompilerSystemError,
loc,
), ),
input, input,
"".into(), "".into(),
@ -310,6 +315,7 @@ impl TyCheckError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -339,6 +345,7 @@ impl TyCheckError {
), ),
errno, errno,
NotImplementedError, NotImplementedError,
callee.loc(),
), ),
input, input,
caused_by, caused_by,
@ -385,6 +392,7 @@ impl TyCheckError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -413,6 +421,7 @@ impl TyCheckError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -438,6 +447,7 @@ impl TyCheckError {
), ),
errno, errno,
NameError, NameError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -465,6 +475,7 @@ impl TyCheckError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -489,6 +500,7 @@ impl TyCheckError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -513,6 +525,7 @@ impl TyCheckError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -587,6 +600,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -619,6 +633,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -646,6 +661,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -673,6 +689,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -700,6 +717,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -727,6 +745,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -754,6 +773,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -780,6 +800,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
Location::Unknown,
), ),
input, input,
caused_by, caused_by,
@ -805,6 +826,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -831,6 +853,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -865,6 +888,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
MethodError, MethodError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -897,6 +921,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -925,6 +950,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
Location::Unknown,
), ),
input, input,
caused_by, caused_by,
@ -953,6 +979,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
Location::Unknown,
), ),
input, input,
caused_by, caused_by,
@ -978,6 +1005,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1010,6 +1038,7 @@ passed keyword args: {kw_args_len}"
), ),
errno, errno,
TypeError, TypeError,
expr.loc(),
), ),
input, input,
caused_by, caused_by,
@ -1041,6 +1070,7 @@ impl EvalError {
), ),
errno, errno,
NotConstExpr, NotConstExpr,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1064,6 +1094,7 @@ impl EvalError {
), ),
errno, errno,
SyntaxError, SyntaxError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1092,6 +1123,7 @@ impl EffectError {
), ),
errno, errno,
HasEffect, HasEffect,
expr.loc(),
), ),
input, input,
caused_by.into(), caused_by.into(),
@ -1124,6 +1156,7 @@ impl EffectError {
), ),
errno, errno,
HasEffect, HasEffect,
sig.loc(),
), ),
input, input,
caused_by.into(), caused_by.into(),
@ -1167,6 +1200,7 @@ impl OwnershipError {
), ),
errno, errno,
MoveError, MoveError,
name_loc,
), ),
input, input,
caused_by.into(), caused_by.into(),
@ -1196,6 +1230,7 @@ impl LowerError {
desc.into(), desc.into(),
errno, errno,
SyntaxError, SyntaxError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1221,6 +1256,7 @@ impl LowerError {
), ),
errno, errno,
NameError, NameError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1246,6 +1282,7 @@ impl LowerError {
), ),
errno, errno,
NameError, NameError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1275,6 +1312,7 @@ impl LowerError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1312,6 +1350,7 @@ impl LowerError {
), ),
errno, errno,
NameError, NameError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1344,6 +1383,7 @@ impl LowerError {
), ),
errno, errno,
NameError, NameError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1380,6 +1420,7 @@ impl LowerError {
), ),
errno, errno,
AttributeError, AttributeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1419,6 +1460,7 @@ impl LowerError {
), ),
errno, errno,
AttributeError, AttributeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1444,6 +1486,7 @@ impl LowerError {
), ),
errno, errno,
AssignError, AssignError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1469,6 +1512,7 @@ impl LowerError {
), ),
errno, errno,
UnusedWarning, UnusedWarning,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1492,6 +1536,7 @@ impl LowerError {
), ),
errno, errno,
NameError, NameError,
ident.loc(),
), ),
input, input,
caused_by, caused_by,
@ -1534,6 +1579,7 @@ impl LowerError {
), ),
errno, errno,
VisibilityError, VisibilityError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1580,6 +1626,7 @@ impl LowerError {
), ),
errno, errno,
NameError, NameError,
name_loc,
), ),
input, input,
caused_by.into(), caused_by.into(),
@ -1604,6 +1651,7 @@ impl LowerError {
), ),
errno, errno,
InheritanceError, InheritanceError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1619,7 +1667,7 @@ impl LowerError {
hint: Option<AtomicStr>, hint: Option<AtomicStr>,
) -> Self { ) -> Self {
Self::new( Self::new(
ErrorCore::new( vec![SubMessage::ambiguous_new(loc, None, hint)], desc, errno, IoError), ErrorCore::new( vec![SubMessage::ambiguous_new(loc, None, hint)], desc, errno, IoError, loc),
input, input,
caused_by, caused_by,
) )
@ -1689,6 +1737,7 @@ impl LowerError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1707,6 +1756,7 @@ impl LowerError {
), ),
errno, errno,
SyntaxError, SyntaxError,
loc,
), ),
input, input,
caused_by, caused_by,
@ -1740,6 +1790,7 @@ impl LowerError {
), ),
errno, errno,
TypeError, TypeError,
loc,
), ),
input, input,
caused_by, caused_by,

View file

@ -44,6 +44,7 @@ impl From<DeserializeError> for ErrorCore {
err.desc, err.desc,
err.errno, err.errno,
ErrorKind::ImportError, ErrorKind::ImportError,
Location::Unknown,
) )
} }
} }

View file

@ -30,6 +30,7 @@ pub struct LexErrors(Vec<LexError>);
impl_stream_for_wrapper!(LexErrors, LexError); impl_stream_for_wrapper!(LexErrors, LexError);
const ERR: Color = THEME.colors.error;
const HINT: Color = THEME.colors.hint; const HINT: Color = THEME.colors.hint;
const ACCENT: Color = THEME.colors.accent; const ACCENT: Color = THEME.colors.accent;
@ -60,6 +61,7 @@ impl LexError {
), ),
errno, errno,
CompilerSystemError, CompilerSystemError,
loc,
)) ))
} }
@ -74,6 +76,7 @@ impl LexError {
), ),
errno, errno,
FeatureError, FeatureError,
loc,
)) ))
} }
@ -88,6 +91,7 @@ impl LexError {
), ),
errno, errno,
SyntaxError, SyntaxError,
loc,
)) ))
} }
@ -102,6 +106,7 @@ impl LexError {
desc, desc,
errno, errno,
SyntaxError, SyntaxError,
loc,
)) ))
} }
@ -116,6 +121,7 @@ impl LexError {
desc, desc,
errno, errno,
SyntaxWarning, SyntaxWarning,
loc,
)) ))
} }
@ -135,7 +141,7 @@ impl LexError {
) )
.into() .into()
}); });
let name = StyledString::new(name, Some(Color::Red), Some(Attribute::Underline)); let name = StyledString::new(name, Some(ERR), Some(Attribute::Underline));
Self::new(ErrorCore::new( Self::new(ErrorCore::new(
vec![SubMessage::ambiguous_new(loc, None, hint)], vec![SubMessage::ambiguous_new(loc, None, hint)],
switch_lang!( switch_lang!(
@ -146,6 +152,7 @@ impl LexError {
), ),
errno, errno,
NameError, NameError,
loc,
)) ))
} }
} }