🐛️ Handle unimported modules properly

helpful error, not panic!

Closes #2422
This commit is contained in:
Emi Simpson 2022-02-24 20:37:16 -05:00
parent b5b26eabc9
commit 4d10c22442
No known key found for this signature in database
GPG key ID: A12F2C2FFDC3D847
7 changed files with 93 additions and 32 deletions

View file

@ -161,10 +161,37 @@ pub enum RuntimeError {
region: Region,
exposed_values: Vec<Lowercase>,
},
/// A module was referenced, but hasn't been imported anywhere in the program
///
/// An example would be:
/// ```roc
/// app "hello"
/// packages { pf: "platform" }
/// imports [ pf.Stdout]
/// provides [ main ] to pf
///
/// main : Task.Task {} [] // Task isn't imported!
/// main = Stdout.line "I'm a Roc application!"
/// ```
ModuleNotImported {
/// The name of the module that was referenced
module_name: ModuleName,
/// A list of modules which *have* been imported
imported_modules: MutSet<Box<str>>,
/// Where the problem occured
region: Region,
/// Whether or not the module exists at all
///
/// This is used to suggest that the user import the module, as opposed to fix a
/// typo in the spelling. For example, if the user typed `Task`, and the platform
/// exposes a `Task` module that hasn't been imported, we can sugguest that they
/// add the import statement.
///
/// On the other hand, if the user typed `Tesk`, they might want to check their
/// spelling.
///
/// If unsure, this should be set to `false`
module_exists: bool,
},
InvalidPrecedence(PrecedenceProblem, Region),
MalformedIdentifier(Box<str>, roc_parse::ident::BadIdent, Region),