tinyscript 0.6.1

Tiny, C-like scripting language.
Documentation
// Copyright © 2025 Stephan Kunz
//! Execution errors, only internaly used.

use thiserror::Error;

use crate::ConstString;

/// Things that may go wrong during execution of a compiled script.
#[derive(Error, Debug)]
pub enum ExecutionError {
	/// No arithemetic with boolean for now.
	#[error("boolean values do not allow arithmetic operations")]
	BoolNoArithmetic,
	/// Passthrough environment errors.
	#[error("environment error: {0}")]
	Environment(#[from] crate::environment::Error),
	/// Nil does not allow anything.
	#[error("value is 'Nil' which does not allow any operation")]
	NilValue,
	/// Expected Boolean, got something else.
	#[error("expected boolean ('true'/'false'), got {value}")]
	NoBoolean {
		/// The faulty value.
		value: ConstString,
	},
	/// Comparisons (greater, less) only with numeric values.
	#[error("comparing values needs two numeric types")]
	NoComparison,
	/// Expected Integer, got something else.
	#[error("expected integer value, got {value}")]
	NoInteger {
		/// The faulty value.
		value: ConstString,
	},
	/// Expected a numerical value, got something else.
	#[error("expected numerical value, got {value}")]
	NoNumber {
		/// The faulty value.
		value: ConstString,
	},
	/// Stack overflow.
	#[error("stack overflow, to many variables/values")]
	StackOverflow,
	/// Strings only allow additions.
	#[error("to Strings you can only 'ADD' something")]
	OnlyAdd,

	/// This code line never should have been reached.
	#[error("{file} at line {line} should be unreachable")]
	Unreachable {
		/// The faulty file.
		file: ConstString,
		/// The faulty line.
		line: u32,
	},
}
#[cfg(test)]
mod tests {
	use super::*;

	// check, that the auto traits are available
	const fn is_normal<T: Sized + Send + Sync>() {}

	#[test]
	const fn normal_types() {
		is_normal::<&ExecutionError>();
		is_normal::<ExecutionError>();
	}
}