mirror of
https://github.com/Dummi26/mers.git
synced 2025-04-28 18:16:05 +02:00
changed the error
This commit is contained in:
parent
c7642ef911
commit
efe8a177dc
@ -135,7 +135,7 @@ impl RStatement {
|
||||
o
|
||||
}
|
||||
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() {
|
||||
return VType {
|
||||
types: vec![VSingleType::Tuple(vec![])],
|
||||
|
@ -30,9 +30,7 @@ pub enum ToRunnableError {
|
||||
UseOfUndefinedVariable(String),
|
||||
UseOfUndefinedFunction(String),
|
||||
UnknownType(String),
|
||||
CannotDeclareVariableWithDereference(String),
|
||||
CannotDereferenceTypeNTimes(VType, usize, VType),
|
||||
FunctionWrongArgCount(String, usize, usize),
|
||||
FunctionWrongArgs(String, Vec<Arc<RFunction>>, Vec<VType>),
|
||||
InvalidType {
|
||||
expected: VType,
|
||||
@ -74,10 +72,13 @@ impl FormatGs for ToRunnableError {
|
||||
f,
|
||||
"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::UseOfUndefinedFunction(v) => write!(f, "Cannot use function \"{v}\" as it isn't defined (yet?)."),
|
||||
Self::UseOfUndefinedVariable(v) => {
|
||||
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::CannotDeclareVariableWithDereference(v) => write!(f, "Cannot declare a variable and dereference it (variable '{v}')."),
|
||||
Self::CannotDereferenceTypeNTimes(og_type, derefs_wanted, last_valid_type) => {
|
||||
write!(f, "Cannot dereference type ")?;
|
||||
og_type.fmtgs(f, info, form, file)?;
|
||||
@ -85,9 +86,29 @@ impl FormatGs for ToRunnableError {
|
||||
last_valid_type.fmtgs(f, info, form, file);
|
||||
write!(f, ")")?;
|
||||
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) => write!(f, "Wrong args for function \"{fn_name}\": {} (possible fns: {})", given_types.iter().map(|v| format!(" {v}")).collect::<String>(), ""),
|
||||
}
|
||||
Self::FunctionWrongArgs(fn_name, possible_fns, given_types) => {
|
||||
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 {
|
||||
expected,
|
||||
found,
|
||||
@ -103,7 +124,10 @@ impl FormatGs for ToRunnableError {
|
||||
Ok(())
|
||||
}
|
||||
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)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -120,7 +144,11 @@ impl FormatGs for ToRunnableError {
|
||||
Ok(())
|
||||
}
|
||||
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 {
|
||||
write!(f, " ")?;
|
||||
arg.fmtgs(f, info, form, file)?;
|
||||
@ -142,16 +170,23 @@ impl FormatGs for ToRunnableError {
|
||||
target.fmtgs(f, info, form, file)?;
|
||||
write!(f, ".")?;
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
Self::ForLoopContainerHasNoInnerTypes => {
|
||||
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 ")?;
|
||||
required.fmtgs(f, info, form, file)?;
|
||||
write!(f, ", but its real output type is ")?;
|
||||
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)?;
|
||||
write!(f, ".")?;
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user