-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Uncalled function checks only works with single conditional #42835
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
189b302
Uncalled function checks only works with single conditional
jonhue c57aec3
fix type errors in compiler
jonhue b17401e
remove uncalled function checks with negations
jonhue e2e6330
review
jonhue de23735
fix test
jonhue c973b9b
Merge branch 'master' into fix-35584
sandersn a5e7a6a
Merge branch 'main' into fix-35584
sandersn 177cea0
Cleanup after merge, accept baselines
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
tests/baselines/reference/uncalledFunctionChecksInConditional.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(5,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(9,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(9,14): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(13,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(32,10): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(36,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(40,22): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(44,16): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
tests/cases/compiler/uncalledFunctionChecksInConditional.ts(48,22): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
|
||
|
||
==== tests/cases/compiler/uncalledFunctionChecksInConditional.ts (9 errors) ==== | ||
declare function isFoo(): boolean; | ||
declare function isBar(): boolean; | ||
declare const isUndefinedFoo: (() => boolean) | undefined; | ||
|
||
if (isFoo) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo | ||
} | ||
|
||
if (isFoo || isBar) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo, isBar | ||
} | ||
|
||
if (isFoo || isFoo()) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo | ||
} | ||
|
||
if (isUndefinedFoo || isFoo()) { | ||
// no error | ||
} | ||
|
||
if (isFoo && isFoo()) { | ||
// no error | ||
} | ||
|
||
declare const x: boolean; | ||
declare const ux: boolean | undefined; | ||
declare const y: boolean; | ||
declare const uy: boolean | undefined; | ||
declare function z(): boolean; | ||
declare const uz: (() => boolean) | undefined; | ||
|
||
if (x || isFoo) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo | ||
} | ||
|
||
if (isFoo || x) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo | ||
} | ||
|
||
if (x || y || z() || isFoo) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo | ||
} | ||
|
||
if (x || uy || z || isUndefinedFoo) { | ||
~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on z | ||
} | ||
|
||
if (ux || y || uz || isFoo) { | ||
~~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
// error on isFoo | ||
} | ||
|
84 changes: 84 additions & 0 deletions
84
tests/baselines/reference/uncalledFunctionChecksInConditional.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//// [uncalledFunctionChecksInConditional.ts] | ||
declare function isFoo(): boolean; | ||
declare function isBar(): boolean; | ||
declare const isUndefinedFoo: (() => boolean) | undefined; | ||
|
||
if (isFoo) { | ||
// error on isFoo | ||
} | ||
|
||
if (isFoo || isBar) { | ||
// error on isFoo, isBar | ||
} | ||
|
||
if (isFoo || isFoo()) { | ||
// error on isFoo | ||
} | ||
|
||
if (isUndefinedFoo || isFoo()) { | ||
// no error | ||
} | ||
|
||
if (isFoo && isFoo()) { | ||
// no error | ||
} | ||
|
||
declare const x: boolean; | ||
declare const ux: boolean | undefined; | ||
declare const y: boolean; | ||
declare const uy: boolean | undefined; | ||
declare function z(): boolean; | ||
declare const uz: (() => boolean) | undefined; | ||
|
||
if (x || isFoo) { | ||
// error on isFoo | ||
} | ||
|
||
if (isFoo || x) { | ||
// error on isFoo | ||
} | ||
|
||
if (x || y || z() || isFoo) { | ||
// error on isFoo | ||
} | ||
|
||
if (x || uy || z || isUndefinedFoo) { | ||
// error on z | ||
} | ||
|
||
if (ux || y || uz || isFoo) { | ||
// error on isFoo | ||
} | ||
|
||
|
||
//// [uncalledFunctionChecksInConditional.js] | ||
if (isFoo) { | ||
// error on isFoo | ||
} | ||
if (isFoo || isBar) { | ||
// error on isFoo, isBar | ||
} | ||
if (isFoo || isFoo()) { | ||
// error on isFoo | ||
} | ||
if (isUndefinedFoo || isFoo()) { | ||
// no error | ||
} | ||
if (isFoo && isFoo()) { | ||
// no error | ||
} | ||
if (x || isFoo) { | ||
// error on isFoo | ||
} | ||
if (isFoo || x) { | ||
// error on isFoo | ||
} | ||
if (x || y || z() || isFoo) { | ||
// error on isFoo | ||
} | ||
if (x || uy || z || isUndefinedFoo) { | ||
// error on z | ||
} | ||
if (ux || y || uz || isFoo) { | ||
// error on isFoo | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just for safety, can you add a test like
x || y || z() || foo
?