diff --git a/compiler/erg_common/error.rs b/compiler/erg_common/error.rs index ee0aa033..9946385f 100644 --- a/compiler/erg_common/error.rs +++ b/compiler/erg_common/error.rs @@ -501,6 +501,7 @@ pub struct ErrorCore { pub main_message: AtomicStr, pub errno: usize, pub kind: ErrorKind, + pub loc: Location, theme: Theme, } @@ -510,26 +511,25 @@ impl ErrorCore { main_message: S, errno: usize, kind: ErrorKind, + loc: Location, ) -> Self { Self { sub_messages, main_message: main_message.into(), errno, kind, + loc, theme: THEME, } } - pub fn sub_messages(&self) -> &Vec { - &self.sub_messages - } - pub fn dummy(errno: usize) -> Self { Self::new( vec![SubMessage::only_loc(Location::Line(errno as usize))], "", errno, DummyError, + Location::Line(errno as usize), ) } @@ -555,6 +555,7 @@ impl ErrorCore { &m_msg, errno, CompilerSystemError, + loc, ) } diff --git a/compiler/erg_compiler/context/initialize/const_func.rs b/compiler/erg_compiler/context/initialize/const_func.rs index b0eb198a..cd814e20 100644 --- a/compiler/erg_compiler/context/initialize/const_func.rs +++ b/compiler/erg_compiler/context/initialize/const_func.rs @@ -27,6 +27,7 @@ pub fn class_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult EvalValueResult EvalValueResult EvalValueResult EvalValueResult< AtomicStr::from(format!("{CLASS_ERR} is not passed")), line!() as usize, ErrorKind::KeyError, + Location::Unknown, ) })?; match class { @@ -118,6 +123,7 @@ pub fn trait_func(mut args: ValueArgs, ctx: &Context) -> EvalValueResult EvalValueResult EvalValueResult EvalValueResult EvalValueResult< )), line!() as usize, ErrorKind::IndexError, + Location::Unknown, ) .into()) } @@ -219,6 +229,7 @@ pub fn __dict_getitem__(mut args: ValueArgs, ctx: &Context) -> EvalValueResult EvalValueResult AtomicStr::from(format!("Index out of range: {}", index)), line!() as usize, ErrorKind::IndexError, + Location::Unknown, ) .into()) } diff --git a/compiler/erg_compiler/context/inquire.rs b/compiler/erg_compiler/context/inquire.rs index 4d5b24ed..eb998803 100644 --- a/compiler/erg_compiler/context/inquire.rs +++ b/compiler/erg_compiler/context/inquire.rs @@ -771,6 +771,7 @@ impl Context { e.core.main_message, e.core.errno, e.core.kind, + e.core.loc, ); TyCheckError::new(core, self.cfg.input.clone(), e.caused_by) }) @@ -818,6 +819,7 @@ impl Context { e.core.main_message, e.core.errno, e.core.kind, + e.core.loc, ); TyCheckError::new(core, self.cfg.input.clone(), e.caused_by) }) diff --git a/compiler/erg_compiler/error.rs b/compiler/erg_compiler/error.rs index bba20121..1b45e30e 100644 --- a/compiler/erg_compiler/error.rs +++ b/compiler/erg_compiler/error.rs @@ -177,6 +177,7 @@ impl CompileError { ), errno, CompilerSystemError, + loc, ), input, "".into(), @@ -209,6 +210,7 @@ impl CompileError { ), 0, CompilerSystemError, + loc, ), input, "".into(), @@ -227,6 +229,7 @@ impl CompileError { ), 0, FeatureError, + loc, ), input, caused_by, @@ -245,6 +248,7 @@ impl CompileError { ), 0, SystemExit, + Location::Unknown, ), Input::Dummy, "".into(), @@ -285,6 +289,7 @@ impl TyCheckError { ), errno, CompilerSystemError, + loc, ), input, "".into(), @@ -310,6 +315,7 @@ impl TyCheckError { ), errno, TypeError, + loc, ), input, caused_by, @@ -339,6 +345,7 @@ impl TyCheckError { ), errno, NotImplementedError, + callee.loc(), ), input, caused_by, @@ -385,6 +392,7 @@ impl TyCheckError { ), errno, TypeError, + loc, ), input, caused_by, @@ -413,6 +421,7 @@ impl TyCheckError { ), errno, TypeError, + loc, ), input, caused_by, @@ -438,6 +447,7 @@ impl TyCheckError { ), errno, NameError, + loc, ), input, caused_by, @@ -465,6 +475,7 @@ impl TyCheckError { ), errno, TypeError, + loc, ), input, caused_by, @@ -489,6 +500,7 @@ impl TyCheckError { ), errno, TypeError, + loc, ), input, caused_by, @@ -513,6 +525,7 @@ impl TyCheckError { ), errno, TypeError, + loc, ), input, caused_by, @@ -587,6 +600,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -619,6 +633,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -646,6 +661,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -673,6 +689,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -700,6 +717,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -727,6 +745,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -754,6 +773,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -780,6 +800,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + Location::Unknown, ), input, caused_by, @@ -805,6 +826,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -831,6 +853,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -865,6 +888,7 @@ passed keyword args: {kw_args_len}" ), errno, MethodError, + loc, ), input, caused_by, @@ -897,6 +921,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -925,6 +950,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + Location::Unknown, ), input, caused_by, @@ -953,6 +979,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + Location::Unknown, ), input, caused_by, @@ -978,6 +1005,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + loc, ), input, caused_by, @@ -1010,6 +1038,7 @@ passed keyword args: {kw_args_len}" ), errno, TypeError, + expr.loc(), ), input, caused_by, @@ -1041,6 +1070,7 @@ impl EvalError { ), errno, NotConstExpr, + loc, ), input, caused_by, @@ -1064,6 +1094,7 @@ impl EvalError { ), errno, SyntaxError, + loc, ), input, caused_by, @@ -1092,6 +1123,7 @@ impl EffectError { ), errno, HasEffect, + expr.loc(), ), input, caused_by.into(), @@ -1124,6 +1156,7 @@ impl EffectError { ), errno, HasEffect, + sig.loc(), ), input, caused_by.into(), @@ -1167,6 +1200,7 @@ impl OwnershipError { ), errno, MoveError, + name_loc, ), input, caused_by.into(), @@ -1196,6 +1230,7 @@ impl LowerError { desc.into(), errno, SyntaxError, + loc, ), input, caused_by, @@ -1221,6 +1256,7 @@ impl LowerError { ), errno, NameError, + loc, ), input, caused_by, @@ -1246,6 +1282,7 @@ impl LowerError { ), errno, NameError, + loc, ), input, caused_by, @@ -1275,6 +1312,7 @@ impl LowerError { ), errno, TypeError, + loc, ), input, caused_by, @@ -1312,6 +1350,7 @@ impl LowerError { ), errno, NameError, + loc, ), input, caused_by, @@ -1344,6 +1383,7 @@ impl LowerError { ), errno, NameError, + loc, ), input, caused_by, @@ -1380,6 +1420,7 @@ impl LowerError { ), errno, AttributeError, + loc, ), input, caused_by, @@ -1419,6 +1460,7 @@ impl LowerError { ), errno, AttributeError, + loc, ), input, caused_by, @@ -1444,6 +1486,7 @@ impl LowerError { ), errno, AssignError, + loc, ), input, caused_by, @@ -1469,6 +1512,7 @@ impl LowerError { ), errno, UnusedWarning, + loc, ), input, caused_by, @@ -1492,6 +1536,7 @@ impl LowerError { ), errno, NameError, + ident.loc(), ), input, caused_by, @@ -1534,6 +1579,7 @@ impl LowerError { ), errno, VisibilityError, + loc, ), input, caused_by, @@ -1580,6 +1626,7 @@ impl LowerError { ), errno, NameError, + name_loc, ), input, caused_by.into(), @@ -1604,6 +1651,7 @@ impl LowerError { ), errno, InheritanceError, + loc, ), input, caused_by, @@ -1619,7 +1667,7 @@ impl LowerError { hint: Option, ) -> Self { 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, caused_by, ) @@ -1689,6 +1737,7 @@ impl LowerError { ), errno, TypeError, + loc, ), input, caused_by, @@ -1707,6 +1756,7 @@ impl LowerError { ), errno, SyntaxError, + loc, ), input, caused_by, @@ -1740,6 +1790,7 @@ impl LowerError { ), errno, TypeError, + loc, ), input, caused_by, diff --git a/compiler/erg_compiler/ty/deserialize.rs b/compiler/erg_compiler/ty/deserialize.rs index 679a7bff..7820205a 100644 --- a/compiler/erg_compiler/ty/deserialize.rs +++ b/compiler/erg_compiler/ty/deserialize.rs @@ -44,6 +44,7 @@ impl From for ErrorCore { err.desc, err.errno, ErrorKind::ImportError, + Location::Unknown, ) } } diff --git a/compiler/erg_parser/error.rs b/compiler/erg_parser/error.rs index 42048d50..75810f79 100644 --- a/compiler/erg_parser/error.rs +++ b/compiler/erg_parser/error.rs @@ -30,6 +30,7 @@ pub struct LexErrors(Vec); impl_stream_for_wrapper!(LexErrors, LexError); +const ERR: Color = THEME.colors.error; const HINT: Color = THEME.colors.hint; const ACCENT: Color = THEME.colors.accent; @@ -60,6 +61,7 @@ impl LexError { ), errno, CompilerSystemError, + loc, )) } @@ -74,6 +76,7 @@ impl LexError { ), errno, FeatureError, + loc, )) } @@ -88,6 +91,7 @@ impl LexError { ), errno, SyntaxError, + loc, )) } @@ -102,6 +106,7 @@ impl LexError { desc, errno, SyntaxError, + loc, )) } @@ -116,6 +121,7 @@ impl LexError { desc, errno, SyntaxWarning, + loc, )) } @@ -135,7 +141,7 @@ impl LexError { ) .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( vec![SubMessage::ambiguous_new(loc, None, hint)], switch_lang!( @@ -146,6 +152,7 @@ impl LexError { ), errno, NameError, + loc, )) } }