Skip to content

for (k, v) in a BTreeMap: 'tuple pattern requires tuple subject' (D44 traversal non-compliance on BTreeMap) #1561

Closed

Description

@ehartford

Found while implementing D61 (#1480); present on the installed v0.15.2.1 and main.

use std.collections.BTreeMap
fn main:
    var bt: BTreeMap[i32, str] = BTreeMap.new()
    bt.insert(10, "ten")
    for (k, v) in bt:
        print(f"{k} {v}")
error: tuple pattern requires tuple subject

The same loop over a HashMap works. D44 (decisions.md) says for (k, v) in map is map.iter() binding &K/&V for maps; BTreeMap implements Iterable[(K, V)] over its Vec[(K, V)] and the tuple pattern does not bind. In a generic body (fn f[K: Ord, V](m: &BTreeMap[K, V])) the bindings come back as undefined variables instead. D61 BTreeMap formatting iterates by index (key_at/value_at) until this is fixed.

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