Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Conversation

@asashour
Copy link
Contributor

Fixes dart-lang/sdk#59021

Description

unnecessary_parenthesis should check for an expression being null aware recursively, through the target.

@coveralls
Copy link

coveralls commented Jan 30, 2023

Coverage Status

Coverage: 95.66% (+0.004%) from 95.656% when pulling 74c4b44 on asashour:4028_unnecessary_parenthesis into 6006d74 on dart-lang:main.

@kevmoo kevmoo merged commit 8bb9658 into dart-archive:main Jan 30, 2023
@asashour asashour deleted the 4028_unnecessary_parenthesis branch January 30, 2023 16:50
@oprypin
Copy link
Contributor

oprypin commented Feb 2, 2023

Thanks. This definitely fixes the false positive.

But I noticed this also adds a new caught case. Which definitely seems to also be an improvement, but just thought I'd point it out because I'm not sure if it was expected.

Wasn't reported before, now is:

var x = (foo?.a.b.c.length) ?? 0;

@asashour
Copy link
Contributor Author

asashour commented Feb 2, 2023

I think the new behavior is correct, the parenthesis are unnecessary, and they can be safely removed, or I am missing something.

class A {
  A a = A();
  A b = A();
  String c = '';
}

void f(A? foo) {
  int x = (foo?.a.b.c.length) ?? 0;
}

@oprypin
Copy link
Contributor

oprypin commented Feb 2, 2023

Sure, can be removed.

definitely seems to also be an improvement, but just thought I'd point it out

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

unnecessary_parenthesis false positive with null-aware toString

5 participants