-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't report
reportUnnecessaryComparison
whern using assert_never
…
… in an intentionally unreachable case in a match statement
- Loading branch information
1 parent
562a2c0
commit 70c15c1
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
17 changes: 17 additions & 0 deletions
17
packages/pyright-internal/src/tests/patternMatching.test.ts
This file contains 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,17 @@ | ||
import { ConfigOptions } from '../common/configOptions'; | ||
import { DiagnosticRule } from '../common/diagnosticRules'; | ||
import { Uri } from '../common/uri/uri'; | ||
import { typeAnalyzeSampleFiles, validateResultsButBased } from './testUtils'; | ||
|
||
test('assert_never', () => { | ||
const configOptions = new ConfigOptions(Uri.empty()); | ||
configOptions.diagnosticRuleSet.reportUnnecessaryComparison = 'error'; | ||
|
||
const analysisResults = typeAnalyzeSampleFiles(['reportUnnecessaryComparison.py'], configOptions); | ||
validateResultsButBased(analysisResults, { | ||
errors: [ | ||
{ code: DiagnosticRule.reportUnnecessaryComparison, line: 16 }, | ||
{ code: DiagnosticRule.reportUnnecessaryComparison, line: 24 }, | ||
], | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/pyright-internal/src/tests/samples/reportUnnecessaryComparison.py
This file contains 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,26 @@ | ||
from typing import Never, assert_never | ||
|
||
def _(something_else: Never, subject: int | str): | ||
match subject: | ||
case int(): | ||
... | ||
case str(): | ||
... | ||
case _: # no error, intentional due to assert_never on the subject | ||
assert_never(subject) | ||
|
||
match subject: | ||
case int(): | ||
... | ||
case str(): | ||
... | ||
case _: # error, the argument passed to assert_never is unrelated to the match subject | ||
assert_never(something_else) | ||
|
||
match subject: | ||
case int(): | ||
... | ||
case str(): | ||
... | ||
case _: # error, not an assert_never | ||
print(subject) |