Skip to content

D114-exposed: an untyped const used in an imported module loses its type context when the root declares a global of the same name #2333

Closed

Description

@ehartford

Spec: §4.2.1 (D88 untyped constants; rule 4, a tail takes the declared return), D114 (default isize), #1703 / D70 (displaced names).

Repro (d114-impl stage1):

// owner.w
pub const A = 10
const B = 3
pub fn f() -> i32: A * B

// main2.w
use owner
let A = 5
fn main:
    print(f() + A)

Actual: owner.w:3:20: implicit integer narrowing or sign change from isize to i32 on A * B.
Expected: A * B is typed i32 by the declared return; prints 35.

Narrowed (lldb + variants):

  • Without the root global (main1), or with a differently named root global (let Z = 5), or with let A = 5 as a local inside main: no error.
  • check_untyped_const_use runs for both uses in owner.w (untyped path taken), but ty stays the declared default (isize): no expected type reaches it.
  • check_fn_body_with_sig_at gives f (sig 655) body_expected_ret = i32 both times it is checked; the lost demand is between there and the operand. Not yet located at the line.

On main the default literal type was i32, so the missing context was invisible. Found by the D114 behavior-test sweep; the #1703 fixture was restored to plain let globals (: i32), which tests displaced globals without this path.

Activity

  1. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Fixed on branch d115-d120 (commit b8ce24c, stacked for the next battery): untyped_const_init_depth now follows the displaced record whose path is the current module, so a module's own untyped constant that a same-named root declaration displaced (registered under its $in$ identity) is found from the module's bare name. Fixture: test/behavior/behav_2333_displaced_untyped_const.w with test/behavior/lib/displaced_const_owner.w (prints 35).

  2. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Fixed on branch d115-d120 (commit b8ce24c, stacked for the next battery): untyped_const_init_depth follows the displaced record whose path is the current module, so a module's own untyped constant that a same-named root declaration displaced (registered under its $in$ identity) is found from the module's bare name. Fixture: test/behavior/behav_2333_displaced_untyped_const.w with test/behavior/lib/displaced_const_owner.w (prints 35).

  3. added a commit that references this issue on Oct 11, 2026
  4. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Merged to main in e4861e1 (#2349), battery green.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions