Implement import aliases

Allows a module to be imported with an alias:

    import JsonDecode as JD

Import aliases must be unique and they cannot have the same name
as an imported module.
This commit is contained in:
Agus Zubiaga 2024-03-29 17:35:24 -03:00
parent d5a38a26db
commit 842a256907
No known key found for this signature in database
6 changed files with 443 additions and 61 deletions

View file

@ -40,6 +40,12 @@ pub enum Problem {
UnusedModuleImport(ModuleId, Region),
ExposedButNotDefined(Symbol),
UnknownGeneratesWith(Loc<Ident>),
ImportAliasConflict {
alias: String,
conflict: ImportAliasConflict,
module_id: ModuleId,
region: Region,
},
/// First symbol is the name of the closure with that argument
/// Bool is whether the closure is anonymous
/// Second symbol is the name of the argument that is unused
@ -213,6 +219,13 @@ pub enum Problem {
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ImportAliasConflict {
Alias(ModuleId, Region),
Module(Region),
Builtin,
}
impl Problem {
pub fn severity(&self) -> Severity {
use Severity::{Fatal, RuntimeError, Warning};
@ -221,6 +234,7 @@ impl Problem {
Problem::UnusedDef(_, _) => Warning,
Problem::UnusedImport(_, _) => Warning,
Problem::UnusedModuleImport(_, _) => Warning,
Problem::ImportAliasConflict { .. } => RuntimeError,
Problem::ExposedButNotDefined(_) => RuntimeError,
Problem::UnknownGeneratesWith(_) => RuntimeError,
Problem::UnusedArgument(_, _, _, _) => Warning,
@ -295,6 +309,7 @@ impl Problem {
}
| Problem::UnusedImport(_, region)
| Problem::UnusedModuleImport(_, region)
| Problem::ImportAliasConflict { region, .. }
| Problem::UnknownGeneratesWith(Loc { region, .. })
| Problem::UnusedArgument(_, _, _, region)
| Problem::UnusedBranchDef(_, region)