Make sure global const delcarations are not misreported as unused.
ConstantDeclarations aren't actually a thing as they're now all just
VariableDeclarations with 'pub const' mutability.  This needed to be
accounted for in the dead code analysis.
@@ -8,7 +8,7 @@ use crate::{
TypedEnumDeclaration, TypedExpression, TypedExpressionVariant,
TypedFunctionDeclaration, TypedReassignment, TypedReturnStatement,
TypedStructDeclaration, TypedStructExpressionField, TypedTraitDeclaration,
- TypedVariableDeclaration, TypedWhileLoop,
+ TypedVariableDeclaration, TypedWhileLoop, VariableMutability,
},
TypeCheckedStorageReassignment, TypedAstNode, TypedAstNodeContent, TypedParseTree,
},
@@ -338,7 +338,17 @@ fn connect_declaration(
) -> Result<Vec<NodeIndex>, CompileError> {
use TypedDeclaration::*;
match decl {
- VariableDeclaration(TypedVariableDeclaration { body, .. }) => connect_expression(
+ VariableDeclaration(TypedVariableDeclaration {
+ name,
+ body,
+ is_mutable,
+ ..
+ }) => {
+ if matches!(is_mutable, VariableMutability::ExportedConst) {
+ graph.namespace.insert_constant(name.clone(), entry_node);
+ Ok(leaves.to_vec())
+ } else {
+ connect_expression(
&body.expression,
graph,
&[entry_node],
@@ -346,7 +356,9 @@ fn connect_declaration(
"variable instantiation",
tree_type,
body.clone().span,
- ),
+ )
+ }
+ }
ConstantDeclaration(TypedConstantDeclaration { name, .. }) => {
graph.namespace.insert_constant(name.clone(), entry_node);
Ok(leaves.to_vec())
