Skip to content

Commit d32bb06

Browse files
committed
feat(analyse): add back the warning on re-exports
1 parent 587f266 commit d32bb06

4 files changed

+27
-36
lines changed

compiler-core/src/analyse.rs

+16-33
Original file line numberDiff line numberDiff line change
@@ -247,40 +247,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
247247
self.register_type_alias(t, &mut env);
248248
}
249249

250-
for c in &statements.constants {
251-
// don't warn if the definition is a re-export.
252-
if let Constant::<(), ()>::Var {
253-
location: _,
254-
module: _,
255-
name,
256-
constructor: _,
257-
type_: _,
258-
} = &*c.value
259-
{
260-
if name == &c.name {
261-
continue;
262-
}
263-
}
264-
265-
if env.unqualified_imported_names.contains_key(&c.name) {
266-
self.problems
267-
.warning(Warning::TopLevelDefinitionShadowsImport {
268-
location: c.location,
269-
name: c.name.clone(),
270-
})
271-
}
272-
}
273-
274250
for f in &statements.functions {
275-
let (_name_location, name) = f.name.clone().expect("A module's function must be named");
276-
if env.unqualified_imported_names.contains_key(&name) {
277-
self.problems
278-
.warning(Warning::TopLevelDefinitionShadowsImport {
279-
location: f.location,
280-
name,
281-
});
282-
}
283-
284251
if let Err(error) = self.register_value_from_function(f, &mut env) {
285252
return self.all_errors(error);
286253
}
@@ -428,6 +395,14 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
428395
} = c;
429396
self.check_name_case(name_location, &name, Named::Constant);
430397

398+
if environment.unqualified_imported_names.contains_key(&name) {
399+
self.problems
400+
.warning(Warning::TopLevelDefinitionShadowsImport {
401+
location: c.location,
402+
name: name.clone(),
403+
})
404+
}
405+
431406
environment.references.begin_constant();
432407

433408
let definition = FunctionDefinition {
@@ -1457,6 +1432,14 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
14571432

14581433
self.check_name_case(*name_location, name, Named::Function);
14591434

1435+
if environment.unqualified_imported_names.contains_key(name) {
1436+
self.problems
1437+
.warning(Warning::TopLevelDefinitionShadowsImport {
1438+
location: f.location,
1439+
name: name.clone(),
1440+
});
1441+
}
1442+
14601443
environment.references.register_value(
14611444
name.clone(),
14621445
EntityKind::Function,

compiler-core/src/type_/tests/dead_code_detection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ pub const wibble = 2
445445

446446
#[test]
447447
fn used_shadowed_imported_value() {
448-
assert_no_warnings!(
448+
assert_warning!(
449449
(
450450
"thepackage",
451451
"wibble",

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__dead_code_detection__used_shadowed_imported_value.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ warning: Definition of "wibble" shadows an imported value
2222
4pub const wibble = wibble
2323
^^^^^^^^^^^^^^^^
2424

25-
The imported value could not be used anyway.
26-
Hint: You could remove the imported value.
25+
The imported value could not be used in functions anyway.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__unused_alias_warning_test.snap

+9
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ warning: Unused imported module alias
2222
Hint: You can safely remove it.
2323

2424
import gleam/wibble as _
25+
26+
27+
warning: Definition of "one" shadows an imported value
28+
┌─ /src/warning/wrn.gleam:3:13
29+
30+
3pub const one = one
31+
^^^^^^^^^^^^^
32+
33+
The imported value could not be used in functions anyway.

0 commit comments

Comments
 (0)