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

Add a warning against unnecessary use of "!" #2414

Closed
rrousselGit opened this issue Jan 12, 2021 · 1 comment
Closed

Add a warning against unnecessary use of "!" #2414

rrousselGit opened this issue Jan 12, 2021 · 1 comment
Labels
lint-request type-enhancement A request for a change that isn't a bug

Comments

@rrousselGit
Copy link

When using non-nullable types, it is possible to write the following:

int? a;
int? b = a!;

While this is valid code, it doesn't make sense to do a! when a simple a would be enough.
Since b is nullable, there is no reason to assert that a is not null, as any usage of b would handle the null case.

This is problematic because as we refactor code, it is possible for b to change from non-nullable to nullable.
So while the ! used to make sense, after refactoring it is instead harmful.

This should also support function calls:

void function(int? b) {}

function(a!); // do function(a) instead
@rrousselGit rrousselGit added type-enhancement A request for a change that isn't a bug lint-request labels Jan 12, 2021
@rrousselGit
Copy link
Author

closing as this is handled my unnecessary_null_checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

1 participant