Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncalled function checks only works with single conditional #42835

Merged
merged 8 commits into from
Feb 17, 2022

Conversation

jonhue
Copy link
Contributor

@jonhue jonhue commented Feb 17, 2021

This pull request makes two changes:

  1. it checks all operands of || binary expressions for uncalled functions (not just the rightmost ones)
  2. it checks operands of ! unary expressions for uncalled functions (if the function cannot be undefined)

Fixes #35584

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Feb 17, 2021
@jonhue jonhue marked this pull request as draft February 17, 2021 11:13
@jonhue jonhue force-pushed the fix-35584 branch 3 times, most recently from 611f5b3 to e848beb Compare February 17, 2021 11:32
@jonhue jonhue marked this pull request as ready for review February 17, 2021 11:34
@sandersn
Copy link
Member

sandersn commented Mar 2, 2021

@typescript-bot user test this
@typescript-bot run dt

@jonhue A couple of things to do next:

  1. Look to see if there are new errors from the user tests or DT tests. Report on whether the new errors are useful or not. (The DT tests may have lots of false positives, since they're often not real code.)
  2. Open a separate bug for "uncalled function checks don't work with negation".

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 2, 2021

Heya @sandersn, I've started to run the parallelized Definitely Typed test suite on this PR at 745a34c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 2, 2021

Heya @sandersn, I've started to run the parallelized community code test suite on this PR at 745a34c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@jonhue
Copy link
Contributor Author

jonhue commented Mar 5, 2021

@sandersn Thank you for your comment! I skimmed through the test suite run and the errors look reasonable to me.
I also split this pr up into two, as you suggested. This one, and #43097. 🙂

@@ -34550,6 +34550,9 @@ namespace ts {
}

const location = isBinaryExpression(condExpr) ? condExpr.right : condExpr;
if (isBinaryExpression(condExpr) && condExpr.operatorToken.kind === SyntaxKind.BarBarToken) {
checkTestingKnownTruthyCallableOrAwaitableType(condExpr.left, type, body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think recursion is a good idea here, because binary expressions might be pretty long, and because the core of checkTestingKnownTruthyCallableOrAwaitableType is not too complex.

I'd move the getSignatureOfType check before location's declaration, then put the rest of the function in a helper that's called in a loop, something like:

            helper(condExpr, body)
            while (isBinaryExpression(condExpr) && condExpr.operatorToken.kind === SyntaxKind.BarBarToken) {
                condExpr = condExpr.left
                helper(condExpr, body)
            }

(although you might be able to write it more elegantly)

// error
}

if (isFoo || isBar) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for safety, can you add a test like x || y || z() || foo?

@sandersn
Copy link
Member

Actually, looking at the whole call chain, I think type needs to be checked per-condExpr as well. At least there needs to be tests for multiple, alternating defined/undefined uncalled functions, like x || uy || z || ufoo or ux || y || uz || foo, where u- means that the variable has undefined in its type.

@jonhue
Copy link
Contributor Author

jonhue commented Mar 12, 2021

@sandersn Thank you for your comments! You're right, we do need to check the type per condExpr for this to work. I added some more test cases and it does work as we would expect now 🙂.
I also implemented the refactoring you suggested.

@jonhue jonhue requested a review from sandersn March 12, 2021 09:13
@sandersn
Copy link
Member

sandersn commented Mar 19, 2021

I like the code as-is, but it checks a lot more than before. I want to see whether there are many new errors in the user tests:

@typescript-bot user test this
@typescript-bot run dt

@jonhue can you take a look at those after they're done running?

Edit: I'll sign off if you find that there aren't a lot of bogus errors appearing.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 19, 2021

Heya @sandersn, I've started to run the parallelized community code test suite on this PR at de23735. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 19, 2021

Heya @sandersn, I've started to run the parallelized Definitely Typed test suite on this PR at de23735. You can monitor the build here.

@jonhue
Copy link
Contributor Author

jonhue commented Mar 20, 2021

@sandersn looks like something went wrong while running the tests. I can't really gather from the logs what exactly went wrong. Could you take a brief look/rerun the tests? 🙂

@sandersn
Copy link
Member

sandersn commented Apr 2, 2021

@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 2, 2021

Heya @sandersn, I've started to run the parallelized Definitely Typed test suite on this PR at c973b9b. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 2, 2021

Heya @sandersn, I've started to run the parallelized community code test suite on this PR at c973b9b. You can monitor the build here.

@sandersn
Copy link
Member

sandersn commented Apr 2, 2021

No report from typescript-bot again =( I manually checked the DT run and there weren't any new failures. It looks like the user test run failed to post a comment after it successfully pushed to the existing PR at https://github.com/typescript-bot/TypeScript/pull/158/files

I looked at the existing PR and saw two new errors: the fluentui one is good. It looks like the author forgot that hasSuggestionSelected was a method since it's used right before an accessor. The clone error is on module.exports -- TS generally doesn't understand module checks, so it's not a problem.

@sandersn
Copy link
Member

sandersn commented Apr 2, 2021

Since this is a new feature, I'll merge this after the 4.3 beta is done.

@typescript-bot
Copy link
Collaborator

The TypeScript team hasn't accepted the linked issue #35584. If you can get it accepted, this PR will have a better chance of being reviewed.

@sandersn sandersn merged commit fb1066e into microsoft:main Feb 17, 2022
@clarkio
Copy link

clarkio commented Feb 17, 2022

Thank you all for your work in this 👍 Glad to see it added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Uncalled function checks only works with single conditional
4 participants