mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-14 03:16:15 +01:00
improve/fix errors in #include
This commit is contained in:
@@ -24,6 +24,7 @@ impl MersStatement for Chain {
|
||||
pos_in_src: self.pos_in_src,
|
||||
first: self.first.compile(info, comp)?,
|
||||
chained: self.chained.compile(info, comp)?,
|
||||
as_part_of_include: None,
|
||||
}))
|
||||
}
|
||||
fn source_range(&self) -> SourceRange {
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::{
|
||||
data::{self, Data},
|
||||
errors::{error_colors, CheckError, SourceRange},
|
||||
info::{self, Local},
|
||||
parsing::Source,
|
||||
program::{self},
|
||||
};
|
||||
|
||||
@@ -15,6 +16,7 @@ use super::{CompInfo, MersStatement};
|
||||
pub struct IncludeMers {
|
||||
pub pos_in_src: SourceRange,
|
||||
pub include: Box<dyn MersStatement>,
|
||||
pub inner_src: Source,
|
||||
}
|
||||
impl MersStatement for IncludeMers {
|
||||
fn has_scope(&self) -> bool {
|
||||
@@ -25,15 +27,23 @@ impl MersStatement for IncludeMers {
|
||||
info: &mut info::Info<super::Local>,
|
||||
comp: CompInfo,
|
||||
) -> Result<Box<dyn program::run::MersStatement>, CheckError> {
|
||||
let compiled: Arc<Box<dyn crate::program::run::MersStatement>> = match self.include.compile(info, comp) {
|
||||
Ok(v) => Arc::new(v),
|
||||
Err(e) => {
|
||||
return Err(CheckError::new()
|
||||
.src(vec![(self.pos_in_src, Some(error_colors::HashIncludeErrorInIncludedFile))])
|
||||
.msg("Error in inner mers statement! (note: inner errors may refer to a different file)".color(error_colors::HashIncludeErrorInIncludedFile).to_string())
|
||||
.err(e))
|
||||
}
|
||||
};
|
||||
let compiled: Arc<Box<dyn crate::program::run::MersStatement>> =
|
||||
match self.include.compile(info, comp) {
|
||||
Ok(v) => Arc::new(v),
|
||||
Err(e) => {
|
||||
return Err(CheckError::new()
|
||||
.src(vec![(
|
||||
self.pos_in_src,
|
||||
Some(error_colors::HashIncludeErrorInIncludedFile),
|
||||
)])
|
||||
.msg(
|
||||
"Error in #include! (note: inner errors may refer to a different file)"
|
||||
.color(error_colors::HashIncludeErrorInIncludedFile)
|
||||
.to_string(),
|
||||
)
|
||||
.err_with_src(e, self.inner_src.clone()))
|
||||
}
|
||||
};
|
||||
let compiled2 = Arc::clone(&compiled);
|
||||
Ok(Box::new(program::run::chain::Chain {
|
||||
pos_in_src: self.pos_in_src,
|
||||
@@ -50,6 +60,7 @@ impl MersStatement for IncludeMers {
|
||||
run: Arc::new(move |_, i| compiled2.run(&mut i.duplicate())),
|
||||
},
|
||||
}),
|
||||
as_part_of_include: Some(self.inner_src.clone()),
|
||||
}))
|
||||
}
|
||||
fn source_range(&self) -> SourceRange {
|
||||
|
||||
@@ -31,8 +31,8 @@ impl MersStatement for AssignTo {
|
||||
return Err(CheckError::new()
|
||||
.src(vec![
|
||||
(self.pos_in_src, None),
|
||||
(self.target.source_range(), Some(error_colors::InitFrom)),
|
||||
(self.source.source_range(), Some(error_colors::InitTo)),
|
||||
(self.target.source_range(), Some(error_colors::InitTo)),
|
||||
(self.source.source_range(), Some(error_colors::InitFrom)),
|
||||
])
|
||||
.msg(format!("Cannot initialize:"))
|
||||
.err(e))
|
||||
|
||||
@@ -5,6 +5,7 @@ use colored::Colorize;
|
||||
use crate::{
|
||||
data::{Data, Type},
|
||||
errors::{error_colors, CheckError, SourceRange},
|
||||
parsing::Source,
|
||||
};
|
||||
|
||||
use super::MersStatement;
|
||||
@@ -14,6 +15,7 @@ pub struct Chain {
|
||||
pub pos_in_src: SourceRange,
|
||||
pub first: Box<dyn MersStatement>,
|
||||
pub chained: Box<dyn MersStatement>,
|
||||
pub as_part_of_include: Option<Source>,
|
||||
}
|
||||
impl MersStatement for Chain {
|
||||
fn check_custom(
|
||||
@@ -35,21 +37,35 @@ impl MersStatement for Chain {
|
||||
match (func.0)(&arg) {
|
||||
Ok(t) => o.add(Arc::new(t)),
|
||||
Err(e) => {
|
||||
return Err(CheckError::new()
|
||||
.src(vec![
|
||||
(self.pos_in_src, None),
|
||||
(
|
||||
self.first.source_range(),
|
||||
Some(error_colors::FunctionArgument),
|
||||
),
|
||||
(self.chained.source_range(), Some(error_colors::Function)),
|
||||
])
|
||||
.msg(format!(
|
||||
"Can't call {} with an argument of type {}:",
|
||||
"this function".color(error_colors::Function),
|
||||
arg.to_string().color(error_colors::FunctionArgument)
|
||||
))
|
||||
.err(e))
|
||||
return Err(if let Some(inner_src) = &self.as_part_of_include {
|
||||
CheckError::new()
|
||||
.src(vec![(
|
||||
self.pos_in_src,
|
||||
Some(error_colors::HashIncludeErrorInIncludedFile),
|
||||
)])
|
||||
.msg(
|
||||
"Error in #include:"
|
||||
.color(error_colors::HashIncludeErrorInIncludedFile)
|
||||
.to_string(),
|
||||
)
|
||||
.err_with_src(e, inner_src.clone())
|
||||
} else {
|
||||
CheckError::new()
|
||||
.src(vec![
|
||||
(self.pos_in_src, None),
|
||||
(
|
||||
self.first.source_range(),
|
||||
Some(error_colors::FunctionArgument),
|
||||
),
|
||||
(self.chained.source_range(), Some(error_colors::Function)),
|
||||
])
|
||||
.msg(format!(
|
||||
"Can't call {} with an argument of type {}:",
|
||||
"this function".color(error_colors::Function),
|
||||
arg.to_string().color(error_colors::FunctionArgument)
|
||||
))
|
||||
.err(e)
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -45,7 +45,20 @@ impl MersStatement for Tuple {
|
||||
).into());
|
||||
}
|
||||
} else {
|
||||
return Err(format!("can't init a {} with a value of type {}, which is part of {} - only tuples can be assigned to tuples", "tuple".color(error_colors::InitTo), t.to_string().color(error_colors::InitFrom), init_to.to_string().color(error_colors::InitFrom)).into());
|
||||
return Err(format!(
|
||||
"can't init a {} with type {}{} - only tuples can be assigned to tuples",
|
||||
"tuple".color(error_colors::InitTo),
|
||||
t.to_string().color(error_colors::InitFrom),
|
||||
if print_is_part_of {
|
||||
format!(
|
||||
", which is part of {}",
|
||||
init_to.to_string().color(error_colors::InitFrom)
|
||||
)
|
||||
} else {
|
||||
format!("")
|
||||
}
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
Some(vec)
|
||||
|
||||
Reference in New Issue
Block a user