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

Commit c0c5298

Browse files
author
Dart CI
committed
Version 2.12.0-264.0.dev
Merge commit '64a8d2a8b8b85a6e3221ebbc80f36a7746045b4e' into 'dev'
2 parents 89cd39c + 64a8d2a commit c0c5298

File tree

29 files changed

+455
-291
lines changed

29 files changed

+455
-291
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ vars = {
111111
"http_multi_server_rev" : "e8c8be7f15b4fb50757ff5bf29766721fbe24fe4",
112112
"http_parser_rev": "5dd4d16693242049dfb43b5efa429fedbf932e98",
113113
"http_retry_tag": "0.1.1",
114-
"http_rev": "3845753a54624b070828cb3eff7a6c2a4e046cfb",
114+
"http_rev": "d5c678cd63c3e9c1d779a09acfa95b7e3af84665",
115115
"http_throttle_tag" : "1.0.2",
116116
"icu_rev" : "79326efe26e5440f530963704c3c0ff965b3a4ac",
117117
"idl_parser_rev": "5fb1ebf49d235b5a70c9f49047e83b0654031eb7",

pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class A {
9595

9696
Future<void> test_createChange_add() async {
9797
await indexTestUnit('''
98+
/// Documentation for [new A]
9899
class A {
99100
A() {} // marker
100101
factory A._() = A;
@@ -114,6 +115,7 @@ main() {
114115
// validate change
115116
refactoring.newName = 'newName';
116117
return assertSuccessfulRefactoring('''
118+
/// Documentation for [new A.newName]
117119
class A {
118120
A.newName() {} // marker
119121
factory A._() = A.newName;
@@ -129,6 +131,7 @@ main() {
129131

130132
Future<void> test_createChange_add_toSynthetic() async {
131133
await indexTestUnit('''
134+
/// Documentation for [new A]
132135
class A {
133136
}
134137
class B extends A {
@@ -146,6 +149,7 @@ main() {
146149
// validate change
147150
refactoring.newName = 'newName';
148151
return assertSuccessfulRefactoring('''
152+
/// Documentation for [new A.newName]
149153
class A {
150154
A.newName();
151155
}
@@ -160,6 +164,7 @@ main() {
160164

161165
Future<void> test_createChange_change() async {
162166
await indexTestUnit('''
167+
/// Documentation for [A.test] and [new A.test]
163168
class A {
164169
A.test() {} // marker
165170
factory A._() = A.test;
@@ -179,6 +184,7 @@ main() {
179184
// validate change
180185
refactoring.newName = 'newName';
181186
return assertSuccessfulRefactoring('''
187+
/// Documentation for [A.newName] and [new A.newName]
182188
class A {
183189
A.newName() {} // marker
184190
factory A._() = A.newName;
@@ -194,6 +200,7 @@ main() {
194200

195201
Future<void> test_createChange_remove() async {
196202
await indexTestUnit('''
203+
/// Documentation for [A.test] and [new A.test]
197204
class A {
198205
A.test() {} // marker
199206
factory A._() = A.test;
@@ -213,6 +220,7 @@ main() {
213220
// validate change
214221
refactoring.newName = '';
215222
return assertSuccessfulRefactoring('''
223+
/// Documentation for [A] and [new A]
216224
class A {
217225
A() {} // marker
218226
factory A._() = A;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,28 @@ class _IndexContributor extends GeneralizingAstVisitor {
583583
super.visitClassTypeAlias(node);
584584
}
585585

586+
@override
587+
visitCommentReference(CommentReference node) {
588+
var identifier = node.identifier;
589+
var element = identifier.staticElement;
590+
if (element is ConstructorElement) {
591+
if (identifier is PrefixedIdentifier) {
592+
var offset = identifier.prefix.end;
593+
var length = identifier.end - offset;
594+
recordRelationOffset(
595+
element, IndexRelationKind.IS_REFERENCED_BY, offset, length, true);
596+
return;
597+
} else {
598+
var offset = identifier.end;
599+
recordRelationOffset(
600+
element, IndexRelationKind.IS_REFERENCED_BY, offset, 0, true);
601+
return;
602+
}
603+
}
604+
605+
return super.visitCommentReference(node);
606+
}
607+
586608
@override
587609
void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
588610
SimpleIdentifier fieldName = node.fieldName;

pkg/analyzer/test/src/dart/analysis/index_test.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,33 +602,39 @@ part 'b.dart';
602602

603603
test_isReferencedBy_ConstructorElement() async {
604604
await _indexTestUnit('''
605+
/// [new A.foo] 1
606+
/// [A.foo] 2
607+
/// [new A] 3
605608
class A implements B {
606609
A() {}
607610
A.foo() {}
608611
}
609612
class B extends A {
610-
B() : super(); // 1
611-
B.foo() : super.foo(); // 2
612-
factory B.bar() = A.foo; // 3
613+
B() : super(); // 4
614+
B.foo() : super.foo(); // 5
615+
factory B.bar() = A.foo; // 6
613616
}
614617
main() {
615-
new A(); // 4
616-
new A.foo(); // 5
618+
new A(); // 7
619+
new A.foo(); // 8
617620
}
618621
''');
619622
var constA = findElement.unnamedConstructor('A');
620623
var constA_foo = findElement.constructor('foo', of: 'A');
621624
// A()
622625
assertThat(constA)
623-
..hasRelationCount(2)
624-
..isReferencedAt('(); // 1', true, length: 0)
625-
..isReferencedAt('(); // 4', true, length: 0);
626+
..hasRelationCount(3)
627+
..isReferencedAt('] 3', true, length: 0)
628+
..isReferencedAt('(); // 4', true, length: 0)
629+
..isReferencedAt('(); // 7', true, length: 0);
626630
// A.foo()
627631
assertThat(constA_foo)
628-
..hasRelationCount(3)
629-
..isReferencedAt('.foo(); // 2', true, length: 4)
630-
..isReferencedAt('.foo; // 3', true, length: 4)
631-
..isReferencedAt('.foo(); // 5', true, length: 4);
632+
..hasRelationCount(5)
633+
..isReferencedAt('.foo] 1', true, length: 4)
634+
..isReferencedAt('.foo] 2', true, length: 4)
635+
..isReferencedAt('.foo(); // 5', true, length: 4)
636+
..isReferencedAt('.foo; // 6', true, length: 4)
637+
..isReferencedAt('.foo(); // 8', true, length: 4);
632638
}
633639

634640
test_isReferencedBy_ConstructorElement_classTypeAlias() async {

pkg/dart2native/bin/dart2native.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Remove debugging information from the output and save it separately to the speci
6666
defaultsTo: '', valueHelp: 'feature', hide: true, help: '''
6767
Comma separated list of experimental features.
6868
''')
69+
..addFlag('sound-null-safety',
70+
help: 'Respect the nullability of types at runtime.', defaultsTo: null)
6971
..addFlag('verbose',
7072
abbr: 'v', negatable: false, help: 'Show verbose output.')
7173
..addOption(
@@ -116,6 +118,7 @@ Sets the verbosity level used for filtering messages during compilation.
116118
defines: parsedArgs['define'],
117119
enableExperiment: parsedArgs['enable-experiment'],
118120
enableAsserts: parsedArgs['enable-asserts'],
121+
soundNullSafety: parsedArgs['sound-null-safety'],
119122
verbose: parsedArgs['verbose'],
120123
verbosity: parsedArgs['verbosity'],
121124
extraOptions: parsedArgs['extra-gen-snapshot-options']);

pkg/dart2native/lib/generate.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Future<void> generateNative({
2626
List<String> defines,
2727
String enableExperiment = '',
2828
bool enableAsserts = false,
29+
bool soundNullSafety,
2930
bool verbose = false,
3031
String verbosity = 'all',
3132
List<String> extraOptions = const [],
@@ -61,7 +62,9 @@ Future<void> generateNative({
6162
enableExperiment: enableExperiment,
6263
extraGenKernelOptions: [
6364
'--invocation-modes=compile',
64-
'--verbosity=$verbosity'
65+
'--verbosity=$verbosity',
66+
if (soundNullSafety != null)
67+
'--${soundNullSafety ? '' : 'no-'}sound-null-safety',
6568
]);
6669
if (kernelResult.exitCode != 0) {
6770
// We pipe both stdout and stderr to stderr because the CFE doesn't print

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ For example: dart compile $commandName -Da=1,b=2 main.dart''')
258258
'''Get package locations from the specified file instead of .packages.
259259
<path> can be relative or absolute.
260260
For example: dart compile $commandName --packages=/tmp/pkgs main.dart''')
261+
..addFlag('sound-null-safety',
262+
help: 'Respect the nullability of types at runtime.',
263+
defaultsTo: null)
261264
..addOption('save-debugging-info', abbr: 'S', valueHelp: 'path', help: '''
262265
Remove debugging information from the output and save it separately to the specified file.
263266
<path> can be relative or absolute.''');
@@ -294,6 +297,7 @@ Remove debugging information from the output and save it separately to the speci
294297
packages: argResults['packages'],
295298
enableAsserts: argResults['enable-asserts'],
296299
enableExperiment: argResults.enabledExperiments.join(','),
300+
soundNullSafety: argResults['sound-null-safety'],
297301
debugFile: argResults['save-debugging-info'],
298302
verbose: verbose,
299303
verbosity: argResults['verbosity'],

pkg/dartdev/test/commands/compile_test.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,74 @@ void main() {}
310310
reason: 'File not found: $outFile');
311311
});
312312

313+
test('Compile and run exe with --sound-null-safety', () {
314+
final p = project(mainSrc: '''void main() {
315+
print((<int?>[] is List<int>) ? 'oh no' : 'sound');
316+
}''');
317+
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
318+
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
319+
320+
var result = p.runSync(
321+
[
322+
'compile',
323+
'exe',
324+
'--sound-null-safety',
325+
'-o',
326+
outFile,
327+
inFile,
328+
],
329+
);
330+
331+
expect(result.stderr, isEmpty);
332+
expect(result.stdout, contains(soundNullSafetyMessage));
333+
expect(result.exitCode, 0);
334+
expect(File(outFile).existsSync(), true,
335+
reason: 'File not found: $outFile');
336+
337+
result = Process.runSync(
338+
outFile,
339+
[],
340+
);
341+
342+
expect(result.stdout, contains('sound'));
343+
expect(result.stderr, isEmpty);
344+
expect(result.exitCode, 0);
345+
});
346+
347+
test('Compile and run exe with --no-sound-null-safety', () {
348+
final p = project(mainSrc: '''void main() {
349+
print((<int?>[] is List<int>) ? 'unsound' : 'oh no');
350+
}''');
351+
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
352+
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
353+
354+
var result = p.runSync(
355+
[
356+
'compile',
357+
'exe',
358+
'--no-sound-null-safety',
359+
'-o',
360+
outFile,
361+
inFile,
362+
],
363+
);
364+
365+
expect(result.stderr, isEmpty);
366+
expect(result.stdout, contains(unsoundNullSafetyMessage));
367+
expect(result.exitCode, 0);
368+
expect(File(outFile).existsSync(), true,
369+
reason: 'File not found: $outFile');
370+
371+
result = Process.runSync(
372+
outFile,
373+
[],
374+
);
375+
376+
expect(result.stdout, contains('unsound'));
377+
expect(result.stderr, isEmpty);
378+
expect(result.exitCode, 0);
379+
});
380+
313381
test('Compile exe without info', () {
314382
final p = project(mainSrc: '''void main() {}''');
315383
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));

pkg/front_end/lib/src/fasta/type_inference/type_demotion.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ class _HasPromotedTypeVariableVisitor extends DartTypeVisitor<bool> {
6565
/// with legacy types.
6666
DartType demoteTypeInLibrary(DartType type, Library library) {
6767
if (library.isNonNullableByDefault) {
68-
return type.accept(const _DemotionNullabilityNormalization(
69-
demoteTypeVariables: true, forNonNullableByDefault: true)) ??
68+
return type.accept1(
69+
const _DemotionNullabilityNormalization(
70+
demoteTypeVariables: true, forNonNullableByDefault: true),
71+
Variance.covariant) ??
7072
type;
7173
} else {
72-
return type.accept(const _DemotionNullabilityNormalization(
73-
demoteTypeVariables: true, forNonNullableByDefault: false)) ??
74+
return type.accept1(
75+
const _DemotionNullabilityNormalization(
76+
demoteTypeVariables: true, forNonNullableByDefault: false),
77+
Variance.covariant) ??
7478
type;
7579
}
7680
}
@@ -85,8 +89,10 @@ DartType normalizeNullabilityInLibrary(DartType type, Library library) {
8589
if (library.isNonNullableByDefault) {
8690
return type;
8791
} else {
88-
return type.accept(const _DemotionNullabilityNormalization(
89-
demoteTypeVariables: false, forNonNullableByDefault: false)) ??
92+
return type.accept1(
93+
const _DemotionNullabilityNormalization(
94+
demoteTypeVariables: false, forNonNullableByDefault: false),
95+
Variance.covariant) ??
9096
type;
9197
}
9298
}
@@ -119,7 +125,7 @@ class _DemotionNullabilityNormalization extends ReplacementVisitor {
119125
}
120126

121127
@override
122-
DartType visitTypeParameterType(TypeParameterType node) {
128+
DartType visitTypeParameterType(TypeParameterType node, int variance) {
123129
Nullability newNullability = visitNullability(node);
124130
if (demoteTypeVariables && node.promotedBound != null) {
125131
return new TypeParameterType(

pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,11 @@ class _TypeSchemaEliminationVisitor extends ReplacementVisitor {
5353
final DartType topType;
5454
final DartType bottomType;
5555

56-
bool isLeastClosure;
57-
58-
_TypeSchemaEliminationVisitor(
59-
this.isLeastClosure, this.topType, this.bottomType);
60-
61-
void changeVariance() {
62-
isLeastClosure = !isLeastClosure;
63-
}
56+
_TypeSchemaEliminationVisitor(this.topType, this.bottomType);
6457

6558
@override
66-
DartType defaultDartType(DartType node) {
59+
DartType defaultDartType(DartType node, int variance) {
60+
bool isLeastClosure = variance == Variance.covariant;
6761
if (node is UnknownType) {
6862
return isLeastClosure ? bottomType : topType;
6963
}
@@ -84,9 +78,9 @@ class _TypeSchemaEliminationVisitor extends ReplacementVisitor {
8478
assert(bottomType == const NeverType(Nullability.nonNullable) ||
8579
bottomType is NullType);
8680
_TypeSchemaEliminationVisitor visitor =
87-
new _TypeSchemaEliminationVisitor(isLeastClosure, topType, bottomType);
88-
DartType result = schema.accept(visitor);
89-
assert(visitor.isLeastClosure == isLeastClosure);
81+
new _TypeSchemaEliminationVisitor(topType, bottomType);
82+
DartType result = schema.accept1(
83+
visitor, isLeastClosure ? Variance.covariant : Variance.contravariant);
9084
return result ?? schema;
9185
}
9286
}

0 commit comments

Comments
 (0)