Skip to content

Commit

Permalink
Version 3.6.0-62.0.dev
Browse files Browse the repository at this point in the history
Merge 11827c8 into dev
  • Loading branch information
Dart CI committed Jul 19, 2024
2 parents e9d3dc0 + 11827c8 commit 9087eea
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vars = {

# co19 is a cipd package automatically generated for each co19 commit.
# Use tests/co19/update.sh to update this hash.
"co19_rev": "9f8dbe998ccaa2326f7be7fc157c242fdc1fa421",
"co19_rev": "683767908d2ddbde3de5e5e8e6cd04904ba71797",

# The internal benchmarks to use. See go/dart-benchmarks-internal
"benchmarks_internal_rev": "3bd6bc6d207dfb7cf687537e819863cf9a8f2470",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class ImportLibrary extends MultiCorrectionProducer {
ImportLibrary.forExtensionMember({required super.context})
: _importKind = _ImportKind.forExtensionMember;

/// Initialize a newly created instance that will add an import for an
/// extension type.
ImportLibrary.forExtensionType({required super.context})
: _importKind = _ImportKind.forExtensionType;

/// Initialize a newly created instance that will add an import for a
/// top-level function.
ImportLibrary.forFunction({required super.context})
Expand All @@ -47,20 +52,20 @@ class ImportLibrary extends MultiCorrectionProducer {
ImportLibrary.forTopLevelVariable({required super.context})
: _importKind = _ImportKind.forTopLevelVariable;

/// Initialize a newly created instance that will add an import for a type
/// (class, enum, mixin).
/// Initialize a newly created instance that will add an import for a
/// type-like declaration (class, enum, mixin, typedef), a constructor, a
/// static member of a declaration, or an enum value.
ImportLibrary.forType({required super.context})
: _importKind = _ImportKind.forType;

@override
Future<List<ResolvedCorrectionProducer>> get producers async {
// TODO(srawlins): static member? enum value? constructor? extension type?
// typedef?
return switch (_importKind) {
_ImportKind.dartAsync =>
_importLibrary(DartFixKind.IMPORT_ASYNC, Uri.parse('dart:async')),
_ImportKind.forExtension => await _producersForExtension(),
_ImportKind.forExtensionMember => await _producersForExtensionMember(),
_ImportKind.forExtensionType => await _producersForExtensionType(),
_ImportKind.forFunction => await _producersForFunction(),
_ImportKind.forTopLevelVariable => await _producersForTopLevelVariable(),
_ImportKind.forType => await _producersForType(),
Expand Down Expand Up @@ -263,9 +268,10 @@ class ImportLibrary extends MultiCorrectionProducer {

Future<List<ResolvedCorrectionProducer>> _producersForExtension() async {
if (node case SimpleIdentifier(:var name)) {
return await _importLibraryForElement(name, const [
ElementKind.EXTENSION,
]);
return await _importLibraryForElement(
name,
const [ElementKind.EXTENSION],
);
}

return const [];
Expand Down Expand Up @@ -308,6 +314,17 @@ class ImportLibrary extends MultiCorrectionProducer {
return producers;
}

Future<List<ResolvedCorrectionProducer>> _producersForExtensionType() async {
if (node case SimpleIdentifier(:var name)) {
return await _importLibraryForElement(
name,
const [ElementKind.EXTENSION_TYPE],
);
}

return const [];
}

Future<List<ResolvedCorrectionProducer>> _producersForFunction() async {
if (node case SimpleIdentifier(:var name, :var parent)) {
if (parent is MethodInvocation) {
Expand Down Expand Up @@ -412,6 +429,7 @@ enum _ImportKind {
dartAsync,
forExtension,
forExtensionMember,
forExtensionType,
forFunction,
forTopLevelVariable,
forType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ final _builtInNonLintMultiProducers = {
CompileTimeErrorCode.UNDEFINED_FUNCTION: [
DataDriven.new,
ImportLibrary.forExtension,
ImportLibrary.forExtensionType,
ImportLibrary.forFunction,
ImportLibrary.forType,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ void f() {
''');
}

Future<void> test_withExtensionType() async {
newFile('$testPackageLibPath/a.dart', '''
extension type ET(int it) {}
''');
await resolveTestCode('''
import 'a.dart' as prefix;
void f() {
prefix.ET(7);
ET(7);
}
''');
await assertHasFix('''
import 'a.dart' as prefix;
void f() {
prefix.ET(7);
prefix.ET(7);
}
''');
}

Future<void> test_withTopLevelVariable() async {
await resolveTestCode('''
import 'dart:math' as prefix;
Expand All @@ -94,6 +116,28 @@ void f() {
prefix.e;
prefix.pi;
}
''');
}

Future<void> test_withTypedef() async {
newFile('$testPackageLibPath/a.dart', '''
typedef T = int;
''');
await resolveTestCode('''
import 'a.dart' as prefix;
void f(num n) {
n is prefix.T;
n is T;
}
''');
await assertHasFix('''
import 'a.dart' as prefix;
void f(num n) {
n is prefix.T;
n is prefix.T;
}
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@ void f() {
''');
}

Future<void> test_extensionType_notImported() async {
newFile('$testPackageLibPath/lib.dart', '''
extension type ET(String it) {}
''');
await resolveTestCode('''
void f(String s) {
ET(s);
}
''');
await assertHasFix('''
import 'package:test/lib.dart';
void f(String s) {
ET(s);
}
''');
}

Future<void> test_invalidUri_interpolation() async {
newFile('$testPackageLibPath/lib.dart', r'''
class Test {
Expand Down Expand Up @@ -1003,6 +1021,25 @@ void f() {
''');
}

Future<void> test_withEnum_value() async {
newFile('$testPackageLibPath/lib.dart', '''
library lib;
enum E { one, two }
''');
await resolveTestCode('''
void f() {
E.one;
}
''');
await assertHasFix('''
import 'package:test/lib.dart';
void f() {
E.one;
}
''');
}

Future<void> test_withExtension_pub_this() async {
updateTestPubspecFile(r'''
name: test
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 6
PATCH 0
PRERELEASE 61
PRERELEASE 62
PRERELEASE_PATCH 0

0 comments on commit 9087eea

Please sign in to comment.