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

LibraryElement.parts broken in analyzer 4.3.0 and newer #49566

Closed
jmatth opened this issue Jul 29, 2022 · 6 comments
Closed

LibraryElement.parts broken in analyzer 4.3.0 and newer #49566

jmatth opened this issue Jul 29, 2022 · 6 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jmatth
Copy link

jmatth commented Jul 29, 2022

  • Dart SDK Version: Dart SDK version: 2.17.6 (stable) (Tue Jul 12 12:54:37 2022 +0200) on "macos_arm64"
  • OS: macOS
  • Browser: N/A

The latest updates to analyzer seem to have broken LibraryElement.parts in at least some cases. The auto_route project uses that field in its code generator. With version 4.3.0 or newer of analyzer, the parts field is empty even when there is a part directive in the file, which causes the generator to break. I have a separate bug open against that project at Milad-Akarie/auto_route_library#1172

I bisected the analyzer package and found the issue was introduced in d19e1d1. Unfortunately that commit contains a lot of code and I'm not familiar with the analyzer internals, so that's when I stopped investigating and filed this issue.

@bwilkerson
Copy link
Member

@scheglov

@bwilkerson bwilkerson added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jul 29, 2022
@scheglov
Copy link
Contributor

LibraryElement.parts stopped including units which don't point back at the library, i.e. don't have a part of name; or part of uri; directives. A not existing file has this property.

OTOH, LibraryElement.parts2 supports these cases. You get List<PartElement>, where each PartElement has DirectiveUri get uri, and there are several subtypes of DirectiveUri. For the valid case it is DirectiveUriWithUnit, but could be DirectiveUriWithSource, etc.

@jmatth
Copy link
Author

jmatth commented Jul 29, 2022

Yeah, there's already an open PR to move to parts2. I opened this issue because I wasn't sure whether the change was intentional or a bug. Since it is intentional, I would suggest the analyzer version should be bumped to 5.0.0 since this:

LibraryElement.parts stopped including units which don't point back at the library, i.e. don't have a part of name; or part of uri; directives. A not existing file has this property.

breaks backwards compatibility.

@scheglov
Copy link
Contributor

I agree that this was a breaking change. But it is too late to publish it as 5.0.0.

I ran this change over large number of clients, and it affected only one in a tiny way. So, I would recommend for an affected client to publish a new version that restricts supported analyzer version to versions before 4.3.0.

@jmatth
Copy link
Author

jmatth commented Jul 29, 2022

But it is too late to publish it as 5.0.0.

Might not be, it's possible to retract versions within 7 days so there may be a few hours left to retract 4.3.0 and 4.3.1. I'm guessing that's not happening though so we can probably just close this issue. Thanks for your help and responding so quickly.

In case anyone ends up here from Github issue search or googling the same problem, here's at least one way to access the URIs of part directives using parts2:

// CaseElement clazz = ...;
Iterable<Uri> partUris = clazz.library.parts2
    .map((e) => e.uri)
    .whereType<DirectiveUriWithRelativeUri>()
    .map((e) => e.relativeUri);

Or if you just need the URI as a string:

// CaseElement clazz = ...;
Iterable<String> partUriStrings = clazz.library.parts2
    .map((e) => e.uri)
    .whereType<DirectiveUriWithRelativeUriString>()
    .map((e) => e.relativeUriString);

See also the discussion at Milad-Akarie/auto_route_library#1165

@keertip keertip added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Aug 1, 2022
@keertip
Copy link
Contributor

keertip commented Aug 1, 2022

closing as there is a workaround.

@keertip keertip closed this as completed Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants