You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
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
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).
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).
Activity
Phase 4: BTreeMap and BTreeSet over the M*LIB B+tree (D151); D152; D1…
Seven compiler fixes: literals at distinct demands (D153), element-pl…
ehartford commentedon Oct 23, 2026
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).