Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9c89ce3

Browse files
author
Dart CI
committed
Version 2.11.0-182.0.dev
Merge commit '68fd2a9d52802bdcc2db31d9b31a2e128b392f30' into 'dev'
2 parents ddbeaab + 68fd2a9 commit 9c89ce3

File tree

521 files changed

+5548
-1132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

521 files changed

+5548
-1132
lines changed

CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
### Core libraries
44

5+
#### `dart:io`
6+
7+
* `HttpRequest` will now correctly follow HTTP 308 redirects
8+
(`HttpStatus.permanentRedirect`).
9+
510
### Dart VM
611

712
### Dart2JS
813

9-
* Removed `--no-defer-class-types` and `--no-new-deferred-split'.
14+
* Removed `--no-defer-class-types` and `--no-new-deferred-split`.
1015

1116
### Tools
1217

@@ -18,8 +23,13 @@
1823

1924
#### Linter
2025

21-
Updated the Linter to `0.1.119`, which includes:
26+
Updated the Linter to `0.1.120`, which includes:
2227

28+
* New lint: `cast_nullable_to_non_nullable`.
29+
* New lint: `null_check_on_nullable_type_parameter`.
30+
* New lint: `tighten_type_of_initializing_formals`.
31+
* Updates to `public_member_apis` to check generic type aliases.
32+
* (Internal): updates to adopt new analyzer APIs.
2333
* Fixed `close_sinks` to handle `this`-prefixed property accesses.
2434
* New lint: `unnecessary_null_checks`.
2535
* Fixed `unawaited_futures` to handle `Future` subtypes.
@@ -157,9 +167,14 @@ applications (issue [flutter/flutter#63038][]).
157167
* [Abstract Unix Domain Socket][] is supported on Linux/Android now. Using an
158168
`InternetAddress` with `address` starting with '@' and type being
159169
`InternetAddressType.Unix` will create an abstract Unix Domain Socket.
170+
* On Windows, file APIs can now handle files and directories identified by
171+
long paths (greater than 260 characters). It complies with all restrictions
172+
from [Long Path on Windows][]. Note that `Directory.current` does not work
173+
with long path.
160174

161175
[#42006]: https://github.com/dart-lang/sdk/issues/42006
162176
[Abstract Unix Domain Socket]: http://man7.org/linux/man-pages/man7/unix.7.html
177+
[Long Path on Windows]: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
163178

164179
#### `dart:html`
165180

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ vars = {
113113
"intl_tag": "0.16.1",
114114
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
115115
"json_rpc_2_rev": "8f189db8f0c299187a0e8fa959dba7e9b0254be5",
116-
"linter_tag": "0.1.119",
116+
"linter_tag": "0.1.120",
117117
"logging_rev": "1590ba0b648a51e7eb3895c612e4b72f72623b6f",
118118
"markupsafe_rev": "8f45f5cfa0009d2a70589bcda0349b8cb2b72783",
119119
"markdown_rev": "dbeafd47759e7dd0a167602153bb9c49fb5e5fe7",

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ class FlowAnalysisDebug<Node, Statement extends Node, Expression, Variable,
10501050

10511051
@override
10521052
bool isUnassigned(Variable variable) {
1053-
return _wrap('isUnassigned($variable)', () => _wrapped.isAssigned(variable),
1053+
return _wrap(
1054+
'isUnassigned($variable)', () => _wrapped.isUnassigned(variable),
10541055
isQuery: true);
10551056
}
10561057

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,17 +1111,17 @@ const Code<Null> codeConstConstructorLateFinalFieldCause =
11111111
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
11121112
const MessageCode messageConstConstructorLateFinalFieldCause =
11131113
const MessageCode("ConstConstructorLateFinalFieldCause",
1114-
severity: Severity.context,
1115-
message: r"""Field is late, but constructor is 'const'.""");
1114+
severity: Severity.context, message: r"""This constructor is const.""");
11161115

11171116
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
11181117
const Code<Null> codeConstConstructorLateFinalFieldError =
11191118
messageConstConstructorLateFinalFieldError;
11201119

11211120
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1122-
const MessageCode messageConstConstructorLateFinalFieldError =
1123-
const MessageCode("ConstConstructorLateFinalFieldError",
1124-
message: r"""Constructor is marked 'const' so fields can't be late.""");
1121+
const MessageCode messageConstConstructorLateFinalFieldError = const MessageCode(
1122+
"ConstConstructorLateFinalFieldError",
1123+
message:
1124+
r"""Can't have a late final field in a class with a const constructor.""");
11251125

11261126
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
11271127
const Code<Null> codeConstConstructorNonFinalField =

pkg/_fe_analyzer_shared/test/flow_analysis/definite_unassignment/data/late_initializer.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// doesn't execute immediately, so it may refer to other late variables that
77
// aren't assigned yet.
88

9+
void use(Object? x) {}
10+
911
eagerInitializerRefersToLateVar() {
1012
late int x;
1113
int y = /*unassigned*/ x;
@@ -17,3 +19,9 @@ lateInitializerRefersToLateVar() {
1719
late int y = x;
1820
x = 0;
1921
}
22+
23+
lateInitializerIsAssignment() {
24+
late int y;
25+
late int z1 = y = 3;
26+
use(y);
27+
}

pkg/_fe_analyzer_shared/test/flow_analysis/type_promotion/data/initialization.dart

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ localVariable_ifElse_sameTypes(bool a) {
5555
x;
5656
}
5757

58-
localVariable_initialized_nonNull() {
59-
num? x = 0;
60-
/*num*/ x;
61-
x = null;
62-
x;
63-
}
64-
65-
localVariable_initialized_nonNull_final() {
66-
final num? x = 0;
67-
x;
68-
}
69-
7058
localVariable_initialized_promoted_type_var<T>(T t) {
7159
if (t is num) {
7260
var x = /*T & num*/ t;
@@ -106,13 +94,13 @@ localVariable_initialized_unpromoted_type_var_with_bound<T extends num?>(T t) {
10694

10795
localVariable_initialized_promoted_type_var_typed<T>(T t) {
10896
if (t is num) {
109-
// This should promote to `T & Object`, because that's the non-nullable
110-
// version of T, but it shouldn't promote to `T & num`.
97+
// TODO(paulberry): This should promote to `T & Object`, because that's the
98+
// non-nullable version of T, but it shouldn't promote to `T & num`.
11199
T x = /*T & num*/ t;
112-
/*T & Object*/ x;
100+
x;
113101
// Check that `T & Object` is a type of interest by promoting and then
114102
// writing to it
115-
if (/*T & Object*/ x is int) {
103+
if (x is int) {
116104
/*T & int*/ x;
117105
x = /*T & num*/ t;
118106
/*T & Object*/ x;

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar
7070
/// A fix producer that produces changes to fix multiple diagnostics.
7171
class BulkFixProcessor {
7272
/// A map from the name of a lint rule to a list of generators used to create
73-
/// the correction producer used to build a fix for that diagnostic. Most
74-
/// entries will have only one generator. In cases where there is more than
75-
/// one, they will be applied in series and the expectation is that only one
76-
/// will produce a change for a given fix. If more than one change is produced
77-
/// the result will almost certainly be invalid code. The generators used for
78-
/// non-lint diagnostics are in the [nonLintProducerMap].
73+
/// the correction producer used to build a fix for that diagnostic. The
74+
/// generators used for non-lint diagnostics are in the [nonLintProducerMap].
75+
///
76+
/// Most entries will have only one generator. In cases where there is more
77+
/// than one, they will be applied in series and the expectation is that only
78+
/// one will produce a change for a given fix. If more than one change is
79+
/// produced the result will almost certainly be invalid code.
7980
static const Map<String, List<ProducerGenerator>> lintProducerMap = {
8081
LintNames.annotate_overrides: [
8182
AddOverride.newInstance,
@@ -241,9 +242,13 @@ class BulkFixProcessor {
241242
],
242243
};
243244

244-
/// A map from error codes to a list of generators used to create multiple
245+
/// A map from an error code to a list of generators used to create multiple
245246
/// correction producers used to build fixes for those diagnostics. The
246247
/// generators used for lint rules are in the [lintMultiProducerMap].
248+
///
249+
/// The expectation is that only one of the correction producers will produce
250+
/// a change for a given fix. If more than one change is produced the result
251+
/// will almost certainly be invalid code.
247252
static const Map<ErrorCode, List<MultiProducerGenerator>>
248253
nonLintMultiProducerMap = {
249254
CompileTimeErrorCode.EXTENDS_NON_CLASS: [
@@ -304,14 +309,12 @@ class BulkFixProcessor {
304309
CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD: [
305310
DataDriven.newInstance,
306311
],
307-
// TODO(brianwilkerson) Uncomment the entries below as we add tests for
308-
// them.
309-
// HintCode.DEPRECATED_MEMBER_USE: [
310-
// DataDriven.newInstance,
311-
// ],
312-
// HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE: [
313-
// DataDriven.newInstance,
314-
// ],
312+
HintCode.DEPRECATED_MEMBER_USE: [
313+
DataDriven.newInstance,
314+
],
315+
HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE: [
316+
DataDriven.newInstance,
317+
],
315318
HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD: [
316319
DataDriven.newInstance,
317320
],
@@ -322,16 +325,22 @@ class BulkFixProcessor {
322325
/// lint rules are in the [lintProducerMap].
323326
static const Map<ErrorCode, ProducerGenerator> nonLintProducerMap = {};
324327

328+
/// Information about the workspace containing the libraries in which changes
329+
/// will be produced.
325330
final DartChangeWorkspace workspace;
326331

327332
/// The change builder used to build the changes required to fix the
328333
/// diagnostics.
329334
ChangeBuilder builder;
330335

336+
/// Initialize a newly created processor to create fixes for diagnostics in
337+
/// libraries in the [workspace].
331338
BulkFixProcessor(this.workspace) {
332339
builder = ChangeBuilder(workspace: workspace);
333340
}
334341

342+
/// Return a change builder that has been used to create fixes for the
343+
/// diagnostics in the libraries at the given [libraryPaths].
335344
Future<ChangeBuilder> fixErrorsInLibraries(List<String> libraryPaths) async {
336345
for (var path in libraryPaths) {
337346
var session = workspace.getSession(path);
@@ -344,8 +353,10 @@ class BulkFixProcessor {
344353
return builder;
345354
}
346355

347-
Future<void> _fixErrorsInLibrary(ResolvedLibraryResult libraryResult) async {
348-
for (var unitResult in libraryResult.units) {
356+
/// Use the change [builder] to create fixes for the diagnostics in the
357+
/// library associated with the analysis [result].
358+
Future<void> _fixErrorsInLibrary(ResolvedLibraryResult result) async {
359+
for (var unitResult in result.units) {
349360
final fixContext = DartFixContextImpl(
350361
workspace,
351362
unitResult,
@@ -358,14 +369,17 @@ class BulkFixProcessor {
358369
}
359370
}
360371

372+
/// Use the change [builder] and the [fixContext] to create a fix for the
373+
/// given [diagnostic] in the compilation unit associated with the analysis
374+
/// [result].
361375
Future<void> _fixSingleError(DartFixContext fixContext,
362-
ResolvedUnitResult unitResult, AnalysisError error) async {
376+
ResolvedUnitResult result, AnalysisError diagnostic) async {
363377
var context = CorrectionProducerContext(
364378
dartFixContext: fixContext,
365-
diagnostic: error,
366-
resolvedResult: unitResult,
367-
selectionOffset: error.offset,
368-
selectionLength: error.length,
379+
diagnostic: diagnostic,
380+
resolvedResult: result,
381+
selectionOffset: diagnostic.offset,
382+
selectionLength: diagnostic.length,
369383
workspace: workspace,
370384
);
371385

@@ -379,7 +393,7 @@ class BulkFixProcessor {
379393
await producer.compute(builder);
380394
}
381395

382-
var errorCode = error.errorCode;
396+
var errorCode = diagnostic.errorCode;
383397
if (errorCode is LintCode) {
384398
var generators = lintProducerMap[errorCode.name];
385399
if (generators != null) {
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
6+
import 'package:analysis_server/src/services/correction/fix.dart';
7+
import 'package:analyzer/dart/ast/ast.dart';
8+
import 'package:analyzer/dart/ast/token.dart';
9+
import 'package:analyzer/error/error.dart';
10+
import 'package:analyzer/source/source_range.dart';
11+
import 'package:analyzer/src/dart/error/hint_codes.dart';
12+
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
13+
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
14+
import 'package:analyzer_plugin/utilities/range_factory.dart';
15+
16+
class RemoveComparison extends CorrectionProducer {
17+
@override
18+
FixKind get fixKind => DartFixKind.REMOVE_COMPARISON;
19+
20+
/// Return `true` if the null comparison will always return `false`.
21+
bool get _conditionIsFalse =>
22+
(diagnostic as AnalysisError).errorCode ==
23+
HintCode.UNNECESSARY_NULL_COMPARISON_FALSE;
24+
25+
/// Return `true` if the null comparison will always return `true`.
26+
bool get _conditionIsTrue =>
27+
(diagnostic as AnalysisError).errorCode ==
28+
HintCode.UNNECESSARY_NULL_COMPARISON_TRUE;
29+
30+
@override
31+
Future<void> compute(ChangeBuilder builder) async {
32+
if (node is! BinaryExpression) {
33+
return;
34+
}
35+
var binaryExpression = node as BinaryExpression;
36+
var parent = binaryExpression.parent;
37+
if (parent is AssertInitializer && _conditionIsTrue) {
38+
var constructor = parent.parent as ConstructorDeclaration;
39+
var list = constructor.initializers;
40+
if (list.length == 1) {
41+
await builder.addDartFileEdit(file, (builder) {
42+
builder.addDeletion(range.endEnd(constructor.parameters, parent));
43+
});
44+
} else {
45+
await builder.addDartFileEdit(file, (builder) {
46+
builder.addDeletion(range.nodeInList(list, parent));
47+
});
48+
}
49+
} else if (parent is AssertStatement && _conditionIsTrue) {
50+
await builder.addDartFileEdit(file, (builder) {
51+
builder.addDeletion(utils.getLinesRange(range.node(parent)));
52+
});
53+
} else if (parent is BinaryExpression) {
54+
if (parent.operator.type == TokenType.AMPERSAND_AMPERSAND &&
55+
_conditionIsTrue) {
56+
await _removeOperatorAndOperand(builder, parent, node);
57+
} else if (parent.operator.type == TokenType.BAR_BAR &&
58+
_conditionIsFalse) {
59+
await _removeOperatorAndOperand(builder, parent, node);
60+
}
61+
} else if (parent is IfStatement) {
62+
if (parent.elseStatement == null && _conditionIsTrue) {
63+
var body = _extractBody(parent);
64+
body = utils.indentSourceLeftRight(body);
65+
await builder.addDartFileEdit(file, (builder) {
66+
builder.addSimpleReplacement(
67+
range.startOffsetEndOffset(
68+
parent.offset, utils.getLineContentEnd(parent.end)),
69+
body);
70+
});
71+
}
72+
}
73+
}
74+
75+
String _extractBody(IfStatement statement) {
76+
var body = statement.thenStatement;
77+
if (body is Block) {
78+
var statements = body.statements;
79+
return utils.getRangeText(range.startOffsetEndOffset(
80+
statements.first.offset,
81+
utils.getLineContentEnd(statements.last.end)));
82+
}
83+
return utils.getNodeText(body);
84+
}
85+
86+
/// Use the [builder] to add an edit to delete the operator and given
87+
/// [operand] from the [binary] expression.
88+
Future<void> _removeOperatorAndOperand(ChangeBuilder builder,
89+
BinaryExpression binary, Expression operand) async {
90+
SourceRange operatorAndOperand;
91+
if (binary.leftOperand == node) {
92+
operatorAndOperand = range.startStart(node, binary.rightOperand);
93+
} else {
94+
operatorAndOperand = range.endEnd(binary.leftOperand, node);
95+
}
96+
await builder.addDartFileEdit(file, (builder) {
97+
builder.addDeletion(operatorAndOperand);
98+
});
99+
}
100+
101+
/// Return an instance of this class. Used as a tear-off in `FixProcessor`.
102+
static RemoveComparison newInstance() => RemoveComparison();
103+
}

pkg/analysis_server/lib/src/services/correction/fix.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ class DartFixKind {
335335
FixKind('dart.fix.remove.argument', 50, 'Remove argument');
336336
static const REMOVE_AWAIT =
337337
FixKind('dart.fix.remove.await', 50, 'Remove await');
338+
static const REMOVE_COMPARISON =
339+
FixKind('dart.fix.remove.comparison', 50, 'Remove comparison');
338340
static const REMOVE_CONST =
339341
FixKind('dart.fix.remove.const', 50, 'Remove const');
340342
static const REMOVE_DEAD_CODE =

0 commit comments

Comments
 (0)