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