Skip to content

Commit e4233e4

Browse files
committed
fix(analyse): do not emit warning for re-exports
1 parent de59a1c commit e4233e4

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

compiler-core/src/analyse.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod tests;
77
use crate::{
88
GLEAM_CORE_PACKAGE_NAME,
99
ast::{
10-
self, Arg, BitArrayOption, CustomType, Definition, DefinitionLocation, Function,
10+
self, Arg, BitArrayOption, Constant, CustomType, Definition, DefinitionLocation, Function,
1111
GroupedStatements, Import, ModuleConstant, Publicity, RecordConstructor,
1212
RecordConstructorArg, SrcSpan, Statement, TypeAlias, TypeAst, TypeAstConstructor,
1313
TypeAstFn, TypeAstHole, TypeAstTuple, TypeAstVar, TypedDefinition, TypedExpr,
@@ -248,6 +248,20 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
248248
}
249249

250250
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+
251265
if env.unqualified_imported_names.contains_key(&c.name) {
252266
self.problems
253267
.warning(Warning::TopLevelDefinitionShadowsImport {

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_warning!(
448+
assert_no_warnings!(
449449
(
450450
"thepackage",
451451
"wibble",

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

-10
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,3 @@ 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 anyway.
34-
Hint: You could remove the imported value.

0 commit comments

Comments
 (0)