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

Commit 933439b

Browse files
author
Dart CI
committed
Version 2.12.0-14.0.dev
Merge commit '6cfd46e177c1d62ed77e598d1468896919d3403f' into 'dev'
2 parents d257741 + 6cfd46e commit 933439b

37 files changed

+3458
-1216
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ opted out of null safety by adding `// @dart=2.9` to the beginning of the file.
3939
`--enable-assert-initializers` command line options. These options haven't
4040
been supported in a while and were no-ops.
4141

42+
#### dartfmt
43+
44+
* Don't duplicate comments on chained if elements.
45+
* Preserve `?` in initializing formal function-typed parameters.
46+
4247
#### Linter
4348

4449
Updated the Linter to `0.1.122`, which includes:

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ vars = {
9898
# and land the review.
9999
#
100100
# For more details, see https://github.com/dart-lang/sdk/issues/30164
101-
"dart_style_tag": "1.3.8+1", # Please see the note above before updating.
101+
"dart_style_tag": "1.3.9", # Please see the note above before updating.
102102

103103
"chromedriver_tag": "83.0.4103.39",
104104
"dartdoc_rev" : "72c69f8659ce8823ce2dde9a4f758b0fa617ab5e",

pkg/dart_internal/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.12-nullsafety.1
2+
3+
- Support the latest Dart SDK.
4+
15
## 0.1.10
26

37
- Support the latest Dart SDK.

pkg/dart_internal/pubspec.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: dart_internal
2-
version: 0.1.12-nullsafety
3-
author: "Dart Team <[email protected]>"
4-
homepage: http://www.dartlang.org
2+
version: 0.1.12-nullsafety.1
53
repository: https://github.com/dart-lang/sdk/tree/master/pkg/dart_internal
64
description: >
75
This package is not intended for wide use. It provides a temporary API to
@@ -18,4 +16,4 @@ description: >
1816
environment:
1917
# Restrict the upper bound so that we can remove support for this in a later
2018
# version of the SDK without it being a breaking change.
21-
sdk: ">=2.10.0-0 <2.11.0"
19+
sdk: ">=2.10.0-0 <2.12.0"

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
581581

582582
var finishGenericTypeTest = _emitClassTypeTests(c, className, body);
583583

584-
// Attach caches on all canonicalized types not in our runtime.
585-
// Types in the runtime will have caches attached in their constructors.
586-
if (!isSdkInternalRuntime(_currentLibrary)) {
587-
body.add(runtimeStatement('addTypeCaches(#)', [className]));
588-
}
584+
// Attach caches on all canonicalized types.
585+
body.add(runtimeStatement('addTypeCaches(#)', [className]));
589586

590587
_emitVirtualFieldSymbols(c, body);
591588
_emitClassSignature(c, className, body);
@@ -1082,29 +1079,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
10821079
}
10831080

10841081
if (c == _coreTypes.deprecatedFutureOrClass) {
1085-
// These methods are difficult to place in the runtime or patch files.
1086-
// * They need to be callable from the class but they can't be static
1087-
// methods on the FutureOr class in Dart because they reference the
1088-
// generic type parameter.
1089-
// * There isn't an obvious place in dart:_runtime were we could place a
1090-
// method that adds these type tests (similar to addTypeTests()) because
1091-
// in the bootstrap ordering the Future class hasn't been defined yet.
1092-
var typeParam =
1093-
TypeParameterType(c.typeParameters[0], Nullability.undetermined);
1094-
var typeT = visitTypeParameterType(typeParam);
1095-
var futureOfT = visitInterfaceType(InterfaceType(
1096-
_coreTypes.futureClass, currentLibrary.nonNullable, [typeParam]));
1097-
body.add(js.statement('''
1098-
#.is = function is_FutureOr(o) {
1099-
return #.is(o) || #.is(o);
1100-
}
1101-
''', [className, typeT, futureOfT]));
1102-
body.add(js.statement('''
1103-
#.as = function as_FutureOr(o) {
1104-
if (#.is(o) || #.is(o)) return o;
1105-
return #.as(o, this);
1106-
}
1107-
''', [className, typeT, futureOfT, runtimeModule]));
1082+
// Custom type tests for FutureOr types are attached when the type is
1083+
// constructed in the runtime normalizeFutureOr method.
11081084
return null;
11091085
}
11101086

pkg/nnbd_migration/lib/src/edit_plan.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,11 @@ class EditPlanner {
495495
}
496496
}
497497

