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

Commit 599329b

Browse files
author
Dart CI
committed
Version 2.12.0-18.0.dev
Merge commit '172647612080b72c07a5f48c439215d11db880d0' into 'dev'
2 parents 57bb12d + 1726476 commit 599329b

Some content is hidden

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

41 files changed

+316
-453
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
613613
@override
614614
void visitPostfixExpression(PostfixExpression node) {
615615
_deprecatedVerifier.postfixExpression(node);
616-
if (node.operand.staticType?.isDartCoreNull ?? false) {
616+
if (node.operator.type == TokenType.BANG &&
617+
node.operand.staticType.isDartCoreNull) {
617618
_errorReporter.reportErrorForNode(HintCode.NULL_CHECK_ALWAYS_FAILS, node);
618619
}
619620
super.visitPostfixExpression(node);
@@ -1641,9 +1642,12 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
16411642

16421643
class _InvalidAccessVerifier {
16431644
static final _templateExtension = '.template';
1644-
static final _testDir = '${path.separator}test${path.separator}';
1645-
static final _testDriverDir = '${path.separator}test_driver${path.separator}';
1646-
static final _testingDir = '${path.separator}testing${path.separator}';
1645+
static final _testDirectories = [
1646+
'${path.separator}test${path.separator}',
1647+
'${path.separator}integration_test${path.separator}',
1648+
'${path.separator}test_driver${path.separator}',
1649+
'${path.separator}testing${path.separator}',
1650+
];
16471651

16481652
final ErrorReporter _errorReporter;
16491653
final LibraryElement _library;
@@ -1658,9 +1662,7 @@ class _InvalidAccessVerifier {
16581662
this._errorReporter, this._library, this._workspacePackage) {
16591663
var path = _library.source.fullName;
16601664
_inTemplateSource = path.contains(_templateExtension);
1661-
_inTestDirectory = path.contains(_testDir) ||
1662-
path.contains(_testDriverDir) ||
1663-
path.contains(_testingDir);
1665+
_inTestDirectory = _testDirectories.any(path.contains);
16641666
}
16651667

16661668
/// Produces a hint if [identifier] is accessed from an invalid location.

pkg/analyzer/lib/src/test_utilities/mock_sdk.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ abstract class num implements Comparable<num> {
491491
int toInt();
492492
}
493493
494+
abstract class Match {}
495+
494496
class Object {
495497
const Object();
496498
@@ -503,7 +505,9 @@ class Object {
503505
external dynamic noSuchMethod(Invocation invocation);
504506
}
505507
506-
abstract class Pattern {}
508+
abstract class Pattern {
509+
Iterable<Match> allMatches(String string, [int start = 0]);
510+
}
507511
508512
abstract class RegExp implements Pattern {
509513
external factory RegExp(String source);

pkg/analyzer/test/src/diagnostics/invalid_use_of_visible_for_testing_member_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ export 'lib1.dart' show fn0;
3939
await _resolveFile('$testPackageRootPath/lib2.dart');
4040
}
4141

42+
test_fromIntegrationTestDirectory() async {
43+
newFile('$testPackageRootPath/lib1.dart', content: r'''
44+
import 'package:meta/meta.dart';
45+
class A {
46+
@visibleForTesting
47+
void a(){ }
48+
}
49+
''');
50+
newFile('$testPackageRootPath/integration_test/test.dart', content: r'''
51+
import '../lib1.dart';
52+
class B {
53+
void b() => new A().a();
54+
}
55+
''');
56+
57+
await _resolveFile('$testPackageRootPath/lib1.dart');
58+
await _resolveFile('$testPackageRootPath/integration_test/test.dart');
59+
}
60+
4261
test_fromTestDirectory() async {
4362
newFile('$testPackageRootPath/lib1.dart', content: r'''
4463
import 'package:meta/meta.dart';
@@ -58,6 +77,25 @@ class B {
5877
await _resolveFile('$testPackageRootPath/test/test.dart');
5978
}
6079

80+
test_fromTestDriverDirectory() async {
81+
newFile('$testPackageRootPath/lib1.dart', content: r'''
82+
import 'package:meta/meta.dart';
83+
class A {
84+
@visibleForTesting
85+
void a(){ }
86+
}
87+
''');
88+
newFile('$testPackageRootPath/test_driver/test.dart', content: r'''
89+
import '../lib1.dart';
90+
class B {
91+
void b() => new A().a();
92+
}
93+
''');
94+
95+
await _resolveFile('$testPackageRootPath/lib1.dart');
96+
await _resolveFile('$testPackageRootPath/test_driver/test.dart');
97+
}
98+
6199
test_fromTestingDirectory() async {
62100
newFile('$testPackageRootPath/lib1.dart', content: r'''
63101
import 'package:meta/meta.dart';

pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ void f() {
3737
test_nullLiteral_parenthesized() async {
3838
await assertErrorsInCode(r'''
3939
void f() {
40-
null!;
40+
(null)!;
4141
}
4242
''', [
43-
error(HintCode.NULL_CHECK_ALWAYS_FAILS, 13, 5),
43+
error(HintCode.NULL_CHECK_ALWAYS_FAILS, 13, 7),
4444
]);
4545
}
4646

pkg/dartdev/lib/dartdev.dart

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import 'dart:io' as io hide exit;
77
import 'dart:isolate';
88

9-
import 'package:analyzer/src/dart/analysis/experiments.dart';
109
import 'package:args/args.dart';
1110
import 'package:args/command_runner.dart';
1211
import 'package:cli_util/cli_logging.dart';
@@ -172,8 +171,6 @@ class DartdevRunner extends CommandRunner<int> {
172171
argParser.addFlag('disable-analytics',
173172
negatable: false, help: 'Disable anonymous analytics.');
174173

175-
addExperimentalFlags(argParser, verbose);
176-
177174
argParser.addFlag('diagnostics',
178175
negatable: false, help: 'Show tool diagnostic output.', hide: !verbose);
179176

@@ -189,7 +186,7 @@ class DartdevRunner extends CommandRunner<int> {
189186

190187
addCommand(AnalyzeCommand());
191188
addCommand(CreateCommand(verbose: verbose));
192-
addCommand(CompileCommand());
189+
addCommand(CompileCommand(verbose: verbose));
193190
addCommand(FixCommand());
194191
addCommand(FormatCommand(verbose: verbose));
195192
addCommand(MigrateCommand(verbose: verbose));
@@ -206,26 +203,6 @@ class DartdevRunner extends CommandRunner<int> {
206203
String get invocation =>
207204
'dart [<vm-flags>] <command|dart-file> [<arguments>]';
208205

209-
void addExperimentalFlags(ArgParser argParser, bool verbose) {
210-
List<ExperimentalFeature> features = experimentalFeatures;
211-
212-
Map<String, String> allowedHelp = {};
213-
for (ExperimentalFeature feature in features) {
214-
String suffix =
215-
feature.isEnabledByDefault ? ' (no-op - enabled by default)' : '';
216-
allowedHelp[feature.enableString] = '${feature.documentation}$suffix';
217-
}
218-
219-
argParser.addMultiOption(
220-
experimentFlagName,
221-
valueHelp: 'experiment',
222-
allowedHelp: verbose ? allowedHelp : null,
223-
help: 'Enable one or more experimental features '
224-
'(see dart.dev/go/experiments).',
225-
hide: !verbose,
226-
);
227-
}
228-
229206
@override
230207
Future<int> runCommand(ArgResults topLevelResults) async {
231208
final stopwatch = Stopwatch()..start();
@@ -250,18 +227,6 @@ class DartdevRunner extends CommandRunner<int> {
250227
? Logger.verbose(ansi: ansi)
251228
: Logger.standard(ansi: ansi);
252229

253-
if (topLevelResults.wasParsed(experimentFlagName)) {
254-
List<String> experimentIds = topLevelResults[experimentFlagName];
255-
for (ExperimentalFeature feature in experimentalFeatures) {
256-
// We allow default true flags, but complain when they are passed in.
257-
if (feature.isEnabledByDefault &&
258-
experimentIds.contains(feature.enableString)) {
259-
print("'${feature.enableString}' is now enabled by default; this "
260-
'flag is no longer required.');
261-
}
262-
}
263-
}
264-
265230
var command = topLevelResults.command;
266231
final commandNames = [];
267232
while (command != null) {
@@ -276,10 +241,6 @@ class DartdevRunner extends CommandRunner<int> {
276241
analyticsInstance.sendScreenView(path),
277242
);
278243

279-
final topLevelCommand = topLevelResults.command == null
280-
? null
281-
: commands[topLevelResults.command.name];
282-
283244
try {
284245
final exitCode = await super.runCommand(topLevelResults);
285246

@@ -299,7 +260,7 @@ class DartdevRunner extends CommandRunner<int> {
299260
//
300261
// Note that this will also conflate short-options and long-options.
301262
command?.options?.where(command.wasParsed)?.toList(),
302-
specifiedExperiments: topLevelCommand?.specifiedExperiments,
263+
specifiedExperiments: topLevelResults.enabledExperiments,
303264
),
304265
);
305266
}

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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

@@ -9,6 +9,7 @@ import 'package:dart2native/generate.dart';
99
import 'package:path/path.dart' as path;
1010

1111
import '../core.dart';
12+
import '../experiments.dart';
1213
import '../sdk.dart';
1314
import '../vm_interop_handler.dart';
1415

@@ -45,7 +46,8 @@ bool checkFile(String sourcePath) {
4546
class CompileJSCommand extends CompileSubcommandCommand {
4647
static const String cmdName = 'js';
4748

48-
CompileJSCommand() : super(cmdName, 'Compile Dart to JavaScript.') {
49+
CompileJSCommand({bool verbose})
50+
: super(cmdName, 'Compile Dart to JavaScript.') {
4951
argParser
5052
..addOption(
5153
commonOptions['outputFile'].flag,
@@ -58,6 +60,7 @@ class CompileJSCommand extends CompileSubcommandCommand {
5860
abbr: 'm',
5961
negatable: false,
6062
);
63+
addExperimentalFlags(argParser, verbose);
6164
}
6265

6366
@override
@@ -91,6 +94,8 @@ class CompileJSCommand extends CompileSubcommandCommand {
9194

9295
VmInteropHandler.run(sdk.dart2jsSnapshot, [
9396
'--libraries-spec=$librariesPath',
97+
if (argResults.enabledExperiments.isNotEmpty)
98+
"--enable-experiment=${argResults.enabledExperiments.join(',')}",
9499
...argResults.arguments,
95100
]);
96101

@@ -112,13 +117,15 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
112117
this.help,
113118
this.fileExt,
114119
this.formatName,
120+
bool verbose,
115121
}) : super(commandName, 'Compile Dart $help') {
116122
argParser
117123
..addOption(
118124
commonOptions['outputFile'].flag,
119125
help: commonOptions['outputFile'].help,
120126
abbr: commonOptions['outputFile'].abbr,
121127
);
128+
addExperimentalFlags(argParser, verbose);
122129
}
123130

124131
@override
@@ -144,10 +151,14 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
144151
outputFile = '$inputWithoutDart.$fileExt';
145152
}
146153

154+
final enabledExperiments = argResults.enabledExperiments;
147155
// Build arguments.
148156
List<String> args = [];
149157
args.add('--snapshot-kind=$formatName');
150158
args.add('--snapshot=${path.canonicalize(outputFile)}');
159+
if (enabledExperiments.isNotEmpty) {
160+
args.add("--enable-experiment=${enabledExperiments.join(',')}");
161+
}
151162
if (verbose) {
152163
args.add('-v');
153164
}
@@ -173,6 +184,7 @@ class CompileNativeCommand extends CompileSubcommandCommand {
173184
this.commandName,
174185
this.format,
175186
this.help,
187+
bool verbose,
176188
}) : super(commandName, 'Compile Dart $help') {
177189
argParser
178190
..addOption(
@@ -195,6 +207,8 @@ For example: dart compile $commandName --packages=/tmp/pkgs main.dart''')
195207
..addOption('save-debugging-info', abbr: 'S', valueHelp: 'path', help: '''
196208
Remove debugging information from the output and save it separately to the specified file.
197209
<path> can be relative or absolute.''');
210+
211+
addExperimentalFlags(argParser, verbose);
198212
}
199213

200214
@override
@@ -225,6 +239,7 @@ Remove debugging information from the output and save it separately to the speci
225239
defines: argResults['define'],
226240
packages: argResults['packages'],
227241
enableAsserts: argResults['enable-asserts'],
242+
enableExperiment: argResults.enabledExperiments.join(','),
228243
debugFile: argResults['save-debugging-info'],
229244
verbose: verbose,
230245
);
@@ -245,30 +260,36 @@ abstract class CompileSubcommandCommand extends DartdevCommand {
245260

246261
class CompileCommand extends DartdevCommand {
247262
static const String cmdName = 'compile';
248-
249-
CompileCommand() : super(cmdName, 'Compile Dart to various formats.') {
250-
addSubcommand(CompileJSCommand());
263+
CompileCommand({bool verbose = false})
264+
: super(cmdName, 'Compile Dart to various formats.') {
265+
addSubcommand(CompileJSCommand(
266+
verbose: verbose,
267+
));
251268
addSubcommand(CompileSnapshotCommand(
252269
commandName: CompileSnapshotCommand.jitSnapshotCmdName,
253270
help: 'to a JIT snapshot.',
254271
fileExt: 'jit',
255272
formatName: 'app-jit',
273+
verbose: verbose,
256274
));
257275
addSubcommand(CompileSnapshotCommand(
258276
commandName: CompileSnapshotCommand.kernelCmdName,
259277
help: 'to a kernel snapshot.',
260278
fileExt: 'dill',
261279
formatName: 'kernel',
280+
verbose: verbose,
262281
));
263282
addSubcommand(CompileNativeCommand(
264283
commandName: CompileNativeCommand.exeCmdName,
265284
help: 'to a self-contained executable.',
266285
format: 'exe',
286+
verbose: verbose,
267287
));
268288
addSubcommand(CompileNativeCommand(
269289
commandName: CompileNativeCommand.aotSnapshotCmdName,
270290
help: 'to an AOT snapshot.',
271291
format: 'aot',
292+
verbose: verbose,
272293
));
273294
}
274295
}

pkg/dartdev/lib/src/commands/pub.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,19 @@ class PubCommand extends DartdevCommand {
6363
final command = sdk.pubSnapshot;
6464
var args = argResults.arguments;
6565

66+
final enabledExperiments = argResults.enabledExperiments;
6667
// Pass any --enable-experiment options along.
67-
if (args.isNotEmpty && wereExperimentsSpecified) {
68-
List<String> experimentIds = specifiedExperiments;
69-
68+
if (args.isNotEmpty && enabledExperiments.isNotEmpty) {
7069
if (args.first == 'run') {
7170
args = [
7271
...args.sublist(0, 1),
73-
'--$experimentFlagName=${experimentIds.join(',')}',
72+
'--$experimentFlagName=${enabledExperiments.join(',')}',
7473
...args.sublist(1),
7574
];
7675
} else if (args.length > 1 && args[0] == 'global' && args[0] == 'run') {
7776
args = [
7877
...args.sublist(0, 2),
79-
'--$experimentFlagName=${experimentIds.join(',')}',
78+
'--$experimentFlagName=${enabledExperiments.join(',')}',
8079
...args.sublist(2),
8180
];
8281
}

pkg/dartdev/lib/src/commands/run.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class RunCommand extends DartdevCommand {
145145
negatable: false,
146146
help: 'Enables tracing of library and script loading.',
147147
);
148+
addExperimentalFlags(argParser, verbose);
148149
}
149150

150151
@override
@@ -216,15 +217,6 @@ class RunCommand extends DartdevCommand {
216217
}
217218
}
218219

219-
// Pass any --enable-experiment options along.
220-
if (args.isNotEmpty && wereExperimentsSpecified) {
221-
List<String> experimentIds = specifiedExperiments;
222-
args = [
223-
'--$experimentFlagName=${experimentIds.join(',')}',
224-
...args,
225-
];
226-
}
227-
228220
// If the user wants to start a debugging session we need to do some extra
229221
// work and spawn a Dart Development Service (DDS) instance. DDS is a VM
230222
// service intermediary which implements the VM service protocol and

0 commit comments

Comments
 (0)