-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Improve uncalled function check related to parenthesized and binary expressions #50756
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
Improve uncalled function check related to parenthesized and binary expressions #50756
Conversation
tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt
Outdated
Show resolved
Hide resolved
src/compiler/checker.ts
Outdated
let parent = node.parent; | ||
while (parent.kind === SyntaxKind.ParenthesizedExpression | ||
|| isBinaryExpression(parent) && (parent.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken || parent.operatorToken.kind === SyntaxKind.BarBarToken)) { | ||
parent = parent.parent; | ||
} | ||
if (operator === SyntaxKind.AmpersandAmpersandToken || isIfStatement(parent)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've thought that perhaps with some of my recent changes this could be reverted but it seems that it can't. Without this change the error here goes away:
TypeScript/tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt
Lines 100 to 101 in 8f0a392
~~~~~~~~~ | |
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? |
It's quite interesting because a similar error here doesn't go away:
TypeScript/tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt
Lines 108 to 109 in 8f0a392
~~~~~~~~~ | |
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? |
So it seems that the logic is very sensitive when it comes to handling left/right side of a binary expression. Should I strive to revert this change here and find another solution? Or is this acceptable?
src/compiler/checker.ts
Outdated
helper(condExpr, body); | ||
while (isBinaryExpression(condExpr) && condExpr.operatorToken.kind === SyntaxKind.BarBarToken) { | ||
condExpr = condExpr.left; | ||
function bothHelper(condExpr: Expression, body: Expression | Statement | undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: this could use a better name, the helper
itself probably could use a better name too. I can try to figure out something better later on
@typescript-bot test this |
Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at bc24f9b. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at bc24f9b. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the extended test suite on this PR at bc24f9b. You can monitor the build here. |
Heya @jakebailey, I've started to run the abridged perf test suite on this PR at bc24f9b. You can monitor the build here. Update: The results are in! |
@jakebailey Here are the results of running the user test suite comparing Everything looks good! |
@jakebailey Here they are:Comparison Report - main..50756
System
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top-repos suite comparing Everything looks good! |
…tion-check # Conflicts: # src/compiler/checker.ts # src/compiler/factory/utilities.ts
@jakebailey you requested perf results for this some time ago. Any chance that you'd have some time to review this now when they are already here? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code LGTM and the perf does appear to be fine. I think from the issue that this is a behavior we want, so, SGTM.
@jakebailey I was wondering if there is a chance to land this before entering the 5.0 beta period (3 days left 😅 ) |
I was hoping for someone else to weigh in (I don't entirely trust myself to merge large-ish checker PRs), but it still seems fine to me given it's an "experience enhancement" aka "obviously an improvement" and top100 passed (so, probably low-risk). |
fixes #37598