Skip to content

A method call on a collection literal under an outer demand types the literal by the demand: [1, 2, 3].traverse(...) with a Result[List[T], E] annotation reports "unknown method 'traverse' for type 'Result[isize]'" #3051

Closed

Description

@ehartford

Spec: §4.3 / D93 (a collection literal is typed by its use) and §10.7 (List.traverse).

type Tracked { n: i32 }
fn main:
    let r: Result[List[Tracked], str] = [1, 2, 3].traverse(n => Ok(Tracked { n }))

Actual (v0.16.0.8):

error: unknown method 'traverse' for type 'Result[isize]'

Expected: the literal is the receiver of traverse; the outer Result[List[Tracked], str] demand is the call's result type, not the receiver's. The literal is a List[isize] (or List[i32] once the closure's parameter use types it) and the call checks as it does when the literal is bound first:

    let nums = [1, 2, 3]
    let r: Result[List[Tracked], str] = nums.traverse(n => Ok(Tracked { n }))   // works

Workaround used in test/debug_alloc/da_traverse_closure_per_element_and_fail_path.w: bind the literal first. Found while fixing the traverse closure-move / short-circuit leak (spec-gaps-3 batch).

Activity

  1. added
    bug
    on Nov 6, 2026
  2. ehartford commented on Nov 7, 2026

    @ehartford
    ContributorAuthor

    Fixed in #3056 (merged as afbdbb1).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions