Skip to content

Commit

Permalink
Version 3.7.0-308.0.dev
Browse files Browse the repository at this point in the history
Merge a1f5ee9 into dev
  • Loading branch information
Dart CI committed Jan 8, 2025
2 parents ba91091 + a1f5ee9 commit 91af235
Show file tree
Hide file tree
Showing 35 changed files with 269 additions and 60 deletions.
4 changes: 0 additions & 4 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ vars = {
"flute_rev": "e4ea0459a7debae5e9592c85141707b01fac86c9",
"glob_rev": "eee18d1a577d5f965f6afbbd251798e065dced43",
"http_rev": "6ecd13a88b82c2fdc8a555f218bafb0ad0370f51",
"http_multi_server_rev": "2b84a4500460d1f3848e54b47169bdf8c504dded",
"intl_rev": "5d65e3808ce40e6282e40881492607df4e35669f",
"leak_tracker_rev": "f5620600a5ce1c44f65ddaa02001e200b096e14c", # manually rolled
"markdown_rev": "19aaded4300d24bedcbf52ade792b203ddf030b0",
Expand Down Expand Up @@ -369,9 +368,6 @@ deps = {

Var("dart_root") + "/third_party/pkg/http":
Var("dart_git") + "http.git" + "@" + Var("http_rev"),
Var("dart_root") + "/third_party/pkg/http_multi_server":
Var("dart_git") + "http_multi_server.git" +
"@" + Var("http_multi_server_rev"),
Var("dart_root") + "/third_party/pkg/intl":
Var("dart_git") + "intl.git" + "@" + Var("intl_rev"),
Var("dart_root") + "/third_party/pkg/leak_tracker":
Expand Down
1 change: 0 additions & 1 deletion pkg/analysis_server/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ lib/src/services/refactoring/legacy/refactoring_manager.dart
lib/src/services/refactoring/legacy/rename.dart
lib/src/services/refactoring/legacy/rename_import.dart
lib/src/services/search/element_visitors.dart
test/abstract_single_unit.dart
test/services/refactoring/legacy/abstract_rename.dart
test/services/search/element_visitors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AddKeyToConstructors extends ResolvedCorrectionProducer {
}
builder.write(className);
builder.write('({');
if (libraryElement2.featureSet.isEnabled(Feature.super_parameters)) {
if (isEnabled(Feature.super_parameters)) {
builder.write('super.key});');
} else {
builder.writeType(keyType);
Expand All @@ -115,9 +115,7 @@ class AddKeyToConstructors extends ResolvedCorrectionProducer {
if (keyType == null) {
return;
}
var superParameters = libraryElement2.featureSet.isEnabled(
Feature.super_parameters,
);
var superParameters = isEnabled(Feature.super_parameters);

void writeKey(DartEditBuilder builder) {
if (superParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AddSuperParameter extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
if (!libraryElement2.featureSet.isEnabled(Feature.super_parameters)) {
if (!isEnabled(Feature.super_parameters)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ConvertClassToEnum extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
if (!libraryElement2.featureSet.isEnabled(Feature.enhanced_enums)) {
if (!isEnabled(Feature.enhanced_enums)) {
// If the library doesn't support enhanced_enums then the class can't be
// converted.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ConvertToIfCaseStatement extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
if (!libraryElement2.featureSet.isEnabled(Feature.patterns)) {
if (!isEnabled(Feature.patterns)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ConvertToSuperParameters extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
if (!libraryElement2.featureSet.isEnabled(Feature.super_parameters)) {
if (!isEnabled(Feature.super_parameters)) {
// If the library doesn't support super_parameters then the change isn't
// appropriate.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConvertIfStatementToSwitchStatement extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
if (!libraryElement2.featureSet.isEnabled(Feature.patterns)) {
if (!isEnabled(Feature.patterns)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class ConvertToWildcardVariable extends ResolvedCorrectionProducer {
if (!wildcardVariablesEnabled) return;

var node = this.node;

if (node is FormalParameter) {
await computeFormalParameterConversion(builder, node);
return;
}

if (node is! VariableDeclaration) return;

var nameToken = node.name;
Expand All @@ -55,4 +61,13 @@ class ConvertToWildcardVariable extends ResolvedCorrectionProducer {
}
});
}

Future<void> computeFormalParameterConversion(
ChangeBuilder builder,
FormalParameter node,
) async {
await builder.addDartFileEdit(file, (builder) {
builder.addSimpleReplacement(range.token(node.name!), '_');
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _CreateConstructor extends ResolvedCorrectionProducer {
var buffer = StringBuffer();
buffer.write('super');
var constructorName = _constructor.name3;
if (libraryElement2.featureSet.isEnabled(Feature.super_parameters)) {
if (isEnabled(Feature.super_parameters)) {
if (constructorName != null && constructorName != 'new') {
buffer.write('.');
buffer.write(constructorName);
Expand All @@ -90,7 +90,7 @@ class _CreateConstructor extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
if (libraryElement2.featureSet.isEnabled(Feature.super_parameters)) {
if (isEnabled(Feature.super_parameters)) {
await _computeWithSuperParameters(builder);
} else {
await _computeWithoutSuperParameters(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MoveAnnotationToLibraryDirective extends ResolvedCorrectionProducer {
return;
}

if (!libraryElement2.featureSet.isEnabled(Feature.unnamedLibraries)) {
if (!isEnabled(Feature.unnamedLibraries)) {
// If the library doesn't support unnamed libraries, then we cannot add
// a new library directive; we don't know what to name it.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MoveDocCommentToLibraryDirective extends ResolvedCorrectionProducer {
var firstDirective = compilationUnit.directives.firstOrNull;
if (firstDirective is LibraryDirective) {
await _moveToExistingLibraryDirective(builder, comment, firstDirective);
} else if (libraryElement2.featureSet.isEnabled(Feature.unnamedLibraries)) {
} else if (isEnabled(Feature.unnamedLibraries)) {
await _moveToNewLibraryDirective(builder, comment, compilationUnit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ LintCode.unnecessary_this:
LintCode.unnecessary_to_list_in_spreads:
status: hasFix
LintCode.unnecessary_underscores:
status: needsFix
status: hasFix
LintCode.unreachable_from_main:
status: hasFix
LintCode.unrelated_type_equality_checks_in_expression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ final _builtInLintProducers = <LintCode, List<ProducerGenerator>>{
],
LinterLintCode.unnecessary_to_list_in_spreads: [RemoveToList.new],
LinterLintCode.unnecessary_this: [RemoveThisExpression.new],
LinterLintCode.unnecessary_underscores: [ConvertToWildcardVariable.new],
LinterLintCode.unreachable_from_main: [RemoveUnusedElement.new],
LinterLintCode.use_colored_box: [ReplaceContainerWithColoredBox.new],
LinterLintCode.use_decorated_box: [ReplaceWithDecoratedBox.new],
Expand Down
10 changes: 3 additions & 7 deletions pkg/analysis_server/test/abstract_single_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/file_system.dart';
Expand All @@ -13,7 +12,6 @@ import 'package:analyzer/src/test_utilities/find_element.dart';
import 'package:analyzer/src/test_utilities/find_element2.dart';
import 'package:analyzer/src/test_utilities/find_node.dart';
import 'package:analyzer/src/utilities/extensions/analysis_session.dart';
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:test/test.dart';

import 'abstract_context.dart';
Expand All @@ -26,13 +24,11 @@ class AbstractSingleUnitTest extends AbstractContextTest {
late ResolvedLibraryResult? testLibraryResult;
late ResolvedUnitResult testAnalysisResult;
late CompilationUnit testUnit;
late CompilationUnitElement testUnitElement;
late LibraryElement testLibraryElement;
late FindNode findNode;
late FindElement findElement;
late FindElement2 findElement2;

LibraryElement2 get testLibraryElement2 => testLibraryElement.asElement2;
late LibraryElement2 testLibraryElement;

void addTestSource(String code) {
testCode = code;
Expand Down Expand Up @@ -84,8 +80,8 @@ class AbstractSingleUnitTest extends AbstractContextTest {
isEmpty,
);
}
testUnitElement = testUnit.declaredElement!;
testLibraryElement = testUnitElement.library;

testLibraryElement = testUnit.declaredFragment!.element;
findNode = FindNode(testCode, testUnit);
findElement = FindElement(testUnit);
findElement2 = FindElement2(testUnit);
Expand Down
37 changes: 27 additions & 10 deletions pkg/analysis_server/test/lsp/server_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,15 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin, LspEditHelpersMixin
var firstRequest = requestsFromServer.firstWhere((n) => n.method == method);
await f();

var requestFromServer = await firstRequest.timeout(timeout);
var requestFromServer = await firstRequest.timeout(
timeout,
onTimeout:
() =>
throw TimeoutException(
'Did not receive the expected $method request from the server in the timeout period',
timeout,
),
);

expect(requestFromServer, isNotNull);
return requestFromServer;
Expand Down Expand Up @@ -1174,6 +1182,7 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin, LspEditHelpersMixin
Duration timeout = const Duration(seconds: 5),
}) async {
late Future<T> outboundRequest;
Object? outboundRequestError;

// Run [f] and wait for the incoming request from the server.
var incomingRequest = await expectRequest(method, () {
Expand All @@ -1182,15 +1191,23 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin, LspEditHelpersMixin
outboundRequest = f();

// Because we don't await this future until "later", if it throws the
// error is treated as unhandled and will fail the test. Attaching an
// error handler prevents that, though since the Future completed with
// an error it will still be handled as such when the future is later
// awaited.

// TODO(srawlins): Fix this static error.
// ignore: body_might_complete_normally_catch_error
outboundRequest.catchError((_) {});
});
// error is treated as unhandled and will fail the test even if expected.
// Instead, capture the error and suppress it. But if we time out (in
// which case we will never return outboundRequest), then we'll raise this
// error.
outboundRequest.then(
(_) {},
onError: (e) {
outboundRequestError = e;
return null;
},
);
}, timeout: timeout).catchError((Object timeoutException) {
// We timed out waiting for the request from the server. Probably this is
// because our outbound request for some reason, so if we have an error
// for that, then throw it. Otherwise, propogate the timeout.
throw outboundRequestError ?? timeoutException;
}, test: (e) => e is TimeoutException);

// Handle the request from the server and send the response back.
var clientsResponse = await handler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ import 'package:ddd/ddd.dart';
await addLibraryImports(
testAnalysisResult.session,
change,
testLibraryElement2,
testLibraryElement,
newLibraries.toSet(),
);
var testEdit = change.getFileEdit(testFile.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ part of the.new.name;
}

void _createRenameRefactoring() {
createRenameRefactoringForElement2(testLibraryElement2);
createRenameRefactoringForElement2(testLibraryElement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:analysis_server/src/services/search/element_visitors.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

Expand All @@ -17,6 +18,8 @@ void main() {

@reflectiveTest
class FindElementByNameOffsetTest extends AbstractSingleUnitTest {
Element get testUnitElement => testLibraryElement.asElement;

Future<void> test_class() async {
await resolveTestCode(r'''
class AAA {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:linter/src/lint_names.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'fix_processor.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConvertToWildcardVariableTest);
defineReflectiveTests(ConvertUnnecessaryUnderscoresTest);
});
}

Expand Down Expand Up @@ -116,3 +118,36 @@ void f() {
await assertNoFix();
}
}

@reflectiveTest
class ConvertUnnecessaryUnderscoresTest extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.CONVERT_TO_WILDCARD_VARIABLE;

@override
String get lintCode => LintNames.unnecessary_underscores;

Future<void> test_functionParameter() async {
await resolveTestCode(r'''
void f(int __) {}
''');
await assertHasFix(r'''
void f(int _) {}
''');
}

Future<void> test_localVariable() async {
await resolveTestCode(r'''
void f() {
// ignore: UNUSED_LOCAL_VARIABLE
int __ = 0;
}
''');
await assertHasFix(r'''
void f() {
// ignore: UNUSED_LOCAL_VARIABLE
int _ = 0;
}
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/src/utilities/selection.dart';
import 'package:analyzer/dart/analysis/analysis_options.dart';
import 'package:analyzer/dart/analysis/code_style_options.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
Expand Down Expand Up @@ -613,6 +614,9 @@ abstract class ResolvedCorrectionProducer
// We don't know.
return null;
}

bool isEnabled(Feature feature) =>
libraryElement2.featureSet.isEnabled(feature);
}

final class StubCorrectionProducerContext implements CorrectionProducerContext {
Expand Down
4 changes: 4 additions & 0 deletions pkg/compiler/lib/src/closure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ abstract class ClosureData {
/// the SSA builder.
CapturedScope getCapturedScope(MemberEntity entity);

/// Look up scope information about a block. Used by the SSA builder to box
/// variables if needed.
CapturedScope getCapturedBlockScope(ir.Block node);

/// If [entity] is a closure call method or closure signature method, the
/// original enclosing member is returned. Otherwise [entity] is returned.
///
Expand Down
5 changes: 5 additions & 0 deletions pkg/compiler/lib/src/io/kernel_source_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ class KernelSourceInformationBuilder implements SourceInformationBuilder {
return _buildTreeNode(node);
}

@override
SourceInformation buildBlock(ir.TreeNode node) {
return _buildTreeNode(node);
}

@override
SourceInformation buildCall(
covariant ir.TreeNode receiver,
Expand Down
Loading

0 comments on commit 91af235

Please sign in to comment.