-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Do not use OfType<T>() with impossible types #33770
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Linq
code-analyzer
Marks an issue that suggests a Roslyn analyzer
in-pr
There is an active PR which will close this issue when it is merged
Milestone
Comments
terrajobst
added
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Linq
code-analyzer
Marks an issue that suggests a Roslyn analyzer
labels
Mar 19, 2020
Dotnet-GitSync-Bot
added
the
untriaged
New issue has not been triaged by the area owner
label
Mar 19, 2020
Estimates:
|
terrajobst
removed
the
untriaged
New issue has not been triaged by the area owner
label
Mar 21, 2020
Possibly at the same time, though via a different diagnostic ID: calling Enumerable.Range(1, 100).OfType<int>();
// @jnyrup points out that this is actually a non-null check,
// so isn't completely safe to remove
// myString.Split(",").OfType<object>(); |
I did a little prototype for fun over at dotnet/roslyn-analyzers#3608 |
@drewnoakes Note that for reference types this can be used as a less clear way of writing |
7 tasks
buyaa-n
added
api-ready-for-review
API is ready for review, it is NOT ready for implementation
and removed
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
labels
Nov 6, 2020
Approved as proposed Category: Reliability |
bartonjs
added
api-approved
API was approved in API review, it can be implemented
and removed
api-ready-for-review
API is ready for review, it is NOT ready for implementation
labels
Nov 10, 2020
Closed
18 tasks
carlossanlop
added
the
in-pr
There is an active PR which will close this issue when it is merged
label
Jul 6, 2022
ghost
locked as resolved and limited conversation to collaborators
Feb 26, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Linq
code-analyzer
Marks an issue that suggests a Roslyn analyzer
in-pr
There is an active PR which will close this issue when it is merged
Warn if use of
OfType<T>()
would provably result in an empty sequence, because we can see that the input type in the sequence will never be the specified type.Category: Reliability
Suggested severity: Warning
UPDATE FROM roslyn-analyzer issue :
The following will always throw an InvalidCastException at runtime:
Perhaps worse, this will return an enumerable that fully enumerates the source and then returns no items silently:
Both of these situations are likely to be a mistake.
Ther is a PR out for review
The text was updated successfully, but these errors were encountered: