circomspect_program_structure/static_single_assignment/
errors.rs1use crate::report_code::ReportCode;
2use crate::report::Report;
3use crate::file_definition::{FileID, FileLocation};
4
5#[derive(Debug)]
7pub enum SSAError {
8 UndefinedVariableError { name: String, file_id: Option<FileID>, location: FileLocation },
10}
11
12pub type SSAResult<T> = Result<T, SSAError>;
13
14impl SSAError {
15 pub fn into_report(&self) -> Report {
16 use SSAError::*;
17 match self {
18 UndefinedVariableError { name, file_id, location } => {
19 let mut report = Report::error(
20 format!("The variable `{name}` is used before it is defined."),
21 ReportCode::UninitializedSymbolInExpression,
22 );
23 if let Some(file_id) = file_id {
24 report.add_primary(
25 location.clone(),
26 *file_id,
27 format!("The variable `{name}` is first seen here."),
28 );
29 }
30 report
31 }
32 }
33 }
34}
35
36impl From<SSAError> for Report {
37 fn from(error: SSAError) -> Report {
38 error.into_report()
39 }
40}