Skip to content

A collection demand on a comprehension leaks into its iterable literal: let m: BTreeMap[i32, i32] = [k: k * k for k in [4, 2, 3]] is refused ("sequence literal cannot target a map") #2569

Closed

Description

@ehartford

Repro

use std.collections.BTreeMap
fn main:
    let squares: BTreeMap[i32, i32] = [k: k * k for k in [4, 2, 3]]
error: sequence literal cannot target a map; use [key: value] form
 --> t.w:3:58
3 |     let squares: BTreeMap[i32, i32] = [k: k * k for k in [4, 2, 3]]
  |                                                          ^^^^^^^^^

Binding the iterable first (let keys = [4, 2, 3] then for k in keys) passes, as does an iterable that is a call (behav_gen_push_comprehension.w's upto(4)).

Cause

The binding's map demand (BTreeMap[i32, i32]) is handed to the comprehension's iterable literal, which is a sequence; the demand belongs to the comprehension's result, not to what it iterates. Same for [x for x in [8, 2, 6, 2]] into a BTreeSet (HashMap/HashSet likely alike).

Expected

A comprehension's iterable is checked without the collection demand; [4, 2, 3] is a List[i32] literal there (§4.3). Found writing test/behavior/behav_btree_engine.w (Phase 4).

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Fixed in #2580 (c7fa606): a comprehension clause's iterable is checked without the collection demand, and a list literal of untyped numbers there is typed by the clause binding's uses (D128), as a for loop's is. Fixture behav_2569 (BTreeMap, BTreeSet, HashMap targets).

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