Skip to content

Uncalled function checks don't work when the variable is referenced in the block #43211

@jonhue

Description

@jonhue

Bug Report

🔎 Search Terms

uncalled function checks, conjunction, &&

🕗 Version & Regression Information

This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

💻 Code

// @strictNullChecks: true

declare function isFoo(): boolean;
declare function isBar(): boolean;

if (isFoo) {
    // uncalled function checks already work well here
}

if (isFoo && isBar()) {
    // uncalled function checks already work well here
}

if (isFoo && isFoo()) {
    // uncalled function checks should cover this case too
}

if (isFoo && isBar()) {
    isFoo;
    // uncalled function checks should cover this case too
}

🙁 Actual behavior

In the last two cases we didn't detect that the first occurrence of isFoo in the condition is uncalled.

🙂 Expected behavior

When isFoo cannot possibly be a falsy value (i.e. undefined) we should highlight this as an error even if isFoo occurs again later on. This is a follow-up to a conversation in #42835 (comment).
I would be happy to enable this check, then we could run this against some user tests and decide whether there are too many false positives 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions