Skip to content

D128 gap: a comprehension's binding is not typed by its uses ( at ) #2343

Closed

Description

@ehartford

Spec: §4.2.1 D128 (locals typed by their uses), §4.3c (D93 types a bracket literal's binding by its uses), §13.6.

fn assert_list_i32(xs: []i32, a: i32, b: i32, c: i32): ...
let src = [(1, 2), (3, 4), (5, 6)]
let sums = [a + b for (a, b) in src]
assert_list_i32(sums, 3, 7, 11)      // wrong argument type: List[isize]

D93 records a use-demand only for a bracket-literal binding (NK_ARRAY_LIT); a comprehension's binding gets no demand, and the demand would have to reach src's tuple elements through the comprehension's pattern. By law 1 the compiler can establish i32 here (the one use says it). test/spec/spec_ss13_6_comprehensions.w carries let src: List[(i32, i32)] until this lands; the annotation comes out with the fix.

Activity

  1. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Fixtures carrying annotations until this lands (each is the comprehension-binding gap or a literal flowing through a generic/builtin result the demand cannot reach): test/spec/spec_ss13_6_comprehensions.w (src/pairs: List[(str, i32)], 0i32.. ranges), test/debug_alloc/da_comprehension_try_releases_collection.w and da_comprehension_iteration_temps.w (0i32..), test/debug_alloc/da_2019_cancel_inside_*.w (xs.fold(0i32, …): a builtin's result from a literal init), test/spec/spec_ss13_5d_loop_value.w (let x: i32 = loop: break 20), test/spec/spec_ss18_7_core_language.w (let t: (i32, i32, i32), a tuple local demanded through an element read). D128 lands with these; the annotations come out with the fixes.

  2. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Fixed on branch d115-d120 (commit b8ce24c): a comprehension's binding is a literal's binding for D93 demands, and a loop or clause binding over a literal's binding carries a D128 demand to that literal, a tuple pattern position by position. Also fixes the plain loop let a1 = [1, 2, 3]; for x in a1: narrow(x). Fixture: test/behavior/behav_2343_comprehension_binding_by_use.w; the annotation in test/spec/spec_ss13_6_comprehensions.w is gone. int-local-rechecks stays 0 for the compiler.

  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