Fix module constant usage warnings.

This commit is contained in:
KtorZ 2024-08-30 18:24:35 +02:00
parent 55d381fbfc
commit 75c059bf65
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 35 additions and 0 deletions

View File

@ -3237,3 +3237,30 @@ fn extraneous_fallback_on_exhaustive_handlers() {
Err((_, Error::UnexpectedValidatorFallback { .. })) Err((_, Error::UnexpectedValidatorFallback { .. }))
)) ))
} }
#[test]
fn constant_usage() {
let source_code = r#"
pub const some_bool_constant: Bool = True
const some_int_constant: Int = 42
const some_string_constant: String = @"Aiken"
test foo() {
some_int_constant == 42
}
"#;
let result = check(parse(source_code));
assert!(result.is_ok());
let (warnings, _) = result.unwrap();
assert!(matches!(
&warnings[..],
[Warning::UnusedPrivateModuleConstant {
name,
..
}] if name == "some_string_constant"
));
}

View File

@ -632,6 +632,14 @@ fn infer_definition(
location, location,
)?; )?;
// NOTE: The assignment above is only a convenient way to create the TypedExpression
// that will be reduced at compile-time. We must increment its usage to not
// automatically trigger a warning since we are virtually creating a block with a
// single assignment that is then left unused.
//
// The usage of the constant is tracked through different means.
environment.increment_usage(&name);
let typed_expr = match typed_assignment { let typed_expr = match typed_assignment {
TypedExpr::Assignment { value, .. } => value, TypedExpr::Assignment { value, .. } => value,
_ => unreachable!("infer_assignment inferred something else than an assignment?"), _ => unreachable!("infer_assignment inferred something else than an assignment?"),