tinyscript 0.6.1

Tiny, C-like scripting language.
Documentation
// Copyright © 2025 Stephan Kunz
//! `tinyscript`s external errors, passes through the internal errors.

use thiserror::Error;

use crate::{ConstString, compilation::CompilationError, execution::ExecutionError};

/// Error cases of the runtime
#[derive(Error, Debug)]
pub enum Error {
	/// Passthrough compilation errors.
	#[error("compilation error: {0}")]
	Compilation(#[from] CompilationError),
	/// Passthrough execution errors.
	#[error("execution error: {0}")]
	Execution(#[from] ExecutionError),
	/// Tried to redefine an enum value.
	#[error("enum variant {name} already exists with value {old} new value: {new}")]
	DuplicateVariant {
		/// Name of the enum value.
		name: ConstString,
		/// Previously defined value.
		old: i8,
		/// Now defined value.
		new: i8,
	},
	/// Conversion failed.
	#[error("conversion of value {value} into {into} is not possible")]
	TryConversion {
		/// The faulty value.
		value: ConstString,
		/// the wanted conversion into.
		into: ConstString,
	},
}

#[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::<&Error>();
		is_normal::<Error>();
	}
}