Enum SemanticAnalysisError

Source
pub enum SemanticAnalysisError {
Show 18 variants UndefinedVariable { name: String, location: Location, }, VariableRedefinition { name: String, location: Location, }, SymbolRedefinition { name: String, kind: String, location: Location, }, InvalidFieldType { struct_name: String, field_name: String, type_id: TypeId, location: Location, }, TypeMismatch { expected: TypeId, actual: TypeId, context: Option<String>, location: Location, }, OperationTypeMismatch { operator: String, left_type: TypeId, right_type: TypeId, location: Location, }, LogicalOperatorTypeMismatch { operator: String, left_type: TypeId, right_type: TypeId, location: Location, }, ValueOutOfRange { value: String, target_type: TypeId, is_float: bool, location: Location, }, ArgumentCountMismatch { function_name: String, expected: usize, actual: usize, location: Location, }, ArgumentTypeMismatch { function_name: String, argument_position: usize, expected: TypeId, actual: TypeId, location: Location, }, ReturnOutsideFunction { location: Location, }, ReturnTypeMismatch { expected: TypeId, actual: TypeId, location: Location, }, MissingReturnValue { expected: TypeId, location: Location, }, UndefinedFunction { name: String, location: Location, }, InvalidUnaryOperation { operator: String, operand_type: TypeId, location: Location, }, AssignmentToImmutableVariable { name: String, location: Location, }, InvalidExpression { message: String, location: Location, }, VariableNotCallable { variable_name: String, variable_type: TypeId, location: Location, },
}
Expand description

Represents different categories of semantic analysis errors that occur during static analysis of the program.

Each variant contains the necessary context for generating appropriate error messages that maintain the existing format.

Variants§

§

UndefinedVariable

An attempt to use a variable that has not been defined in scope

Fields

§name: String

The name of the undefined variable

§location: Location

The location where the error occurred

§

VariableRedefinition

A variable with the same name is already defined in the current scope

Fields

§name: String

The name of the variable being redefined

§location: Location

The location where the redefinition occurred

§

SymbolRedefinition

A symbol (type, variable, function) is being redefined.

Fields

§name: String

The name of the symbol being redefined

§kind: String

The kind of the symbol (e.g., type, variable, function)

§location: Location

The location where the redefinition occurred

§

InvalidFieldType

A struct field is defined with an invalid type (e.g. unknown, unspecified)

Fields

§struct_name: String

The name of the struct containing the field

§field_name: String

The name of the field with the invalid type

§type_id: TypeId

The type ID of the invalid field type

§location: Location

The location where the invalid field type was defined

§

TypeMismatch

The type of an expression does not match the expected type

Fields

§expected: TypeId

The expected type

§actual: TypeId

The actual type found

§context: Option<String>

Optional context for the mismatch (like variable or function name)

§location: Location

The location where the type mismatch occurred

§

OperationTypeMismatch

Incompatible types for an operation like arithmetic or comparison

Fields

§operator: String

The operation being performed (e.g., +, -, *, /)

§left_type: TypeId

Left operand type

§right_type: TypeId

Right operand type

§location: Location

The location where the operation type mismatch occurred

§

LogicalOperatorTypeMismatch

Logical operators (AND, OR) used with non-boolean operands

Fields

§operator: String

The logical operator being used (AND, OR)

§left_type: TypeId

Left operand type

§right_type: TypeId

Right operand type

§location: Location

The location where the logical operator type mismatch occurred

§

ValueOutOfRange

Value is out of range for the target type (e.g., integer overflow)

Fields

§value: String

The value that can’t fit in the type

§target_type: TypeId

The target type

§is_float: bool

Whether the value is an integer or float

§location: Location

The location where the value out of range occurred

§

ArgumentCountMismatch

Function call with wrong number of arguments

Fields

§function_name: String

Function name

§expected: usize

Expected number of arguments

§actual: usize

Actual number of arguments provided

§location: Location

The location where the argument count mismatch occurred

§

ArgumentTypeMismatch

Function call with wrong argument types

Fields

§function_name: String

Function name

§argument_position: usize

Argument position (1-based)

§expected: TypeId

Expected type

§actual: TypeId

Actual type

§location: Location

The location where the argument type mismatch occurred

§

ReturnOutsideFunction

Return statement outside of a function

Fields

§location: Location

The source location where the return statement was found

§

ReturnTypeMismatch

Return type does not match function declaration

Fields

§expected: TypeId

Expected return type

§actual: TypeId

Actual returned type

§location: Location

The location where the return type mismatch occurred

§

MissingReturnValue

Missing return value for a function that requires one

Fields

§expected: TypeId

Expected return type

§location: Location

The location where the missing return value was found

§

UndefinedFunction

Undefined function in a function call

Fields

§name: String

The name of the undefined function

§location: Location

The location where the undefined function was called

§

InvalidUnaryOperation

Unary operation applied to incompatible type

Fields

§operator: String

The unary operator (e.g., -, !)

§operand_type: TypeId

The operand type

§location: Location

The location where the invalid unary operation occurred

§

AssignmentToImmutableVariable

Assignment to an immutable variable

Fields

§name: String

The name of the immutable variable

§location: Location

The location where the assignment attempt occurred

§

InvalidExpression

An expression has an unexpected form or context

Fields

§message: String

A description of what was expected vs what was found

§location: Location

The location where the invalid expression was found

§

VariableNotCallable

Attempt to call a variable that is not a function

Fields

§variable_name: String

The name of the variable being called

§variable_type: TypeId

The actual type of the variable

§location: Location

The location where the invalid call was attempted

Implementations§

Source§

impl SemanticAnalysisError

Source

pub fn format_message(&self, context: &CompilationContext) -> String

Convert the SemanticAnalysisError to a String representation that matches the existing error message formats.

Source

fn get_location(&self) -> &Location

Extracts the SourceLocation from any SemanticAnalysisError variant.

Source

fn get_token_length(&self) -> Option<usize>

Determines the token length for the error, using the length from SourceLocation. Falls back to heuristics only for cases where location information may not be available.

Source

pub fn to_compiler_error(&self, context: &CompilationContext) -> CompilerError

Convert a SemanticAnalysisError to a CompilerError that can be used by the rest of the compiler.

§Arguments
  • context - The CompilationContext providing type names and other context for error messages
§Returns

A CompilerError with the appropriate message and location information.

Source

pub fn error_code(&self) -> ErrorCode

Get the appropriate error code for this semantic error

Trait Implementations§

Source§

impl Clone for SemanticAnalysisError

Source§

fn clone(&self) -> SemanticAnalysisError

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SemanticAnalysisError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.