Skip to content

Commit d59fce2

Browse files
author
Dart CI
committed
Version 2.12.0-1.0.dev
Merge commit '9ca05a40927142d3512b72055b72fccd7a1cc592' into 'dev'
2 parents 1a18fff + 9ca05a4 commit d59fce2

19 files changed

+191
-391
lines changed

pkg/analysis_server/lib/src/computer/import_elements_computer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,15 @@ class ImportElementsComputer {
325325
var scope = libraryResult.libraryElement.scope;
326326

327327
if (prefix.isNotEmpty) {
328-
var prefixElement = scope.lookup2(prefix).getter;
328+
var prefixElement = scope.lookup(prefix).getter;
329329
if (prefixElement is PrefixElement) {
330330
scope = prefixElement.scope;
331331
} else {
332332
return false;
333333
}
334334
}
335335

336-
var lookupResult = scope.lookup2(name);
336+
var lookupResult = scope.lookup(name);
337337
return lookupResult.getter != null || lookupResult.setter != null;
338338
}
339339

pkg/dartdev/lib/dartdev.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io' as io;
5+
// Do not call exit() directly. Use VmInteropHandler.exit() instead.
6+
import 'dart:io' as io hide exit;
67
import 'dart:isolate';
78

89
import 'package:analyzer/src/dart/analysis/experiments.dart';
@@ -29,8 +30,7 @@ import 'src/utils.dart';
2930
import 'src/vm_interop_handler.dart';
3031

3132
/// This is typically called from bin/, but given the length of the method and
32-
/// analytics logic, it has been moved here. Also note that this method calls
33-
/// [io.exit(code)] directly.
33+
/// analytics logic, it has been moved here.
3434
Future<void> runDartdev(List<String> args, SendPort port) async {
3535
VmInteropHandler.initialize(port);
3636

@@ -69,13 +69,15 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
6969

7070
// Alert the user that analytics has been disabled.
7171
print(analyticsDisabledNoticeMessage);
72-
io.exit(0);
72+
VmInteropHandler.exit(0);
73+
return;
7374
} else if (args.contains('--enable-analytics')) {
7475
analytics.enabled = true;
7576

7677
// Alert the user again that anonymous data will be collected.
7778
print(analyticsNoticeOnFirstRunMessage);
78-
io.exit(0);
79+
VmInteropHandler.exit(0);
80+
return;
7981
}
8082

