Skip to content

D93: an empty [] in one branch of an if expression is not typed from the other branch #3060

Closed

Description

@ehartford

§3 / D93 (collection literal by use): an empty [] takes its element type from how it is used. In an if expression whose other branch is a List[T], the [] has that type, but the compiler refuses it:

fn hosts(n: i32) -> List[i32]: [n]
let xs = if true: hosts(1) else: []
error: empty sequence literal requires expected type

Expected: xs: List[i32], the then-branch's type (as let xs = [] followed by xs.push(1) already infers). Found 2026-11-07 writing let op_hosts = if cj >= 0: self.facade_method_host(sym) else: [] in src/SemaFacade.w under the pinned seed; the workaround is to nest the if so no branch is empty (the D194 stack does that; remove it when this lands).

Activity

  1. added
    spec-gap
    on Nov 7, 2026
  2. added 2 commits that reference this issue on Nov 7, 2026
  3. ehartford commented on Nov 11, 2026

    @ehartford
    ContributorAuthor

    Merged to main ae20d89 (#3248): an arm that is a bare [] takes the other arm's type (§4.3c rule 1: it waits for its first use, and beside another arm that use is the join). Fixture test/behavior/behav_3060_empty_literal_arm_takes_the_other_arms_type.w.

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