Skip to content

Sema (§10.7, D165): List.traverse does not propagate expected Option[List[U]] / Result[List[U], E] return demand into its closure #3042

Closed

Description

@ehartford

Found during the #2987 manual audit of docs/spec/010_errors.md (§10.7, lines 342–349).

Minimal reproduction

fn main:
    let names = ["1", "2", "3"]
    let parsed: Option[List[i32]] = names.traverse(s => s.parse())
    print(parsed.unwrap().len())

Actual

error: List.traverse() function must return Option or Result
 --> repro.w:3:37
3 |     let parsed: Option[List[i32]] = names.traverse(s => s.parse())
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot infer generic method type parameter 'T'
 --> repro.w:3:57
3 |     let parsed: Option[List[i32]] = names.traverse(s => s.parse())
  |                                                         ^^^^^^^^^

Expected

When List.traverse has surrounding expected type Option[List[U]] or Result[List[U], E], Sema propagates Option[U] / Result[U, E] as the closure's expected return type so return-type-polymorphic expressions inside the closure (s.parse(), D165) infer U without an explicit (s) -> Option[i32] => return annotation.

Activity

  1. added
    spec-gap
    on Nov 5, 2026
  2. added a commit that references this issue on Nov 5, 2026
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

    spec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions