sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[analyzer] strange `ambiguous_import` report

Open incendial opened this issue 2 years ago • 12 comments

Hey!

Just upgraded to Dart 3.0.0-417.4.beta and now see some strange reports for code inside the documentation comments https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/lib/src/dart/ast/ast.dart#L5528 Screenshot 2023-05-08 at 21 09 11

is it supposed to be this way?

incendial avatar May 08 '23 17:05 incendial

Here is a better screenshot with double empty mixins 🤷‍♂️ Screenshot 2023-05-08 at 21 16 51

incendial avatar May 08 '23 17:05 incendial

My thought is 'no' it shouldn't be reporting an issue there.

bwilkerson avatar May 08 '23 17:05 bwilkerson

I cannot reproduce this, and AFAIK we have never seen anything like this before.

Also, the analyzer package itself has not yet enabled Dart 3.0, so it is probably unrelated to Dart 3.0 features, although of course we cannot rule out that some implementation changes caused it.

scheglov avatar May 08 '23 19:05 scheglov

I have a fork, so haven't checked if the problem actually appears in the original codebase.

so it is probably unrelated to Dart 3.0 features

I started seeing it only after "flutter channel beta" / "flutter upgrade" which gave me "Dart 3.0.0-417.4.beta".

I'm more confused by the message and two empty mixin on, to be honest and not that it happens in the analyzer codebase. Do you need any additional info from me?

incendial avatar May 08 '23 19:05 incendial

I'll double-check tomorrow if the issue was present before the update just to be sure, but I don't remember anything red.

incendial avatar May 08 '23 19:05 incendial

It seems that we have a state with misconfigured language features for these libraries, that makes the parser to produce mixins with empty names. And then [ is parsed as a CommentReference with a synthetic (empty) identifier.

I can reproduce something like this, but with non-synthetic names.

  solo_test_X() async {
    newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');

    newFile('$testPackageLibPath/b.dart', r'''
class A {}
''');

    await assertErrorsInCode(r'''
import 'a.dart';
import 'b.dart';

/// Test '[A' it.
void f() {}
''', [
      error(CompileTimeErrorCode.AMBIGUOUS_IMPORT, 46, 1),
    ]);
  }

scheglov avatar May 08 '23 19:05 scheglov

Interesting, now I don't see any issues with the same setup. I did upstream all missing changes though. Let me know if you need more info from me.

incendial avatar May 09 '23 16:05 incendial

Noticed another issue though.

Dart SDK version: 2.19.6 (stable): Screenshot 2023-05-09 at 20 44 53

Dart 3.0.0-417.4.beta: Screenshot 2023-05-09 at 20 42 04

Looks like a regression to me.

Is it? Or it's expected? Want a separate issue?

incendial avatar May 09 '23 16:05 incendial

And explicit type is marked unnecessary. Screenshot 2023-05-09 at 20 59 38

incendial avatar May 09 '23 17:05 incendial

The type inference issue seems quite different to me. So, please, open a new issue.

scheglov avatar May 09 '23 19:05 scheglov

I can reproduce it with

  solo_test_X() async {
    newFile('$testPackageLibPath/a.dart', r'''
mixin
''');

    newFile('$testPackageLibPath/b.dart', r'''
mixin
''');

    await assertErrorsInCode(r'''
import 'a.dart';
import 'b.dart';

/// Test '[' it.
void f() {}
''', [
      error(CompileTimeErrorCode.AMBIGUOUS_IMPORT, 46, 0),
    ]);
  }

But it looks to be a very small case - you have to have invalid syntax in imported libraries.

Parsing for CommentReference inside quotes '' is unfortunate.

And we probably should not report diagnostics for comment references, specifically AMBIGUOUS_IMPORT. We try to prevent this while resolving, but do nothing during error reporting.

scheglov avatar May 09 '23 19:05 scheglov

I think this is less serous issue than we thought originally, so set the priority accordingly.

scheglov avatar May 09 '23 19:05 scheglov