Skip to content

A collection literal's binding takes its type from its uses (D93, #2144) - #2155

Merged
ehartford merged 1 commit into
fix-2142-comptime-comprehensionfrom
d93-collection-by-use
Oct 5, 2026
Merged

ehartford merged 1 commit into
fix-2142-comptime-comprehensionfrom
d93-collection-by-use

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements spec v7.23 §4.3c rule 1 (D93). A binding with no annotation whose initializer is an element-form literal takes its type from its uses in its own function: a parameter (total(xs) with &Vec[i32]), a typed let, a return, or a method exactly one collection has (push demands a Vec). The demand settles the element type (Vec[i64]); a slice demand is met by the fixed array; two demanded types are an error at the second; an empty literal with no demand is an error.

How: the check hears the demands at the sites that would otherwise be type errors; a program with any demand is checked a second time with those bindings at the decided type, as D89's fields are. A program with none is checked once.

Not yet a demand (follow-up in #2144): assignment to or from a typed place (xs = some_vec), and top-level script bindings.

Tests: behav_d93_collection_literal_by_use (parameter, method, HashSet, element type, slice, typed let, return, empty literal), err_d93_two_demands, err_d93_empty_literal_no_demand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant