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
VariableRedefinition
A variable with the same name is already defined in the current scope
Fields
SymbolRedefinition
A symbol (type, variable, function) is being redefined.
Fields
InvalidFieldType
A struct field is defined with an invalid type (e.g. unknown, unspecified)
Fields
TypeMismatch
The type of an expression does not match the expected type
Fields
OperationTypeMismatch
Incompatible types for an operation like arithmetic or comparison
Fields
LogicalOperatorTypeMismatch
Logical operators (AND, OR) used with non-boolean operands
Fields
ValueOutOfRange
Value is out of range for the target type (e.g., integer overflow)
Fields
ArgumentCountMismatch
Function call with wrong number of arguments
Fields
ArgumentTypeMismatch
Function call with wrong argument types
Fields
ReturnOutsideFunction
Return statement outside of a function
ReturnTypeMismatch
Return type does not match function declaration
Fields
MissingReturnValue
Missing return value for a function that requires one
Fields
UndefinedFunction
Undefined function in a function call
Fields
InvalidUnaryOperation
Unary operation applied to incompatible type
Fields
AssignmentToImmutableVariable
Assignment to an immutable variable
Fields
InvalidExpression
An expression has an unexpected form or context
Fields
VariableNotCallable
Attempt to call a variable that is not a function
Implementations§
Source§impl SemanticAnalysisError
impl SemanticAnalysisError
Sourcepub fn format_message(&self, context: &CompilationContext) -> String
pub fn format_message(&self, context: &CompilationContext) -> String
Convert the SemanticAnalysisError to a String representation that matches the existing error message formats.
Sourcefn get_location(&self) -> &Location
fn get_location(&self) -> &Location
Extracts the SourceLocation from any SemanticAnalysisError variant.
Sourcefn get_token_length(&self) -> Option<usize>
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.
Sourcepub fn to_compiler_error(&self, context: &CompilationContext) -> CompilerError
pub fn to_compiler_error(&self, context: &CompilationContext) -> CompilerError
Sourcepub fn error_code(&self) -> ErrorCode
pub fn error_code(&self) -> ErrorCode
Get the appropriate error code for this semantic error
Trait Implementations§
Source§impl Clone for SemanticAnalysisError
impl Clone for SemanticAnalysisError
Source§fn clone(&self) -> SemanticAnalysisError
fn clone(&self) -> SemanticAnalysisError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more