Skip to content

False positive in unreachable_from_main #59199

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
natebosch opened this issue Jun 27, 2023 · 4 comments
Closed

False positive in unreachable_from_main #59199

natebosch opened this issue Jun 27, 2023 · 4 comments
Assignees
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-false-positive P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@natebosch
Copy link
Member

jsonEncode checks for the presence of a toJson method and uses it when it exists. It's a common pattern to have a toJson without any static references to it. I think we should consider it a false positive to flag a toJson member.

import 'dart:convert';

void main() async {
  print(jsonEncode([C()]));
}

class C {
  List toJson() => ['c'];
  //   ^ unreachable_from_main
}
@pq
Copy link
Member

pq commented Jun 30, 2023

/fyi @srawlins

@pq pq added the P2 A bug or feature request we're likely to work on label Jun 30, 2023
@srawlins
Copy link
Member

srawlins commented Jul 3, 2023

I'm happy to take this as a false positive, but I am extremely curious: how does dart:convert#jsonEncode do this? Mirrors? native magic?

@srawlins srawlins self-assigned this Jul 3, 2023
copybara-service bot referenced this issue Jul 4, 2023
Bug: https://github.com/dart-lang/linter/issues/4495
Change-Id: I74b0a6cb516d2850bb922005e463f58f58453b4f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312280
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
@natebosch
Copy link
Member Author

I am extremely curious: how does dart:convert#jsonEncode do this?

Cast the object to dynamic for dynamic dispatch, use try {} catch {} for the NoSuchMethodError when it doesn't exist.

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 3, 2024
copybara-service bot referenced this issue Apr 15, 2024
Fixes https://github.com/dart-lang/linter/issues/4495

Change-Id: Ic6ba67393f9c05d8fa1b327b8d2c87f654fc01d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362561
Auto-Submit: Samuel Rawlins <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
@srawlins
Copy link
Member

Fixed by 954ed42

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

No branches or pull requests

4 participants