Skip to content

[soundness] hy-check(const_init): type-parameter shadows on const conversions, type ascriptions, and file constants bypass HYB-E6003 #3851

Closed

Description

@Burapa-J

Summary

In compiler/crates/hy-check/src/const_init.rs, expr_is_constant_inner, is_const_conversion_target, is_const_string_conversion_target, is_const_string_expr, is_const_allowed_ty, and ident_is_constant check st.env_lookup and file-level declarations, but do not check whether a function's generic type parameter (st.type_params) shadows a type alias, conversion target, type ascription, or file-level const:

  1. type my_int = int; fn f[my_int]() { const c = my_int(1) } and fn f[my_int]() { const c my_int = 1 } treat my_int as the file-level alias int instead of the function's type parameter my_int, accepting a Go non-constant type conversion/ascription.
  2. const k = 42; fn f[k]() { const c = k + 1 } and const s = "abc"; fn f[s]() { const n = len(s) } resolve k/s to the file-level constant even though the identifier is shadowed in function scope by the type parameter.
  3. resolve_type_alias in const_init.rs did not stop when an intermediate/target name was shadowed by structs, struct_type_params, or enums.

Minimal Reproducer

type my_int = int
const k = 42
fn f[my_int, k]() {
    const c = my_int(1)
    const d my_int = 1
    const e = k + 1
    _ = c
    _ = d
    _ = e
}
fn main() {}

Expected Behavior

Reject all three local const declarations with HYB-E6003.

Activity

  1. dextermos-dev commented on Nov 6, 2026

    @dextermos-dev
    Contributor

    Hello! We have implemented and submitted a complete fix for this issue in #3867.

    Solution Overview:

    1. Type-Parameter Shadow Guards on Conversions: Added s.type_params.contains(ty_name) checks in expr_is_constant_inner (Expr::Call) and is_const_conversion_target so generic type parameters shadowing aliases or primitive conversion names cannot be evaluated as constants.
    2. Type Ascription Verification: Extended is_const_allowed_ty to inspect st: Option<&FnState>, rejecting any ascribed type whose named root or alias target matches an in-scope type parameter.
    3. Identifier Shadowing in Scope: In ident_is_constant and is_const_string_expr, verified st.type_params.contains(name) to ensure function type parameters correctly shadow file-level constants, rejecting non-constant references with HYB-E6003.
    4. Test Suite: Added compiler/crates/hy-check/tests/issue_3851_const_init_type_param_shadow.rs covering all reproducer cases and positive controls.

    Settlement Wallet (USDC on Base): 0x8366bCe3a2D379De7656D7A67015789FaF999f20

  2. added 3 commits that reference this issue on Nov 6, 2026
    12b26ce
    bab307e
    5e73f6b
  3. added a commit that references this issue on Nov 7, 2026
    3d88bd5
  4. added a commit that references this issue on Nov 7, 2026
    9a704c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions