You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[soundness] hy-check(const_init): type-parameter shadows on const conversions, type ascriptions, and file constants bypass HYB-E6003 #3851
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:
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.
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.
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 = 42fn 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.
Hello! We have implemented and submitted a complete fix for this issue in #3867.
Solution Overview:
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.
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.
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.
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
Activity
dextermos-dev commentedon Nov 6, 2026
Hello! We have implemented and submitted a complete fix for this issue in #3867.
Solution Overview:
s.type_params.contains(ty_name)checks inexpr_is_constant_inner(Expr::Call) andis_const_conversion_targetso generic type parameters shadowing aliases or primitive conversion names cannot be evaluated as constants.is_const_allowed_tyto inspectst: Option<&FnState>, rejecting any ascribed type whose named root or alias target matches an in-scope type parameter.ident_is_constantandis_const_string_expr, verifiedst.type_params.contains(name)to ensure function type parameters correctly shadow file-level constants, rejecting non-constant references withHYB-E6003.compiler/crates/hy-check/tests/issue_3851_const_init_type_param_shadow.rscovering all reproducer cases and positive controls.Settlement Wallet (USDC on Base):
0x8366bCe3a2D379De7656D7A67015789FaF999f20hy-check(const_init): reject type-parameter shadows on const conversi…
hy-check(const_init): reject type-parameter shadows on const conversi…
hy-check(const_init): reject type-parameter shadows on const conversi…
Merge PR limitlessprojects#3867: hy-check(const_init) reject type-par…
hy-check(const_init): stop alias-chain resolution on intermediate typ…