Skip to content

Uncalled-function error with function check in binary expression misses usage in body #41586

Closed

Description

declare var f: () => void
declare var b: boolean
if (f && b) {
    f()
}

Expected behavior:
No error

Actual behavior:
Error: "Did you mean to call 'f'?"

Activity

  1. sandersn commented on Nov 18, 2020

    @sandersn
    MemberAuthor

    Oleksandr Tarasiuk (@a-tarasyuk) you might be interested in this too.

  2. MartinJohns commented on Nov 19, 2020

    @MartinJohns
    Contributor

    In version 4.2.0-dev.20201112 (nightly on the playground) this works as expected. With strictNullChecks enabled it errors, without strictNullChecks it provides no error.

  3. typescript-bot commented on Nov 19, 2020

    @typescript-bot
    Contributor

    👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in this issue running against the nightly TypeScript. If something changes, I will post a new comment.


    Issue body code block by Nathan Shively-Sanders (@sandersn)

    ❌ Failed: -

    • This condition will always return true since the function is always defined. Did you mean to call it instead?

    Historical Information

    Issue body code block by Nathan Shively-Sanders (@sandersn)

    Version Reproduction Outputs
    Nightly

    ❌ Failed: -

    • This condition will always return true since the function is always defined. Did you mean to call it instead?

    3.6.3, 3.7.5, 3.8.2, 3.9.2, 4.0.2

    👍 Compiled

  4. sandersn commented on Nov 19, 2020

    @sandersn
    MemberAuthor

    Martin Johns (@MartinJohns) I think that's because the problem started with Oleksandr Tarasiuk (@a-tarasyuk)'s recent PR to issue the error for binary expressions. Before that, the checker never issued an error for uncalled functions in binary expressions.

    Separately, this means that the playground nightly is a week out of date, which is concerning. I'll let Orta Therox (@orta) know.

  5. a-tarasyuk commented on Nov 19, 2020

    @a-tarasyuk
    Contributor

    Nathan Shively-Sanders (@sandersn) Yep. I think these issues (#41586, #41588) are equal and both related to this #40260 (comment).

  6. sandersn commented on Nov 19, 2020

    @sandersn
    MemberAuthor

    Makes sense. I have some time this morning so I can look at it if you're not already working on it.

  7. a-tarasyuk commented on Nov 19, 2020

    @a-tarasyuk
    Contributor

    I checked this case before, as I remember we need to handle binary expression and condition body. Not sure what need to check - find parent context of binary expression or use a binary expression from a condition.

    if (f && b) {
        f()
    }

    I suppose getFalsyFlags will return true for condition type, so maybe need to find the parent of binary expression. Nathan Shively-Sanders (@sandersn) What do you think?

  8. sandersn commented on Nov 19, 2020

    @sandersn
    MemberAuthor

    I think you just have to find the parent of the binary expression and if it's IfStatement, pass the body to checkTestingKnownTruthyCallableType. I've got a fix for this bug that does just that; I'm going to make sure if fixes the other bug too.

  9. sandersn commented on Nov 19, 2020

    @sandersn
    MemberAuthor

    No, the other bug also repros without a binary expression. I'll update the repro for it.

  10. added a commit that references this issue on Nov 19, 2020
    7265f49
  11. added a commit that references this issue on Nov 30, 2020
    06fb724
  12. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-repros

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions