make file loading errors that happen late in compilation still fatal

This commit is contained in:
Brendan Hansknecht 2023-04-04 20:16:19 -07:00
parent 21d063da26
commit 8f4945f286
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
9 changed files with 189 additions and 114 deletions

View file

@ -1,3 +1,6 @@
use std::io;
use std::path::PathBuf;
use roc_collections::all::MutSet;
use roc_module::called_via::BinOp;
use roc_module::ident::{Ident, Lowercase, ModuleName, TagName};
@ -204,11 +207,15 @@ pub enum Problem {
OverAppliedCrash {
region: Region,
},
FileProblem {
filename: PathBuf,
error: io::ErrorKind,
},
}
impl Problem {
pub fn severity(&self) -> Severity {
use Severity::{RuntimeError, Warning};
use Severity::{Fatal, RuntimeError, Warning};
match self {
Problem::UnusedDef(_, _) => Warning,
@ -269,6 +276,7 @@ impl Problem {
Problem::UnappliedCrash { .. } => RuntimeError,
Problem::OverAppliedCrash { .. } => RuntimeError,
Problem::DefsOnlyUsedInRecursion(_, _) => Warning,
Problem::FileProblem { .. } => Fatal,
}
}
@ -414,6 +422,7 @@ impl Problem {
| Problem::RuntimeError(RuntimeError::VoidValue)
| Problem::RuntimeError(RuntimeError::ExposedButNotDefined(_))
| Problem::RuntimeError(RuntimeError::NoImplementationNamed { .. })
| Problem::FileProblem { .. }
| Problem::ExposedButNotDefined(_) => None,
}
}

View file

@ -6,6 +6,10 @@ pub mod can;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Severity {
/// This should stop compilation in all cases.
/// Due to delayed loading of ingested files, this is wanted behaviour over a runtime error.
Fatal,
/// This will cause a runtime error if some code get srun
/// (e.g. type mismatch, naming error)
RuntimeError,