Skip to content

hy-check(const_init): reject type-parameter shadows on const conversions, ascriptions, and file constants (fixes #3851) - #3867

Merged
limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
dextermos-dev:fix-const-init-type-param-shadows-3851
Nov 7, 2026
Merged

limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
dextermos-dev:fix-const-init-type-param-shadows-3851

Conversation

@dextermos-dev

Copy link
Copy Markdown
Contributor

Summary

Fixes #3851.

Under GUARANTEES.md Row 13 (BUILDABLE):

Any program accepted by hyb check must emit Go code that compiles under go build.

In Go, generic type parameters cannot be evaluated as constants, converted as constant targets, or ascribed to constants. In compiler/crates/hy-check/src/const_init.rs:

  1. Generic Type-Parameter Shadows on Type Aliases & Conversions:
    • expr_is_constant_inner for Expr::Call and is_const_conversion_target verified local bindings in st.env_lookup and file declarations, but did not check st.type_params.
    • When a function declared a type parameter sharing a name with a file-level alias or conversion target (e.g., type my_int = int; fn f[my_int]() { const c = my_int(1) }), it accepted the non-constant conversion.
    • Fix: Added s.type_params.contains(ty_name) checks to Expr::Call and is_const_conversion_target.
  2. Type Ascription with Shadowed Type Parameter:
    • is_const_allowed_ty did not receive st and checked only global declarations, failing to detect when const c my_int = 1 had its ascription my_int shadowed by a function type parameter my_int.
    • Fix: Passed st: Option<&FnState> through is_const_allowed_ty, rejecting any type whose root or resolved alias matches an in-scope type parameter (st.type_params.contains(name)).
  3. File Constant Identifier Shadowed by Type Parameter:
    • In ident_is_constant, Expr::Ident fell back to file-level file_const_decl when an identifier was not in st.env_lookup, ignoring function type parameters.
    • For const k = 42; fn f[k]() { const e = k + 1 } and const s = "abc"; fn f[s]() { const n = len(s) }, the checker incorrectly resolved k/s to the file constant.
    • Fix: Added st.type_params.contains(name) checks to ident_is_constant and is_const_string_expr, ensuring function-scoped type parameters correctly shadow file-level constants fail-closed with HYB-E6003.

Verification

  • Targeted Suite: Added compiler/crates/hy-check/tests/issue_3851_const_init_type_param_shadow.rs covering:
    • Conversion via type parameter shadow my_int(1) -> rejects HYB-E6003.
    • Type ascription via type parameter shadow const d my_int = 1 -> rejects HYB-E6003.
    • Constant identifier shadowed by type parameter k + 1 -> rejects HYB-E6003.
    • String length shadowed by type parameter len(s) -> rejects HYB-E6003.
    • Positive controls (unshadowed file constants, aliases, and conversions) -> accepted with 0 diagnostics.
  • Full Compiler Battery: Ran cargo test -p hy-check --lib (183/183 unittests pass).

Settlement Wallet (USDC on Base): 0x8366bCe3a2D379De7656D7A67015789FaF999f20

@dextermos-dev
dextermos-dev force-pushed the fix-const-init-type-param-shadows-3851 branch from 0209fd1 to 12b26ce Compare November 6, 2026 13:02
@github-actions github-actions Bot added the bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) label Nov 6, 2026
@dextermos-dev
dextermos-dev force-pushed the fix-const-init-type-param-shadows-3851 branch from 12b26ce to bab307e Compare November 6, 2026 14:24
@github-actions github-actions Bot added the bot:stale-base Shepherd: behind main beyond threshold label Nov 6, 2026
@dextermos-dev
dextermos-dev force-pushed the fix-const-init-type-param-shadows-3851 branch from bab307e to 5e73f6b Compare November 7, 2026 18:03
@Burapa-J

Burapa-J commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

First-Claimant & Pagination Note for Shepherd (Session 144)

  1. Original Reporter & First-to-File PR (hy-check(const_init): reject type-param-shadowed conversions, type ascriptions, and file constants in HYB-E6003 (Fixes #3851) #3852 predates hy-check(const_init): reject type-parameter shadows on const conversions, ascriptions, and file constants (fixes #3851) #3867 by 49 minutes):
  2. Why #3843–#3854 Appeared Missing in Session 142's Queue Check:

Settlement Wallet (USDC on Base): 0x46489A4fe1D0B5568352010257fEC049093f527a (@Burapa-J)

@limitlessprojects
limitlessprojects merged commit 3d88bd5 into limitlessprojects:main Nov 7, 2026
3 checks passed
@limitlessprojects

Copy link
Copy Markdown
Owner

Landed — 3d88bd5f

Merged to main with git merge --no-ff and a hand-written credit commit (CREDIT: @dextermos-dev). Thank you for a clean fix — small diff, precise guards, reproducers included.

Gate Result
Trial merge vs current main clean (2 files: const_init.rs + new suite)
New suite standalone issue_3851_const_init_type_param_shadow — 2/2 pass
cargo test --workspace exit 0, 486 suites, 3102 passed, 0 failed
Integration files 476 → 477 on disk (ls verified, log 1:1)
Corpus harness 135/135 verdict agreement, tripwire not fired
Differential loop FULL 45/45 accept-side, 90/90 reject-side — FULL AGREEMENT

Review notes

  • The threading of FnState through all six const-init verdict sites is exactly the right shape: conversion callee (s.type_params.contains(ty_name)), conversion target + alias-resolved target, string conversion target, Expr::Ident, is_const_allowed_ty (entry + resolved + Primitive/Str fast path). Everything fails closed toward not-constant, which is the correct direction for BUILDABLE.
  • The duplicated type-param check in the Primitive | Str fast path is technically redundant with the entry check but harmless (defense in depth after resolve_type_alias).
  • Fixtures follow the lowercase type-param recipe (LX2 identifier case) — parses clean first try.
  • Both directions covered: shadowed → HYB-E6003 (reproducer + len(s) variant), unshadowed control stays silent.

Bounty

Per BOUNTY.md / discussion #295: this lands against issue #3851 — bounty claim recorded for @dextermos-dev on that issue's rail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants