sdk
sdk copied to clipboard
[analyzer] strange `ambiguous_import` report
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

is it supposed to be this way?
Here is a better screenshot with double empty mixins 🤷♂️

My thought is 'no' it shouldn't be reporting an issue there.
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.
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?
I'll double-check tomorrow if the issue was present before the update just to be sure, but I don't remember anything red.
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),
]);
}
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.
Noticed another issue though.
Dart SDK version: 2.19.6 (stable):
Dart 3.0.0-417.4.beta:
Looks like a regression to me.
Is it? Or it's expected? Want a separate issue?
And explicit type is marked unnecessary.
The type inference issue seems quite different to me. So, please, open a new issue.
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.
I think this is less serous issue than we thought originally, so set the priority accordingly.