Skip to content

Infer types across conditional branches for same variables #15525

Description

@josevalim

Following up on #15459, we need to make it so Kernel.or, Kernel.and, Kernel.|| and Kernel.&& can all pass this test:

            assert typecheck!(
              [x],
              cond do
                is_integer(x) or is_boolean(x) -> {:one, x}
                true -> {:two, x}
              end
            ) == opt_union(
              tuple([atom([:one]), opt_union(integer(), boolean())]),
              tuple([atom([:two]), negation(opt_union(integer(), boolean()))])
           )

As far as I know, none of them do it today. And it is tricky because is_integer(x) or is_boolean(y) gets a different result. We already have this machinery in guards, but we need to repurpose it.

Originally posted by @josevalim in #15450

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions