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

Commit e1a475a

Browse files
author
Dart CI
committed
Version 2.16.0-2.0.dev
Merge commit 'ac78f998830e08e82f47095ae3c5c9b30e7444db' into 'dev'
2 parents af386ed + ac78f99 commit e1a475a

36 files changed

+627
-179
lines changed

.dart_tool/package_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"constraint, update this by running tools/generate_package_config.dart."
1212
],
1313
"configVersion": 2,
14-
"generated": "2021-10-26T10:20:01.277340",
14+
"generated": "2021-11-10T09:58:01.876670",
1515
"generator": "tools/generate_package_config.dart",
1616
"packages": [
1717
{
@@ -124,7 +124,7 @@
124124
"name": "bazel_worker",
125125
"rootUri": "../third_party/pkg/bazel_worker",
126126
"packageUri": "lib/",
127-
"languageVersion": "2.12"
127+
"languageVersion": "2.14"
128128
},
129129
{
130130
"name": "benchmark_harness",

DEPS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ vars = {
7676
# Revisions of /third_party/* dependencies.
7777
"args_rev": "3b3f55766af13d895d2020ec001a28e8dc147f91",
7878
"async_rev": "80886150a5e6c58006c8ae5a6c2aa7108638e2a9",
79-
"bazel_worker_rev": "0885637b037979afbf5bcd05fd748b309fd669c0",
79+
"bazel_worker_rev": "ceeba0982d4ff40d32371c9d35f3d2dc1868de20",
8080
"benchmark_harness_rev": "c546dbd9f639f75cd2f75de8df2eb9f8ea15e8e7",
8181
"boolean_selector_rev": "665e6921ab246569420376f827bff4585dff0b14",
8282
"boringssl_gen_rev": "7322fc15cc065d8d2957fccce6b62a509dc4d641",
@@ -141,7 +141,7 @@ vars = {
141141
"process_rev": "56ece43b53b64c63ae51ec184b76bd5360c28d0b",
142142
"protobuf_rev": "c1eb6cb51af39ccbaa1a8e19349546586a5c8e31",
143143
"pub_rev": "96404e0749864c9fbf8b12e1d424e8078809e00a",
144-
"pub_semver_rev": "a43ad72fb6b7869607581b5fedcb186d1e74276a",
144+
"pub_semver_rev": "cee044a3dc867c1c8464408ed435bd21949510c0",
145145
"root_certificates_rev": "692f6d6488af68e0121317a9c2c9eb393eb0ee50",
146146
"rust_revision": "b7856f695d65a8ebc846754f97d15814bcb1c244",
147147
"shelf_static_rev": "202ec1a53c9a830c17cf3b718d089cf7eba568ad",

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ class CorrectionProducerContext {
239239

240240
final AstNode node;
241241

242-
/// A map keyed by lock names whose value is a list of the ranges for which a
243-
/// lock has already been acquired.
244-
final Map<String, List<SourceRange>> _lockRanges = {};
245-
246242
CorrectionProducerContext._({
247243
required this.resolvedResult,
248244
required this.workspace,
@@ -458,26 +454,6 @@ abstract class _AbstractCorrectionProducer {
458454

459455
CorrectionUtils get utils => _context.utils;
460456

461-
/// Return `true` if this is the first request to lock the given [range] for
462-
/// the lock with the given [lockName], or false if a lock for that range has
463-
/// already been acquired.
464-
///
465-
/// This method is used to allow correction producers to guard against
466-
/// repeating changes that have already been made. For example, if multiple
467-
/// arguments in an argument list have diagnostics reported against them and
468-
/// the fix will fix all of the arguments, then the fix should be applied for
469-
/// the first diagnostic and not for the others. A correction producer can
470-
/// ensure this behavior by attempting to acquire a lock prior to creating any
471-
/// edits, and only create the edits if a lock could be acquired.
472-
bool acquireLockOnRange(String lockName, SourceRange range) {
473-
var ranges = _context._lockRanges.putIfAbsent(lockName, () => []);
474-
if (ranges.contains(range)) {
475-
return false;
476-
}
477-
ranges.add(range);
478-
return true;
479-
}
480-
481457
/// Configure this producer based on the [context].
482458
void configure(CorrectionProducerContext context) {
483459
_context = context;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ class ModifyParameters extends Change<_Data> {
5959
// This should only happen if `validate` didn't check this case.
6060
return;
6161
}
62-
if (!fix.acquireLockOnRange('ModifyParameters', range.node(argumentList))) {
63-
return;
64-
}
6562
var arguments = argumentList.arguments;
6663
var argumentCount = arguments.length;
6764
var templateContext = TemplateContext(invocation, fix.utils);

pkg/analyzer/lib/src/dart/analysis/session.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,13 @@ class SynchronousSession {
221221

222222
_typeSystemLegacy?.updateOptions(
223223
implicitCasts: analysisOptions.implicitCasts,
224+
strictCasts: analysisOptions.strictCasts,
224225
strictInference: analysisOptions.strictInference,
225226
);
226227

227228
_typeSystemNonNullableByDefault?.updateOptions(
228229
implicitCasts: analysisOptions.implicitCasts,
230+
strictCasts: analysisOptions.strictCasts,
229231
strictInference: analysisOptions.strictInference,
230232
);
231233
}
@@ -268,13 +270,15 @@ class SynchronousSession {
268270
_typeSystemLegacy = TypeSystemImpl(
269271
implicitCasts: _analysisOptions.implicitCasts,
270272
isNonNullableByDefault: false,
273+
strictCasts: _analysisOptions.strictCasts,
271274
strictInference: _analysisOptions.strictInference,
272275
typeProvider: legacy,
273276
);
274277

275278
_typeSystemNonNullableByDefault = TypeSystemImpl(
276279
implicitCasts: _analysisOptions.implicitCasts,
277280
isNonNullableByDefault: true,
281+
strictCasts: _analysisOptions.strictCasts,
278282
strictInference: _analysisOptions.strictInference,
279283
typeProvider: nonNullableByDefault,
280284
);

pkg/analyzer/lib/src/dart/constant/value.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ class DartObjectImpl implements DartObject {
518518
var typeSystem = TypeSystemImpl(
519519
implicitCasts: false,
520520
isNonNullableByDefault: false,
521+
strictCasts: false,
521522
strictInference: false,
522523
typeProvider: typeProvider,
523524
);

pkg/analyzer/lib/src/dart/element/type_system.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class TypeSystemImpl implements TypeSystem {
4545
/// This affects the behavior of [isAssignableTo].
4646
bool implicitCasts;
4747

48+
/// True if "strict casts" should be enforced.
49+
///
50+
/// This affects the behavior of [isAssignableTo].
51+
bool strictCasts;
52+
4853
/// A flag indicating whether inference failures are allowed, off by default.
4954
///
5055
/// This option is experimental and subject to change.
@@ -71,6 +76,7 @@ class TypeSystemImpl implements TypeSystem {
7176
TypeSystemImpl({
7277
required this.implicitCasts,
7378
required this.isNonNullableByDefault,
79+
required this.strictCasts,
7480
required this.strictInference,
7581
required TypeProvider typeProvider,
7682
}) : typeProvider = typeProvider as TypeProviderImpl {
@@ -699,9 +705,10 @@ class TypeSystemImpl implements TypeSystem {
699705
}
700706
}
701707

702-
// First make sure --no-implicit-casts disables all downcasts, including
703-
// dynamic casts.
704-
if (!implicitCasts) {
708+
// First make sure that the static analysis options, `implicit-casts: false`
709+
// and `strict-casts: true` disable all downcasts, including casts from
710+
// `dynamic`.
711+
if (!implicitCasts || strictCasts) {
705712
return false;
706713
}
707714

@@ -1537,9 +1544,11 @@ class TypeSystemImpl implements TypeSystem {
15371544

15381545
void updateOptions({
15391546
required bool implicitCasts,
1547+
required bool strictCasts,
15401548
required bool strictInference,
15411549
}) {
15421550
this.implicitCasts = implicitCasts;
1551+
this.strictCasts = strictCasts;
15431552
this.strictInference = strictInference;
15441553
}
15451554

pkg/analyzer/lib/src/error/literal_element_verifier.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ class LiteralElementVerifier {
138138
/// assigned to the [elementType] of the enclosing collection.
139139
void _verifySpreadForListOrSet(bool isNullAware, Expression expression) {
140140
var expressionType = expression.typeOrThrow;
141-
if (expressionType.isDynamic) return;
141+
if (expressionType.isDynamic) {
142+
if (typeSystem.strictCasts) {
143+
return errorReporter.reportErrorForNode(
144+
CompileTimeErrorCode.NOT_ITERABLE_SPREAD,
145+
expression,
146+
);
147+
}
148+
return;
149+
}
142150

143151
if (typeSystem.isNonNullableByDefault) {
144152
if (typeSystem.isSubtypeOf(expressionType, NeverTypeImpl.instance)) {
@@ -224,7 +232,15 @@ class LiteralElementVerifier {
224232
/// its key and values are assignable to [mapKeyType] and [mapValueType].
225233
void _verifySpreadForMap(bool isNullAware, Expression expression) {
226234
var expressionType = expression.typeOrThrow;
227-
if (expressionType.isDynamic) return;
235+
if (expressionType.isDynamic) {
236+
if (typeSystem.strictCasts) {
237+
return errorReporter.reportErrorForNode(
238+
CompileTimeErrorCode.NOT_MAP_SPREAD,
239+
expression,
240+
);
241+
}
242+
return;
243+
}
228244

229245
if (typeSystem.isNonNullableByDefault) {
230246
if (typeSystem.isSubtypeOf(expressionType, NeverTypeImpl.instance)) {

pkg/analyzer/lib/src/generated/engine.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ class AnalysisOptionsImpl implements AnalysisOptions {
285285
/// re-throwing them)
286286
bool propagateLinterExceptions = false;
287287

288+
/// Whether implicit casts should be reported as potential problems.
289+
bool strictCasts = false;
290+
288291
/// A flag indicating whether inference failures are allowed, off by default.
289292
///
290293
/// This option is experimental and subject to change.

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,26 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
22592259

22602260
DartType iterableType = node.iterable.typeOrThrow;
22612261

2262+
Token? awaitKeyword;
2263+
var parent = node.parent;
2264+
if (parent is ForStatement) {
2265+
awaitKeyword = parent.awaitKeyword;
2266+
} else if (parent is ForElement) {
2267+
awaitKeyword = parent.awaitKeyword;
2268+
}
2269+
2270+
// Use an explicit string instead of [loopType] to remove the "<E>".
2271+
String loopNamedType = awaitKeyword != null ? 'Stream' : 'Iterable';
2272+
2273+
if (iterableType.isDynamic && typeSystem.strictCasts) {
2274+
errorReporter.reportErrorForNode(
2275+
CompileTimeErrorCode.FOR_IN_OF_INVALID_TYPE,
2276+
node.iterable,
2277+
[iterableType, loopNamedType],
2278+
);
2279+
return false;
2280+
}
2281+
22622282
// TODO(scheglov) use NullableDereferenceVerifier
22632283
if (_isNonNullableByDefault) {
22642284
if (typeSystem.isNullable(iterableType)) {
@@ -2275,14 +2295,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
22752295
return false;
22762296
}
22772297

2278-
Token? awaitKeyword;
2279-
var parent = node.parent;
2280-
if (parent is ForStatement) {
2281-
awaitKeyword = parent.awaitKeyword;
2282-
} else if (parent is ForElement) {
2283-
awaitKeyword = parent.awaitKeyword;
2284-
}
2285-
22862298
// The object being iterated has to implement Iterable<T> for some T that
22872299
// is assignable to the variable's type.
22882300
// TODO(rnystrom): Move this into mostSpecificTypeArgument()?
@@ -2297,8 +2309,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
22972309
}
22982310

22992311
if (!typeSystem.isAssignableTo(iterableType, requiredSequenceType)) {
2300-
// Use an explicit string instead of [loopType] to remove the "<E>".
2301-
String loopNamedType = awaitKeyword != null ? 'Stream' : 'Iterable';
23022312
errorReporter.reportErrorForNode(
23032313
CompileTimeErrorCode.FOR_IN_OF_INVALID_TYPE,
23042314
node.iterable,

0 commit comments

Comments
 (0)