8183
try {

pkg/nnbd_migration/lib/migration_cli.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,8 @@ class MigrationCli {
314314
CommandLineOptions.skipPubOutdatedFlag,
315315
(parser, hide) => parser.addFlag(
316316
CommandLineOptions.skipPubOutdatedFlag,
317-
// TODO(srawlins): Before "beta," change the default to "false," and
318-
// negatable to "false." See
319-
// https://github.com/dart-lang/sdk/issues/43774.
320-
defaultsTo: true,
321-
negatable: true,
317+
defaultsTo: false,
318+
negatable: false,
322319
help:
323320
'Skip the `pub outdated --mode=null-safety` check. This allows a '
324321
'migration to proceed even if some package dependencies have not yet '

pkg/nnbd_migration/lib/nnbd_migration.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class NullabilityFixDescription {
117117
kind: NullabilityFixKind.downcastExpression,
118118
);
119119

120+
/// Informative message: there is no valid migration for `null` in a
121+
/// non-nullable context.
122+
static const noValidMigrationForNull = NullabilityFixDescription._(
123+
appliedMessage: 'No valid migration for `null` in a non-nullable context',
124+
kind: NullabilityFixKind.noValidMigrationForNull);
125+
120126
/// Informative message: a null-aware access won't be necessary in strong
121127
/// checking mode.
122128
static const nullAwarenessUnnecessaryInStrongMode =
@@ -276,6 +282,7 @@ enum NullabilityFixKind {
276282
downcastExpression,
277283
makeTypeNullable,
278284
makeTypeNullableDueToHint,
285+
noValidMigrationForNull,
279286
nullAwarenessUnnecessaryInStrongMode,
280287
nullAwareAssignmentUnnecessaryInStrongMode,
281288
otherCastExpression,

pkg/nnbd_migration/lib/src/fix_aggregator.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ class NodeChangeForDefaultFormalParameter
684684
/// Implementation of [NodeChange] specialized for operating on [Expression]
685685
/// nodes.
686686
class NodeChangeForExpression<N extends Expression> extends NodeChange<N> {
687+
bool _addsNoValidMigration = false;
688+
689+
AtomicEditInfo _addNoValidMigrationInfo;
690+
687691
bool _addsNullCheck = false;
688692

689693
AtomicEditInfo _addNullCheckInfo;
@@ -696,9 +700,15 @@ class NodeChangeForExpression<N extends Expression> extends NodeChange<N> {
696700

697701
NodeChangeForExpression() : super._();
698702

703+
/// Gets the info for any added "no valid migration" comment.
704+
AtomicEditInfo get addNoValidMigrationInfo => _addNoValidMigrationInfo;
705+
699706
/// Gets the info for any added null check.
700707
AtomicEditInfo get addNullCheckInfo => _addNullCheckInfo;
701708

709+
/// Indicates whether [addNoValidMigration] has been called.
710+
bool get addsNoValidMigration => _addsNoValidMigration;
711+
702712
/// Indicates whether [addNullCheck] has been called.
703713
bool get addsNullCheck => _addsNullCheck;
704714

@@ -711,10 +721,17 @@ class NodeChangeForExpression<N extends Expression> extends NodeChange<N> {
711721

712722
@override
713723
Iterable<String> get _toStringParts => [
724+
if (_addsNoValidMigration) 'addsNoValidMigration',
714725
if (_addsNullCheck) 'addsNullCheck',
715726
if (_introducesAsType != null) 'introducesAsType'
716727
];
717728

729+
void addNoValidMigration(AtomicEditInfo info) {
730+
assert(!_addsNoValidMigration);
731+
_addsNoValidMigration = true;
732+
_addNoValidMigrationInfo = info;
733+
}
734+
718735
/// Causes a null check to be added to this expression, with the given [info].
719736
void addNullCheck(AtomicEditInfo info, {HintComment hint}) {
720737
assert(!_addsNullCheck);
@@ -754,6 +771,11 @@ class NodeChangeForExpression<N extends Expression> extends NodeChange<N> {
754771
.addUnaryPostfix(plan, TokenType.BANG, info: _addNullCheckInfo);
755772
}
756773
}
774+
if (_addsNoValidMigration) {
775+
plan = aggregator.planner.addCommentPostfix(
776+
plan, '/* no valid migration */',
777+
info: _addNoValidMigrationInfo, isInformative: true);
778+
}
757779
if (_introducesAsType != null) {
758780
plan = aggregator.planner.addBinaryPostfix(
759781
plan, TokenType.AS, aggregator.typeToCode(_introducesAsType),

pkg/nnbd_migration/lib/src/fix_builder.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,21 @@ class MigrationResolutionHooksImpl
573573
{AtomicEditInfo info, HintComment hint}) {
574574
var checks =
575575
_fixBuilder._variables.expressionChecks(_fixBuilder.source, node);
576+
bool noValidMigration = node is NullLiteral && hint == null;
576577
info ??= checks != null
577578
? AtomicEditInfo(
578-
NullabilityFixDescription.checkExpression, checks.edges)
579+
noValidMigration
580+
? NullabilityFixDescription.noValidMigrationForNull
581+
: NullabilityFixDescription.checkExpression,
582+
checks.edges)
579583
: null;
580-
(_fixBuilder._getChange(node) as NodeChangeForExpression)
581-
.addNullCheck(info, hint: hint);
584+
var nodeChangeForExpression =
585+
_fixBuilder._getChange(node) as NodeChangeForExpression;
586+
if (noValidMigration) {
587+
nodeChangeForExpression.addNoValidMigration(info);
588+
} else {
589+
nodeChangeForExpression.addNullCheck(info, hint: hint);
590+
}
582591
_flowAnalysis.nonNullAssert_end(node);
583592
return _fixBuilder._typeSystem.promoteToNonNull(type as TypeImpl);
584593
}

pkg/nnbd_migration/lib/src/front_end/info_builder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ class InfoBuilder {
211211
// their "OrNull" equivalents. We don't offer any hints around
212212
// this transformation.
213213
break;
214+
case NullabilityFixKind.noValidMigrationForNull:
215+
// We don't offer any edits around unmigratable `null`s. The user has
216+
// to fix manually.
217+
break;
214218
}
215219
return edits;
216220
}

pkg/nnbd_migration/lib/src/front_end/migration_summary.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class MigrationSummary {
9494
return 'makeTypeNullable';
9595
case NullabilityFixKind.makeTypeNullableDueToHint:
9696
return 'makeTypeNullableDueToHint';
97+
case NullabilityFixKind.noValidMigrationForNull:
98+
return 'noValidMigrationForNull';
9799
case NullabilityFixKind.nullAwarenessUnnecessaryInStrongMode:
98100
return 'nullAwarenessUnnecessaryInStrongMode';
99101
case NullabilityFixKind.nullAwareAssignmentUnnecessaryInStrongMode:

pkg/nnbd_migration/lib/src/front_end/non_nullable_fix.dart

Lines changed: 3 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:convert' show jsonDecode, JsonEncoder;
66

7-
import 'package:analyzer/dart/analysis/features.dart';
87
import 'package:analyzer/dart/analysis/results.dart';
98
import 'package:analyzer/dart/ast/ast.dart';
109
import 'package:analyzer/file_system/file_system.dart';
@@ -30,11 +29,11 @@ class NonNullableFix {
3029
// TODO(srawlins): Refactor to use
3130
// `Feature.non_nullable.releaseVersion` when this becomes non-null (perhaps
3231
// after "Beta").
33-
static final Version _intendedMinimumSdkVersion =
34-
Feature.non_nullable.experimentalReleaseVersion;
32+
static final Version _intendedMinimumSdkVersion = Version.parse('2.12.0-0');
3533

3634
// In the package_config.json file, the patch number is omitted.
37-
static const String _intendedLanguageVersion = '2.10';
35+
static final String _intendedLanguageVersion =
36+
'${_intendedMinimumSdkVersion.major}.${_intendedMinimumSdkVersion.minor}';
3837

3938
static final String _intendedSdkVersionConstraint =
4039
'>=$_intendedMinimumSdkVersion <2.12.0';
@@ -153,9 +152,6 @@ class NonNullableFix {
153152
if (updated) {
154153
_processConfigFile(pkgFolder, pubspec);
155154
}
156-
// TODO(https://github.com/dart-lang/sdk/issues/43806): stop processing
157-
// analysis options file when the experiment is no longer needed.
158-
_processAnalysisOptionsFile(pkgFolder);
159155
}
160156

161157
Future<void> processUnit(ResolvedUnitResult result) async {
@@ -212,91 +208,6 @@ class NonNullableFix {
212208
}
213209
}
214210

215-
void _processAnalysisOptionsException(
216-
String action, String analysisOptionsPath, error) {
217-
listener.addRecommendation('''Failed to $action analysis options file
218-
$analysisOptionsPath
219-
$error
220-
221-
Manually update this file to enable the Null Safety language feature in static
222-
analysis by adding:
223-
224-
analyzer:
225-
enable-experiment:
226-
- non-nullable
227-
''');
228-
}
229-
230-
void _processAnalysisOptionsFile(Folder pkgFolder) {
231-
var analysisOptionsFile =
232-
pkgFolder.getChildAssumingFile('analysis_options.yaml');
233-
if (!analysisOptionsFile.exists) {
234-
// A source file edit cannot be made for a file which doesn't exist.
235-
// Instead of using the fix listener, just write the file directly.
236-
analysisOptionsFile.writeAsStringSync('''
237-
analyzer:
238-
enable-experiment:
239-
- non-nullable
240-
241-
''');
242-
return;
243-
}
244-
245-
_YamlFile analysisOptions;
246-
try {
247-
analysisOptions = _YamlFile._parseFrom(analysisOptionsFile);
248-
} on FileSystemException catch (e) {
249-
_processAnalysisOptionsException('read', analysisOptionsFile.path, e);
250-
return;
251-
} on FormatException catch (e) {
252-
_processAnalysisOptionsException('parse', analysisOptionsFile.path, e);
253-
return;
254-
}
255-
256-
var analysisOptionsMap = analysisOptions.content;
257-
YamlNode analyzerOptions;
258-
if (analysisOptionsMap is YamlMap) {
259-
analyzerOptions = analysisOptionsMap.nodes['analyzer'];
260-
}
261-
if (analyzerOptions == null) {
262-
// There is no top-level "analyzer" section. We can write one in its
263-
// entirety, and use a 2-space indentation. This is a valid indentation,
264-
// even if the file contains another top-level section (perhaps "linter")
265-
// which uses a different indentation.
266-
var start = SourceLocation(0, line: 0, column: 0);
267-
var content = '''
268-
analyzer:
269-
enable-experiment:
270-
- non-nullable
271-
272-
''';
273-
analysisOptions._insertAfterParent(
274-
SourceSpan(start, start, ''), content, listener);
275-
} else if (analyzerOptions is YamlMap) {
276-
var enableExperiment = analyzerOptions.nodes['enable-experiment'];
277-
if (enableExperiment == null) {
278-
var analyzerIndentation =
279-
analysisOptions._getMapEntryIndentation(analyzerOptions);
280-
var indent = ' ' * analyzerIndentation;
281-
var content = '\n'
282-
'${indent}enable-experiment:\n'
283-
'$indent - non-nullable';
284-
analysisOptions._insertAfterParent(
285-
analyzerOptions.span, content, listener);
286-
} else if (enableExperiment is YamlList) {
287-
var enableExperimentIndentation =
288-
analysisOptions._getListIndentation(enableExperiment);
289-
var indent = ' ' * enableExperimentIndentation;
290-
var nonNullableIsEnabled = enableExperiment.value
291-
.any((experiment) => experiment == 'non-nullable');
292-
if (nonNullableIsEnabled) return;
293-
var content = '\n' '$indent- non-nullable';
294-
analysisOptions._insertAfterParent(
295-
enableExperiment.span, content, listener);
296-
}
297-
}
298-
}
299-
300211
/// Updates the Package Config file to specify a minimum Dart SDK version
301212
/// which supports null safety.
302213
void _processConfigFile(Folder pkgFolder, _YamlFile pubspec) {
@@ -516,48 +427,13 @@ $stackTrace''');
516427
}
517428

518429
class _YamlFile {
519-
static final _newlineCharacter = RegExp('[\r\n]');
520430
final String path;
521431
final String textContent;
522432

523433
final YamlNode content;
524434

525435
_YamlFile._(this.path, this.textContent, this.content);
526436

527-
/// Returns the indentation of the entries in [node].
528-
int _getListIndentation(YamlList node) {
529-
return node.span.start.column;
530-
}
531-
532-
/// Returns the indentation of the first (and presumably all) entry of [node].
533-
int _getMapEntryIndentation(YamlMap node) {
534-
if (node.isEmpty) return 2;
535-
536-
var value = node.nodes.values.first;
537-
if (value is YamlScalar) {
538-
// A YamlScalar value indicates that a "key: value" pair is on a single
539-
// line. The span's start column is the start column of the value, not the
540-
// key.
541-
var offset = value.span.start.offset;
542-
var firstSpaceIndex =
543-
textContent.lastIndexOf(_newlineCharacter, offset) + 1;
544-
var index = firstSpaceIndex;
545-
while (textContent.codeUnitAt(index) == $space) {
546-
index++;
547-
}
548-
return index - firstSpaceIndex;
549-
} else if (value is YamlMap) {
550-
// If the first entry of [node] is a YamlMap, then the span for [node]
551-
// indicates the start of the first entry.
552-
return node.span.start.column;
553-
} else {
554-
assert(value is YamlList);
555-
// If the first entry of [node] is a YamlList, then the span for [value]
556-
// indicates the start of the first list entry.
557-
return value.span.start.column;
558-
}
559-
}
560-
561437
String _getName() {
562438
YamlNode packageNameNode;
563439

pkg/nnbd_migration/lib/src/front_end/unit_renderer.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class UnitRenderer {
2323
/// "proposed edits" area, in the order in which they should be displayed.
2424
@visibleForTesting
2525
static const List<NullabilityFixKind> kindPriorityOrder = [
26+
NullabilityFixKind.noValidMigrationForNull,
2627
NullabilityFixKind.compoundAssignmentHasBadCombinedType,
2728
NullabilityFixKind.compoundAssignmentHasNullableSource,
2829
NullabilityFixKind.removeDeadCode,
@@ -316,6 +317,8 @@ class UnitRenderer {
316317
return '$count type$s made nullable';
317318
case NullabilityFixKind.makeTypeNullableDueToHint:
318319
return '$count nullability hint$s converted to ?$s';
320+
case NullabilityFixKind.noValidMigrationForNull:
321+
return '$count literal `null`$s could not be migrated';
319322
case NullabilityFixKind.nullAwarenessUnnecessaryInStrongMode:
320323
return '$count null-aware access$es will be unnecessary in strong '
321324
'checking mode';

0 commit comments

Comments
 (0)