Explicit builtin import warning

We will now show a warning if a builtin is imported explicitly,
since this is unncessary.

We will not show the warning if they expose functions from the builtin:

	import Dict exposing [isEmpty]

However, we will show a special warning if they expose types from it:

	import Dict exposing [Dict, isEmpty]
This commit is contained in:
Agus Zubiaga 2024-04-14 10:46:37 -03:00
parent 3217e5a3f0
commit 979aff8bf7
No known key found for this signature in database
6 changed files with 144 additions and 8 deletions

View file

@ -47,6 +47,8 @@ pub enum Problem {
new_import_region: Region,
existing_import: ScopeModuleSource,
},
ExplicitBuiltinImport(ModuleId, Region),
ExplicitBuiltinTypeImport(Symbol, 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
@ -229,6 +231,8 @@ impl Problem {
Problem::UnusedImport(_, _) => Warning,
Problem::UnusedModuleImport(_, _) => Warning,
Problem::ImportNameConflict { .. } => RuntimeError,
Problem::ExplicitBuiltinImport(_, _) => Warning,
Problem::ExplicitBuiltinTypeImport(_, _) => Warning,
Problem::ExposedButNotDefined(_) => RuntimeError,
Problem::UnknownGeneratesWith(_) => RuntimeError,
Problem::UnusedArgument(_, _, _, _) => Warning,
@ -307,6 +311,8 @@ impl Problem {
new_import_region: region,
..
}
| Problem::ExplicitBuiltinImport(_, region)
| Problem::ExplicitBuiltinTypeImport(_, region)
| Problem::UnknownGeneratesWith(Loc { region, .. })
| Problem::UnusedArgument(_, _, _, region)
| Problem::UnusedBranchDef(_, region)