changed the error

This commit is contained in:
mark 2023-06-04 20:17:36 +02:00
parent c7642ef911
commit efe8a177dc
2 changed files with 124 additions and 89 deletions

View File

@ -135,7 +135,7 @@ impl RStatement {
o o
} }
pub fn out(&self, info: &GlobalScriptInfo) -> VType { pub fn out(&self, info: &GlobalScriptInfo) -> VType {
// `a = b` evaluates to [] // `a = b` evaluates to [] (don't change this - cloning is cheap but a = b should NEVER return a boolean because that will make if a = b {} errors way too likely.)
if self.output_to.is_some() { if self.output_to.is_some() {
return VType { return VType {
types: vec![VSingleType::Tuple(vec![])], types: vec![VSingleType::Tuple(vec![])],

View File

@ -30,9 +30,7 @@ pub enum ToRunnableError {
UseOfUndefinedVariable(String), UseOfUndefinedVariable(String),
UseOfUndefinedFunction(String), UseOfUndefinedFunction(String),
UnknownType(String), UnknownType(String),
CannotDeclareVariableWithDereference(String),
CannotDereferenceTypeNTimes(VType, usize, VType), CannotDereferenceTypeNTimes(VType, usize, VType),
FunctionWrongArgCount(String, usize, usize),
FunctionWrongArgs(String, Vec<Arc<RFunction>>, Vec<VType>), FunctionWrongArgs(String, Vec<Arc<RFunction>>, Vec<VType>),
InvalidType { InvalidType {
expected: VType, expected: VType,
@ -74,10 +72,13 @@ impl FormatGs for ToRunnableError {
f, f,
"Main function had the wrong input. This is a bug and should never happen." "Main function had the wrong input. This is a bug and should never happen."
), ),
Self::UseOfUndefinedVariable(v) => write!(f, "Cannot use variable \"{v}\" as it isn't defined (yet?)."), Self::UseOfUndefinedVariable(v) => {
Self::UseOfUndefinedFunction(v) => write!(f, "Cannot use function \"{v}\" as it isn't defined (yet?)."), write!(f, "Cannot use variable \"{v}\" as it isn't defined (yet?).")
}
Self::UseOfUndefinedFunction(v) => {
write!(f, "Cannot use function \"{v}\" as it isn't defined (yet?).")
}
Self::UnknownType(name) => write!(f, "Unknown type \"{name}\"."), Self::UnknownType(name) => write!(f, "Unknown type \"{name}\"."),
Self::CannotDeclareVariableWithDereference(v) => write!(f, "Cannot declare a variable and dereference it (variable '{v}')."),
Self::CannotDereferenceTypeNTimes(og_type, derefs_wanted, last_valid_type) => { Self::CannotDereferenceTypeNTimes(og_type, derefs_wanted, last_valid_type) => {
write!(f, "Cannot dereference type ")?; write!(f, "Cannot dereference type ")?;
og_type.fmtgs(f, info, form, file)?; og_type.fmtgs(f, info, form, file)?;
@ -85,9 +86,29 @@ impl FormatGs for ToRunnableError {
last_valid_type.fmtgs(f, info, form, file); last_valid_type.fmtgs(f, info, form, file);
write!(f, ")")?; write!(f, ")")?;
Ok(()) Ok(())
}, }
Self::FunctionWrongArgCount(v, a, b) => write!(f, "Tried to call function \"{v}\", which takes {a} arguments, with {b} arguments instead."), Self::FunctionWrongArgs(fn_name, possible_fns, given_types) => {
Self::FunctionWrongArgs(fn_name, possible_fns, given_types) => write!(f, "Wrong args for function \"{fn_name}\": {} (possible fns: {})", given_types.iter().map(|v| format!(" {v}")).collect::<String>(), ""), write!(f, "Wrong args for function \"{fn_name}\": Found (");
for (i, t) in given_types.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
t.fmtgs(f, info, form, file)?;
}
write!(f, "), but valid are only ")?;
for (i, func) in possible_fns.iter().enumerate() {
if i != 0 {
if i + 1 == possible_fns.len() {
write!(f, ", and ")?;
} else {
write!(f, ", ")?;
}
}
VDataEnum::Function(Arc::clone(func)).fmtgs(f, info, form, file)?;
}
write!(f, ".")?;
Ok(())
}
Self::InvalidType { Self::InvalidType {
expected, expected,
found, found,
@ -103,7 +124,10 @@ impl FormatGs for ToRunnableError {
Ok(()) Ok(())
} }
Self::CaseForceButTypeNotCovered(v) => { Self::CaseForceButTypeNotCovered(v) => {
write!(f, "Switch! statement, but not all types covered. Types to cover: ")?; write!(
f,
"Switch! statement, but not all types covered. Types to cover: "
)?;
v.fmtgs(f, info, form, file)?; v.fmtgs(f, info, form, file)?;
Ok(()) Ok(())
} }
@ -120,7 +144,11 @@ impl FormatGs for ToRunnableError {
Ok(()) Ok(())
} }
Self::WrongInputsForBuiltinFunction(_builtin, builtin_name, args) => { Self::WrongInputsForBuiltinFunction(_builtin, builtin_name, args) => {
write!(f, "Wrong arguments for builtin function \"{}\":", builtin_name)?; write!(
f,
"Wrong arguments for builtin function \"{}\":",
builtin_name
)?;
for arg in args { for arg in args {
write!(f, " ")?; write!(f, " ")?;
arg.fmtgs(f, info, form, file)?; arg.fmtgs(f, info, form, file)?;
@ -142,16 +170,23 @@ impl FormatGs for ToRunnableError {
target.fmtgs(f, info, form, file)?; target.fmtgs(f, info, form, file)?;
write!(f, ".")?; write!(f, ".")?;
Ok(()) Ok(())
}, }
Self::ForLoopContainerHasNoInnerTypes => { Self::ForLoopContainerHasNoInnerTypes => {
write!(f, "For loop: container had no inner types, cannot iterate.") write!(f, "For loop: container had no inner types, cannot iterate.")
} }
Self::StatementRequiresOutputTypeToBeAButItActuallyOutputsBWhichDoesNotFitInA(required, real, problematic) => { Self::StatementRequiresOutputTypeToBeAButItActuallyOutputsBWhichDoesNotFitInA(
required,
real,
problematic,
) => {
write!(f, "the statement requires its output type to be ")?; write!(f, "the statement requires its output type to be ")?;
required.fmtgs(f, info, form, file)?; required.fmtgs(f, info, form, file)?;
write!(f, ", but its real output type is ")?; write!(f, ", but its real output type is ")?;
real.fmtgs(f, info, form, file)?; real.fmtgs(f, info, form, file)?;
write!(f, ", which doesn't fit in the required type because of the problematic types ")?; write!(
f,
", which doesn't fit in the required type because of the problematic types "
)?;
problematic.fmtgs(f, info, form, file)?; problematic.fmtgs(f, info, form, file)?;
write!(f, ".")?; write!(f, ".")?;
Ok(()) Ok(())