498-
/// Creates a new edit plan that removes [node] from the AST.
498+
/// Creates a new edit plan that removes [sourceNode] from the AST.
499499
///
500-
/// [node] must be one element of a variable length sequence maintained by
501-
/// [node]'s parent (for example, a statement in a block, an element in a
502-
/// list, a declaration in a class, etc.). If it is not, an exception is
500+
/// [sourceNode] must be one element of a variable length sequence maintained
501+
/// by [sourceNode]'s parent (for example, a statement in a block, an element
502+
/// in a list, a declaration in a class, etc.). If it is not, an exception is
503503
/// thrown.
504504
///
505505
/// Optional argument [info] contains information about why the change was
@@ -674,9 +674,10 @@ class EditPlanner {
674674
///
675675
/// Optional argument [info] contains information about why the change was
676676
/// made.
677-
EditPlan tryRemoveNode(AstNode sourceNode, {AtomicEditInfo info}) {
677+
EditPlan tryRemoveNode(AstNode sourceNode,
678+
{List<AstNode> sequenceNodes, AtomicEditInfo info}) {
678679
var parent = sourceNode.parent;
679-
var sequenceNodes = _computeSequenceNodes(parent);
680+
sequenceNodes ??= _computeSequenceNodes(parent);
680681
if (sequenceNodes == null) {
681682
return null;
682683
}
@@ -809,6 +810,8 @@ class EditPlanner {
809810
return node.elements;
810811
} else if (node is ArgumentList) {
811812
return node.arguments;
813+
} else if (node is FormalParameter) {
814+
return node.metadata;
812815
} else if (node is FormalParameterList) {
813816
return node.parameters;
814817
} else if (node is VariableDeclarationList) {
@@ -1525,7 +1528,8 @@ class _PassThroughBuilderImpl implements PassThroughBuilder {
15251528
AstNode parent, List<AstNode> childNodes) {
15261529
if (parent is Block ||
15271530
parent is ClassDeclaration ||
1528-
parent is CompilationUnit) {
1531+
parent is CompilationUnit ||
1532+
parent is FormalParameter) {
15291533
// These parent types don't use separators.
15301534
return null;
15311535
} else {

pkg/nnbd_migration/lib/src/fix_aggregator.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,14 @@ class NodeChangeForDefaultFormalParameter
666666
/// contained in the edit.
667667
AtomicEditInfo addRequiredKeywordInfo;
668668

669+
/// If non-null, indicates a `@required` annotation which should be removed
670+
/// from this node.
671+
Annotation annotationToRemove;
672+
673+
/// If [annotationToRemove] is non-null, the information that should be
674+
/// contained in the edit.
675+
AtomicEditInfo removeAnnotationInfo;
676+
669677
NodeChangeForDefaultFormalParameter() : super._();
670678

671679
@override
@@ -676,8 +684,17 @@ class NodeChangeForDefaultFormalParameter
676684
EditPlan _apply(DefaultFormalParameter node, FixAggregator aggregator) {
677685
var innerPlan = aggregator.innerPlanForNode(node);
678686
if (!addRequiredKeyword) return innerPlan;
679-
return aggregator.planner.surround(innerPlan,
680-
prefix: [AtomicEdit.insert('required ', info: addRequiredKeywordInfo)]);
687+
688+
var offset = node.firstTokenAfterCommentAndMetadata.offset;
689+
return aggregator.planner.passThrough(node, innerPlans: [
690+
aggregator.planner.insertText(node, offset, [
691+
AtomicEdit.insert('required ', info: addRequiredKeywordInfo),
692+
]),
693+
if (annotationToRemove != null)
694+
aggregator.planner
695+
.removeNode(annotationToRemove, info: removeAnnotationInfo),
696+
...aggregator.innerPlansForNode(node),
697+
]);
681698
}
682699
}
683700

pkg/nnbd_migration/lib/src/fix_builder.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,20 +1145,33 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor<void>
11451145
cls.name, method.name, element.name),
11461146
{FixReasonTarget.root: node});
11471147
var metadata = parameter.metadata;
1148-
for (var annotation in metadata) {
1149-
if (annotation.elementAnnotation.isRequired) {
1150-
// TODO(paulberry): what if `@required` isn't the first annotation?
1151-
// Will we produce something that isn't grammatical?
1152-
(_fixBuilder._getChange(annotation) as NodeChangeForAnnotation)
1148+
if (metadata != null && metadata.isNotEmpty) {
1149+
// Only the last annotation can be changed into a `required` keyword;
1150+
// changing an earlier annotation into a keyword would be illegal.
1151+
var lastAnnotation = metadata.last;
1152+
if (lastAnnotation.elementAnnotation.isRequired) {
1153+
(_fixBuilder._getChange(lastAnnotation) as NodeChangeForAnnotation)
11531154
..changeToRequiredKeyword = true
11541155
..changeToRequiredKeywordInfo = info;
11551156
return;
11561157
}
11571158
}
11581159
// Otherwise create a new `required` keyword.
1159-
(_fixBuilder._getChange(parameter) as NodeChangeForDefaultFormalParameter)
1160+
var nodeChange = (_fixBuilder._getChange(parameter)
1161+
as NodeChangeForDefaultFormalParameter)
11601162
..addRequiredKeyword = true
11611163
..addRequiredKeywordInfo = info;
1164+
var requiredAnnotation = metadata?.firstWhere(
1165+
(annotation) => annotation.elementAnnotation.isRequired,
1166+
orElse: () => null);
1167+
if (requiredAnnotation != null) {
1168+
// If the parameter was annotated with `@required`, but it was not the
1169+
// last annotation, we remove the annotation in addition to adding the
1170+
// `required` keyword.
1171+
nodeChange
1172+
..annotationToRemove = requiredAnnotation
1173+
..removeAnnotationInfo = info;
1174+
}
11621175
}
11631176

11641177
void _makeTypeNameNullable(TypeAnnotation node, DecoratedType decoratedType) {

pkg/nnbd_migration/lib/src/node_builder.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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 'package:_fe_analyzer_shared/src/scanner/token.dart';
65
import 'package:analyzer/dart/ast/ast.dart';
76
import 'package:analyzer/dart/ast/visitor.dart';
87
import 'package:analyzer/dart/element/element.dart';
@@ -894,40 +893,3 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
894893
throw UnimplementedError(buffer.toString());
895894
}
896895
}
897-
898-
extension on FormalParameter {
899-
// TODO(srawlins): Add this to FormalParameter interface.
900-
Token get firstTokenAfterCommentAndMetadata {
901-
var parameter = this is DefaultFormalParameter
902-
? (this as DefaultFormalParameter).parameter
903-
: this as NormalFormalParameter;
904-
if (parameter is FieldFormalParameter) {
905-
if (parameter.keyword != null) {
906-
return parameter.keyword;
907-
} else if (parameter.type != null) {
908-
return parameter.type.beginToken;
909-
} else {
910-
return parameter.thisKeyword;
911-
}
912-
} else if (parameter is FunctionTypedFormalParameter) {
913-
if (parameter.covariantKeyword != null) {
914-
return parameter.covariantKeyword;
915-
} else if (parameter.returnType != null) {
916-
return parameter.returnType.beginToken;
917-
} else {
918-
return parameter.identifier.token;
919-
}
920-
} else if (parameter is SimpleFormalParameter) {
921-
if (parameter.covariantKeyword != null) {
922-
return parameter.covariantKeyword;
923-
} else if (parameter.keyword != null) {
924-
return parameter.keyword;
925-
} else if (parameter.type != null) {
926-
return parameter.type.beginToken;
927-
} else {
928-
return parameter.identifier.token;
929-
}
930-
}
931-
return null;
932-
}
933-
}

pkg/nnbd_migration/lib/src/utilities/hint_utils.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
6+
import 'package:analyzer/dart/ast/ast.dart';
67
import 'package:nnbd_migration/src/edit_plan.dart';
78

89
/// Determines if the given [token] is followed by a nullability hint, and if
@@ -226,3 +227,40 @@ enum HintCommentKind {
226227
/// required.
227228
required,
228229
}
230+
231+
extension FormalParameterExtensions on FormalParameter {
232+
// TODO(srawlins): Add this to FormalParameter interface.
233+
Token get firstTokenAfterCommentAndMetadata {
234+
var parameter = this is DefaultFormalParameter
235+
? (this as DefaultFormalParameter).parameter
236+
: this as NormalFormalParameter;
237+
if (parameter is FieldFormalParameter) {
238+
if (parameter.keyword != null) {
239+
return parameter.keyword;
240+
} else if (parameter.type != null) {
241+
return parameter.type.beginToken;
242+
} else {
243+
return parameter.thisKeyword;
244+
}
245+
} else if (parameter is FunctionTypedFormalParameter) {
246+
if (parameter.covariantKeyword != null) {
247+
return parameter.covariantKeyword;
248+
} else if (parameter.returnType != null) {
249+
return parameter.returnType.beginToken;
250+
} else {
251+
return parameter.identifier.token;
252+
}
253+
} else if (parameter is SimpleFormalParameter) {
254+
if (parameter.covariantKeyword != null) {
255+
return parameter.covariantKeyword;
256+
} else if (parameter.keyword != null) {
257+
return parameter.keyword;
258+
} else if (parameter.type != null) {
259+
return parameter.type.beginToken;
260+
} else {
261+
return parameter.identifier.token;
262+
}
263+
}
264+
return null;
265+
}
266+
}

0 commit comments

Comments
 (0)