Skip to content

"part" in lib and "part of" in bin breaks analyzer #52951

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

Open
treeplate opened this issue Jul 16, 2023 · 2 comments
Open

"part" in lib and "part of" in bin breaks analyzer #52951

treeplate opened this issue Jul 16, 2023 · 2 comments
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@treeplate
Copy link

Dart SDK version: 3.1.0-246.0.dev (dev) (Fri Jun 23 01:04:39 2023 -0700) on "macos_arm64"
How to reproduce issue:
dart create foo
in foo/lib/foo.dart:

library foo;

part '../bin/foo.dart';

int x = 3;

in foo/bin/foo.dart:

part of '../lib/foo.dart';

void main(List<String> arguments) {
  print(x);
}

remove the test directory.
dart analyze:

Analyzing foo...              0.5s

  error • bin/foo.dart:4:9 • Undefined name 'x'. Try correcting the name to one that is defined, or defining the name. • undefined_identifier
  error • lib/foo.dart:3:6 • Target of URI doesn't exist: 'package:foo/bin/foo.dart'. Try creating the file referenced by the URI, or try using a URI for a file that
          does exist. • uri_does_not_exist

2 issues found.

dart run:

Building package executable... 
Built foo:foo.
3
@lrhn
Copy link
Member

lrhn commented Jul 16, 2023

First: don't do that. Do not have dependencies that go into or out of lib using relative references. Always use package: URIs to refer to files in lib from the outside. Never refer to files outside of lib from inside.

I'm not sure anyone is wrong, they're just helping you in different ways.

The analyser is giving the library file the URI package:foo/foo.dart. That's reasonable, and prevents a lot of problems.

Then it tries to resolve ../bin/foo.dart against that package URI, giving package:foo/bin/foo.dart, because that's how a relative path is resolved against a package URI.

That file doesn't exist.

Resolving in the other direction is actually fine, because no package URI is involved, it's all local files. I'm guessing the analyzer fails that because it only gives one URI to each file, or because it helps you avoid file paths into lib/.

The dart run is actually wrong, because part files are not valid dart scripts. You should only be allowed to run a library file.

@eernstg
Copy link
Member

eernstg commented Jul 17, 2023

Cf. #52575

@a-siva a-siva added the legacy-area-analyzer Use area-devexp instead. label Jul 17, 2023
@pq pq added the P3 A lower priority bug or feature request label Jul 17, 2023
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 27, 2024
@srawlins srawlins added the dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec label Oct 29, 2024
@bwilkerson bwilkerson added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants