Skip to content

iterable_contains_unrelated_type not working for List #57708

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

Closed
davidmorgan opened this issue May 23, 2018 · 6 comments · Fixed by dart-archive/linter#2536
Closed

iterable_contains_unrelated_type not working for List #57708

davidmorgan opened this issue May 23, 2018 · 6 comments · Fixed by dart-archive/linter#2536
Labels
customer-google3 devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@davidmorgan
Copy link
Contributor

In IntelliJ, I see this triggers the lint:

  Iterable<int> foo = [1];
  print(foo.contains('3'));

and this:

  Set<int> foo = Set.from([1]);
  print(foo.contains('3'));

but not this:

  List<int> foo = [1];
  print(foo.contains('3'));

I'm at a loss as to why not; it looks like there are test cases that should catch this in the linter code, and they pass. Maybe there is something in the test setup that is now different from the actual List?

@alexeieleusis
Copy link
Contributor

I just tried adding the example you provide and the test fails, also confirmed that if I remove the // LINT annotation the test fails, so is definitely being linted in the tests. If I run dart bin/linter.dart --rules=iterable_contains_unrelated_type test/rules/iterable_contains_unrelated_type.dart the lint is not reported.

I have no idea what the problem is :(

@pq
Copy link
Member

pq commented Jun 25, 2018

Maybe there is something in the test setup that is now different from the actual List?

👍

We mock the SDK to speed up testing and it looks like List is out of date:

https://github.com/dart-lang/linter/blob/9f3df652baa88372513f1ac74148b8e7a5a6d1a0/test/mock_sdk.dart#L125-L134

(In the SDK, List implements EfficientLengthIterable<E>)

@pq pq added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 25, 2018
@pq
Copy link
Member

pq commented Jun 25, 2018

/cc @alexeieleusis

@lambda-fairy
Copy link

I think the issue is that unrelated_types_visitor only checks interfaces, and not superclass or mixins.

Indeed, in the SDK List<T> extends EfficientLengthIterable, not implements.

Perhaps replacing that bespoke method with a call to getImplementedInterfaces would fix the bug.

@lambda-fairy
Copy link

I take that back -- after changing the mock List<T> to extend an intermediate EfficientLengthIterable class, the tests still pass 🤔

NB: The mock SDK has been moved to the analyzer package.

@xvrh
Copy link
Contributor

xvrh commented Mar 18, 2021

I think the lint iterable_contains_unrelated_type is still broken. The examples don't trigger the lint in my project.

dart --version
Dart SDK version: 2.12.1 (stable) (Wed Mar 10 10:18:47 2021 +0100) on "macos_x64"
// main.dart
void someFunction() {
  var list = <int>[];
  if (list.contains('1')) print('someFunction');
}
# analysis_options.yaml
linter:
  rules:
    - iterable_contains_unrelated_type
dart analyze
No issues found!

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-google3 devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants