Version 2.14.0-215.0.dev
Merge commit 'f4b4882f4811edd8d1a8d9f43b301f542c1538d3' into 'dev'
diff --git a/DEPS b/DEPS
index 2359e52..f63c925 100644
--- a/DEPS
+++ b/DEPS
@@ -44,7 +44,7 @@
# co19 is a cipd package. Use update.sh in tests/co19[_2] to update these
# hashes. It requires access to the dart-build-access group, which EngProd
# has.
- "co19_rev": "26019f5b2efb294eacddfef6ce443083979feff5",
+ "co19_rev": "dfab47fd11fb47a8475e77765fdb183a8002fe4e",
"co19_2_rev": "1c2e425f461bfae7de6db7014fc44a58fc72b4a8",
# The internal benchmarks to use. See go/dart-benchmarks-internal
diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
index 68e4192..8c0af08 100644
--- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
@@ -674,6 +674,7 @@
void visitExportDirective(ExportDirective node) {
computer._addRegion_node(node, HighlightRegionType.DIRECTIVE);
computer._addRegion_token(node.keyword, HighlightRegionType.BUILT_IN);
+ _addRegions_configurations(node.configurations);
super.visitExportDirective(node);
}
@@ -821,6 +822,7 @@
computer._addRegion_token(
node.deferredKeyword, HighlightRegionType.BUILT_IN);
computer._addRegion_token(node.asKeyword, HighlightRegionType.BUILT_IN);
+ _addRegions_configurations(node.configurations);
super.visitImportDirective(node);
}
@@ -1108,6 +1110,14 @@
super.visitYieldStatement(node);
}
+ void _addRegions_configurations(List<Configuration> configurations) {
+ for (final configuration in configurations) {
+ computer._addRegion_token(
+ configuration.ifKeyword, HighlightRegionType.BUILT_IN,
+ semanticTokenModifiers: {CustomSemanticTokenModifiers.control});
+ }
+ }
+
void _addRegions_functionBody(FunctionBody node) {
var keyword = node.keyword;
if (keyword != null) {
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart
index 8277894..655d3dd 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'package:analysis_server/src/protocol_server.dart'
+ show CompletionSuggestionKind;
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
import 'package:analysis_server/src/utilities/extensions/element.dart';
@@ -27,6 +29,10 @@
memberBuilder = MemberSuggestionBuilder(request, builder);
+ var defaultKind = request.target.isFunctionalArgument()
+ ? CompletionSuggestionKind.IDENTIFIER
+ : request.opType.suggestKind;
+
// Recompute the target because resolution might have changed it.
var expression = request.dotTarget;
@@ -40,7 +46,7 @@
if (classOrMixin != null) {
var type = classOrMixin.declaredElement?.thisType;
if (type != null) {
- _addExtensionMembers(containingLibrary, type);
+ _addExtensionMembers(containingLibrary, defaultKind, type);
}
} else {
var extension = request.target.containingNode
@@ -53,9 +59,9 @@
var inheritanceDistance = memberBuilder.request.featureComputer
.inheritanceDistanceFeature(
extendedType.element, type.element);
- _addTypeMembers(type, inheritanceDistance);
+ _addTypeMembers(type, defaultKind, inheritanceDistance);
}
- _addExtensionMembers(containingLibrary, extendedType);
+ _addExtensionMembers(containingLibrary, defaultKind, extendedType);
}
}
}
@@ -81,7 +87,7 @@
if (expression is ExtensionOverride) {
var staticElement = expression.staticElement;
if (staticElement != null) {
- _addInstanceMembers(staticElement, 0.0);
+ _addInstanceMembers(staticElement, defaultKind, 0.0);
}
} else {
var type = expression.staticType;
@@ -99,12 +105,13 @@
// invoked on a non-null value.
type = containingLibrary.typeSystem.promoteToNonNull(type);
}
- _addExtensionMembers(containingLibrary, type);
+ _addExtensionMembers(containingLibrary, defaultKind, type);
expression.staticType;
}
}
- void _addExtensionMembers(LibraryElement containingLibrary, DartType type) {
+ void _addExtensionMembers(LibraryElement containingLibrary,
+ CompletionSuggestionKind? kind, DartType type) {
var typeSystem = containingLibrary.typeSystem;
var nameScope = containingLibrary.scope;
for (var extension in nameScope.extensions) {
@@ -118,17 +125,19 @@
}
// TODO(brianwilkerson) We might want to apply the substitution to the
// members of the extension for display purposes.
- _addInstanceMembers(extension, inheritanceDistance);
+ _addInstanceMembers(extension, kind, inheritanceDistance);
}
}
}
- void _addInstanceMembers(
- ExtensionElement extension, double inheritanceDistance) {
+ void _addInstanceMembers(ExtensionElement extension,
+ CompletionSuggestionKind? kind, double inheritanceDistance) {
for (var method in extension.methods) {
if (!method.isStatic) {
memberBuilder.addSuggestionForMethod(
- method: method, inheritanceDistance: inheritanceDistance);
+ method: method,
+ kind: kind,
+ inheritanceDistance: inheritanceDistance);
}
}
for (var accessor in extension.accessors) {
@@ -139,10 +148,11 @@
}
}
- void _addTypeMembers(InterfaceType type, double inheritanceDistance) {
+ void _addTypeMembers(InterfaceType type, CompletionSuggestionKind? kind,
+ double inheritanceDistance) {
for (var method in type.methods) {
memberBuilder.addSuggestionForMethod(
- method: method, inheritanceDistance: inheritanceDistance);
+ method: method, kind: kind, inheritanceDistance: inheritanceDistance);
}
for (var accessor in type.accessors) {
memberBuilder.addSuggestionForAccessor(
diff --git a/pkg/analysis_server/test/analysis/notification_highlights2_test.dart b/pkg/analysis_server/test/analysis/notification_highlights2_test.dart
index 301ef96..89296f2 100644
--- a/pkg/analysis_server/test/analysis/notification_highlights2_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_highlights2_test.dart
@@ -538,6 +538,33 @@
assertHasStringRegion(HighlightRegionType.DIRECTIVE, "part 'part.dart';");
}
+ Future<void> test_DIRECTIVE_configuration() async {
+ addTestFile('''
+import 'dart:math'
+ if (dart.library.io) 'dart:io'
+ if (dart.library.html) 'dart:html';
+export 'dart:math'
+ if (dart.library.io) 'dart:io'
+ if (dart.library.html) 'dart:html';
+''');
+ await prepareHighlights();
+
+ assertHasStringRegion(HighlightRegionType.DIRECTIVE, '''
+import 'dart:math'
+ if (dart.library.io) 'dart:io'
+ if (dart.library.html) 'dart:html';''');
+
+ assertHasStringRegion(HighlightRegionType.DIRECTIVE, '''
+export 'dart:math'
+ if (dart.library.io) 'dart:io'
+ if (dart.library.html) 'dart:html';''');
+
+ assertHasStringRegion(HighlightRegionType.BUILT_IN, 'if');
+ assertHasStringRegion(HighlightRegionType.LITERAL_STRING, "'dart:math'");
+ assertHasStringRegion(HighlightRegionType.LITERAL_STRING, "'dart:io'");
+ assertHasStringRegion(HighlightRegionType.LITERAL_STRING, "'dart:html'");
+ }
+
Future<void> test_DIRECTIVE_partOf() async {
addTestFile('''
part of lib;
diff --git a/pkg/analysis_server/test/domain_completion_test.dart b/pkg/analysis_server/test/domain_completion_test.dart
index fd933fa..da117aa 100644
--- a/pkg/analysis_server/test/domain_completion_test.dart
+++ b/pkg/analysis_server/test/domain_completion_test.dart
@@ -263,6 +263,22 @@
assertHasResult(CompletionSuggestionKind.INVOCATION, 'foo');
}
+ Future<void> test_extension() async {
+ addTestFile('''
+class MyClass {
+ void foo() {
+ ba^
+ }
+}
+
+extension MyClassExtension on MyClass {
+ void bar() {}
+}
+''');
+ await getSuggestions();
+ assertHasResult(CompletionSuggestionKind.INVOCATION, 'bar');
+ }
+
Future<void> test_html() {
//
// We no longer support the analysis of non-dart files.
@@ -596,7 +612,7 @@
''');
await getSuggestions();
assertHasResult(CompletionSuggestionKind.IDENTIFIER, 'bar');
- assertHasResult(CompletionSuggestionKind.INVOCATION, 'baz');
+ assertHasResult(CompletionSuggestionKind.IDENTIFIER, 'baz');
}
Future<void> test_inherited() {
diff --git a/pkg/analysis_server/test/lsp/semantic_tokens_test.dart b/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
index c688729..ed99582 100644
--- a/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
+++ b/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
@@ -380,7 +380,9 @@
final content = '''
import 'package:flutter/material.dart';
export 'package:flutter/widgets.dart';
- import '../file.dart';
+ import '../file.dart'
+ if (dart.library.io) 'file_io.dart'
+ if (dart.library.html) 'file_html.dart';
library foo;
''';
@@ -392,6 +394,12 @@
_Token("'package:flutter/widgets.dart'", SemanticTokenTypes.string),
_Token('import', SemanticTokenTypes.keyword),
_Token("'../file.dart'", SemanticTokenTypes.string),
+ _Token('if', SemanticTokenTypes.keyword,
+ [CustomSemanticTokenModifiers.control]),
+ _Token("'file_io.dart'", SemanticTokenTypes.string),
+ _Token('if', SemanticTokenTypes.keyword,
+ [CustomSemanticTokenModifiers.control]),
+ _Token("'file_html.dart'", SemanticTokenTypes.string),
_Token('library', SemanticTokenTypes.keyword),
_Token('foo', SemanticTokenTypes.namespace),
];
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 2934d49..5afa05af 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -82,7 +82,7 @@
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
- static const int DATA_VERSION = 154;
+ static const int DATA_VERSION = 155;
/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
diff --git a/pkg/analyzer/lib/src/dart/ast/extensions.dart b/pkg/analyzer/lib/src/dart/ast/extensions.dart
index d261083..3df0bb6 100644
--- a/pkg/analyzer/lib/src/dart/ast/extensions.dart
+++ b/pkg/analyzer/lib/src/dart/ast/extensions.dart
@@ -92,6 +92,10 @@
}
extension FormalParameterExtension on FormalParameter {
+ bool get isOfLocalFunction {
+ return thisOrAncestorOfType<FunctionBody>() != null;
+ }
+
FormalParameter get notDefault {
var self = this;
if (self is DefaultFormalParameter) {
diff --git a/pkg/analyzer/lib/src/dart/element/extensions.dart b/pkg/analyzer/lib/src/dart/element/extensions.dart
index d1421ed..66ba586 100644
--- a/pkg/analyzer/lib/src/dart/element/extensions.dart
+++ b/pkg/analyzer/lib/src/dart/element/extensions.dart
@@ -52,12 +52,6 @@
}
extension ParameterElementExtensions on ParameterElement {
- bool get isParameterOfTopLevelFunction {
- var enclosing = enclosingElement;
- return enclosing is FunctionElement &&
- enclosing.enclosingElement is CompilationUnitElement;
- }
-
/// Return [ParameterElement] with the specified properties replaced.
ParameterElement copyWith({DartType? type, ParameterKind? kind}) {
return ParameterElementImpl.synthetic(
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
index 54882a1..0534495 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
@@ -2600,8 +2600,10 @@
hasPublishedDocs: true);
/**
- * When "strict-raw-types" is enabled, raw types must be inferred via the
- * context type, or have type arguments.
+ * When "strict-raw-types" is enabled, "raw types" must have type arguments.
+ *
+ * A "raw type" is a type name that does not use inference to fill in missing
+ * type arguments; instead, each type argument is instantiated to its bound.
*/
static const HintCode STRICT_RAW_TYPE = HintCode('STRICT_RAW_TYPE',
"The generic type '{0}' should have explicit type arguments but doesn't.",
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 805f0bc..72b1e6a 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -20,7 +20,6 @@
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
import 'package:analyzer/src/dart/element/element.dart';
-import 'package:analyzer/src/dart/element/extensions.dart';
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
import 'package:analyzer/src/dart/element/member.dart'
show ConstructorMember, Member;
@@ -1310,8 +1309,7 @@
super.visitDefaultFormalParameter(node);
ParameterElement element = node.declaredElement!;
- if (element is DefaultParameterElementImpl &&
- !element.isParameterOfTopLevelFunction) {
+ if (element is DefaultParameterElementImpl && node.isOfLocalFunction) {
element.constantInitializer = node.defaultValue;
}
}
diff --git a/pkg/analyzer/lib/src/summary2/informative_data.dart b/pkg/analyzer/lib/src/summary2/informative_data.dart
index a3e1768..62d03b7 100644
--- a/pkg/analyzer/lib/src/summary2/informative_data.dart
+++ b/pkg/analyzer/lib/src/summary2/informative_data.dart
@@ -164,6 +164,7 @@
(applier) {
applier.applyToMetadata(element);
applier.applyToTypeParameters(element.typeParameters);
+ applier.applyToFormalParameters(element.parameters);
},
);
}
@@ -263,7 +264,7 @@
info.constantOffsets,
(applier) {
applier.applyToMetadata(element);
- applier.applyToFormalParameters(element);
+ applier.applyToFormalParameters(element.parameters);
applier.applyToConstructorInitializers(element);
},
);
@@ -392,7 +393,7 @@
(applier) {
applier.applyToMetadata(element);
applier.applyToTypeParameters(element.typeParameters);
- applier.applyToFormalParameters(element);
+ applier.applyToFormalParameters(element.parameters);
},
);
}
@@ -492,6 +493,8 @@
info.libraryConstantOffsets,
(applier) {
applier.applyToMetadata(element);
+ applier.applyToDirectives(element.imports);
+ applier.applyToDirectives(element.exports);
},
);
}
@@ -523,7 +526,7 @@
(applier) {
applier.applyToMetadata(element);
applier.applyToTypeParameters(element.typeParameters);
- applier.applyToFormalParameters(element);
+ applier.applyToFormalParameters(element.parameters);
},
);
},
@@ -607,7 +610,7 @@
var aliasedElement = element.aliasedElement;
if (aliasedElement is FunctionTypedElementImpl) {
applier.applyToTypeParameters(aliasedElement.typeParameters);
- applier.applyToFormalParameters(aliasedElement);
+ applier.applyToFormalParameters(aliasedElement.parameters);
if (aliasedTypeParameters != null) {
_applyToTypeParameters(
aliasedElement.typeParameters,
@@ -1203,6 +1206,7 @@
_writeOffsets(
metadata: node.metadata,
typeParameters: node.functionExpression.typeParameters,
+ formalParameters: node.functionExpression.parameters,
);
},
);
@@ -1360,7 +1364,10 @@
sink.writeUInt30(1 + (node.identifier?.offset ?? -1));
var notDefault = node.notDefault;
- if (notDefault is FunctionTypedFormalParameter) {
+ if (notDefault is FieldFormalParameter) {
+ _writeTypeParameters(notDefault.typeParameters);
+ _writeFormalParameters(notDefault.parameters);
+ } else if (notDefault is FunctionTypedFormalParameter) {
_writeTypeParameters(notDefault.typeParameters);
_writeFormalParameters(notDefault.parameters);
} else {
@@ -1386,27 +1393,30 @@
_writeOffsets(
metadata: node.metadata,
typeParameters: node.typeParameters,
+ formalParameters: node.parameters,
);
},
);
}
void _writeLibraryName(CompilationUnit unit) {
+ Directive? firstDirective;
var nameOffset = -1;
var nameLength = 0;
- NodeList<Annotation>? metadata;
for (var directive in unit.directives) {
+ firstDirective ??= directive;
if (directive is LibraryDirective) {
nameOffset = directive.name.offset;
nameLength = directive.name.length;
- metadata = directive.metadata;
break;
}
}
sink.writeUInt30(1 + nameOffset);
sink.writeUInt30(nameLength);
_writeOffsets(
- metadata: metadata,
+ metadata: firstDirective?.metadata,
+ importDirectives: unit.directives.whereType<ImportDirective>(),
+ exportDirectives: unit.directives.whereType<ExportDirective>(),
);
}
@@ -1434,6 +1444,8 @@
void _writeOffsets({
NodeList<Annotation>? metadata,
+ Iterable<ImportDirective>? importDirectives,
+ Iterable<ExportDirective>? exportDirectives,
TypeParameterList? typeParameters,
FormalParameterList? formalParameters,
Expression? constantInitializer,
@@ -1443,6 +1455,14 @@
}) {
var collector = _OffsetsCollector();
+ void addDirectives(Iterable<Directive>? directives) {
+ if (directives != null) {
+ for (var directive in directives) {
+ directive.metadata.accept(collector);
+ }
+ }
+ }
+
void addTypeParameters(TypeParameterList? typeParameters) {
if (typeParameters != null) {
for (var typeParameter in typeParameters.typeParameters) {
@@ -1455,6 +1475,11 @@
if (formalParameters != null) {
for (var parameter in formalParameters.parameters) {
parameter.metadata.accept(collector);
+ addFormalParameters(
+ parameter is FunctionTypedFormalParameter
+ ? parameter.parameters
+ : null,
+ );
if (parameter is DefaultFormalParameter) {
parameter.defaultValue?.accept(collector);
}
@@ -1463,6 +1488,8 @@
}
metadata?.accept(collector);
+ addDirectives(importDirectives);
+ addDirectives(exportDirectives);
addTypeParameters(typeParameters);
addFormalParameters(formalParameters);
constantInitializer?.accept(collector);
@@ -1665,15 +1692,22 @@
}
}
+ void applyToDirectives(List<UriReferencedElement> elements) {
+ for (var element in elements) {
+ applyToMetadata(element);
+ }
+ }
+
void applyToEnumConstants(List<FieldElement> constants) {
for (var constant in constants) {
applyToMetadata(constant);
}
}
- void applyToFormalParameters(FunctionTypedElement element) {
- for (var parameter in element.parameters) {
+ void applyToFormalParameters(List<ParameterElement> formalParameters) {
+ for (var parameter in formalParameters) {
applyToMetadata(parameter);
+ applyToFormalParameters(parameter.parameters);
applyToConstantInitializer(parameter);
}
}
@@ -1899,6 +1933,12 @@
}
@override
+ void visitSimpleFormalParameter(SimpleFormalParameter node) {
+ _tokenOrNull(node.requiredKeyword);
+ super.visitSimpleFormalParameter(node);
+ }
+
+ @override
void visitSimpleIdentifier(SimpleIdentifier node) {
_tokenOrNull(node.token);
}
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 86ffd26..4961d3e 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -1066,7 +1066,7 @@
requiredPositional final this.x @28
type: dynamic Function(double)
parameters
- requiredPositional b @-1
+ requiredPositional b @37
type: double
accessors
synthetic get x @-1
@@ -1100,7 +1100,7 @@
requiredPositional final this.x @32
type: int Function(double)
parameters
- requiredPositional b @-1
+ requiredPositional b @41
type: double
accessors
synthetic get x @-1
@@ -1134,10 +1134,10 @@
requiredPositional final this.f @43
type: List<U> Function<T, U>(T)
typeParameters
- covariant T @-1
- covariant U @-1
+ covariant T @45
+ covariant U @48
parameters
- requiredPositional t @-1
+ requiredPositional t @53
type: T
accessors
synthetic get f @-1
@@ -13717,15 +13717,15 @@
constantInitializer
IsExpression
expression: IntegerLiteral
- literal: 0 @0
+ literal: 0 @14
staticType: int
- isOperator: is @0
+ isOperator: is @16
staticType: bool
type: TypeName
name: SimpleIdentifier
staticElement: dart:core::@class::int
staticType: null
- token: int @-1
+ token: int @19
type: int
returnType: void
''');
@@ -16394,7 +16394,7 @@
requiredPositional final this.a @16
type: int Function(int)
parameters
- requiredPositional b @-1
+ requiredPositional b @22
type: int
returnType: void
''');
@@ -17605,7 +17605,7 @@
staticElement: a@71
staticType: null
token: a @71
- requiredKeyword: required @0
+ requiredKeyword: required @58
type: TypeName
name: SimpleIdentifier
staticElement: dart:core::@class::int
@@ -18325,7 +18325,7 @@
name: SimpleIdentifier
staticElement: <null>
staticType: null
- token: foo @-1
+ token: foo @1
imports
<unresolved>
metadata
@@ -18335,7 +18335,7 @@
name: SimpleIdentifier
staticElement: <null>
staticType: null
- token: foo @-1
+ token: foo @1
definingUnit
''');
}
@@ -22654,7 +22654,7 @@
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @1
exports
foo.dart
metadata
@@ -22664,7 +22664,7 @@
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @1
definingUnit
topLevelVariables
static const a @28
@@ -23197,7 +23197,7 @@
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @1
imports
dart:math
metadata
@@ -23207,7 +23207,7 @@
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @1
definingUnit
topLevelVariables
static const a @29
@@ -23238,7 +23238,7 @@
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @1
imports
dart:math
metadata
@@ -23248,7 +23248,7 @@
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @1
combinators
show: Random
definingUnit
@@ -23322,12 +23322,12 @@
type: int
metadata
Annotation
- atSign.offset: 0
+ atSign.offset: 48
element: self::@getter::a
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @49
returnType: void
topLevelVariables
static const a @6
@@ -23998,12 +23998,12 @@
type: int
metadata
Annotation
- atSign.offset: 0
+ atSign.offset: 46
element: self::@getter::foo
name: SimpleIdentifier
staticElement: self::@getter::foo
staticType: null
- token: foo @-1
+ token: foo @47
returnType: void
topLevelVariables
static const foo @6
@@ -24693,12 +24693,12 @@
type: int
metadata
Annotation
- atSign.offset: 0
+ atSign.offset: 32
element: self::@getter::foo
name: SimpleIdentifier
staticElement: self::@getter::foo
staticType: null
- token: foo @-1
+ token: foo @33
returnType: void
''');
}
@@ -24946,12 +24946,12 @@
type: int
metadata
Annotation
- atSign.offset: 0
+ atSign.offset: 25
element: self::@getter::a
name: SimpleIdentifier
staticElement: self::@getter::a
staticType: null
- token: a @-1
+ token: a @26
returnType: void
''');
}
diff --git a/tests/language/const/map_test.dart b/tests/language/const/map_test.dart
index 19ced31..13c6720 100644
--- a/tests/language/const/map_test.dart
+++ b/tests/language/const/map_test.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import "package:expect/expect.dart";
+import 'package:expect/expect.dart';
/// Returns its argument.
///
@@ -15,7 +15,6 @@
main() {
// TODO(terry): Should check:
- // - const map is immutable
// - simple expressions are const e.g., 2 + 3, true && !false, etc.
// - const with final and/or static with same const attributes
// Additionally new class instances with a static const same identity
@@ -30,9 +29,65 @@
// Make sure that const maps use the == operator and not object identity. The
// specification does not explicitly require it, otherwise ints and Strings
// wouldn't make much sense as keys.
- var m = const {1: 42, "foo": 499, 2: "bar"};
- Expect.equals(42, m[getValueNonOptimized(1.0)]);
+ final map = const {1: 42, 'foo': 499, 2: 'bar'};
+ Expect.equals(42, map[getValueNonOptimized(1.0)]);
Expect.equals(
- 499, m[getValueNonOptimized(new String.fromCharCodes("foo".runes))]);
- Expect.equals('bar', m[getValueNonOptimized(2)]);
+ 499, map[getValueNonOptimized(new String.fromCharCodes('foo'.runes))]);
+ Expect.equals('bar', map[getValueNonOptimized(2)]);
+
+ void testThrowsNoModification(void Function() f) {
+ Expect.throws(f, (e) {
+ return e is UnsupportedError;
+ });
+
+ Expect.equals(42, map[getValueNonOptimized(1.0)]);
+ Expect.equals(
+ 499, map[getValueNonOptimized(new String.fromCharCodes('foo'.runes))]);
+ Expect.equals('bar', map[getValueNonOptimized(2)]);
+ Expect.isNull(map[1024]);
+ }
+
+ testThrowsNoModification(() {
+ map[1024] = 'something';
+ });
+
+ testThrowsNoModification(() {
+ map.addAll({1024: 'something'});
+ });
+
+ testThrowsNoModification(() {
+ map.putIfAbsent(1024, () => 'something');
+ });
+
+ testThrowsNoModification(() {
+ map.putIfAbsent(1, () => 1024);
+ });
+
+ testThrowsNoModification(() {
+ map.clear();
+ });
+
+ testThrowsNoModification(() {
+ map.remove(1024);
+ });
+
+ testThrowsNoModification(() {
+ map.remove(1);
+ });
+
+ testThrowsNoModification(() {
+ map.addEntries([MapEntry(1024, 'something')]);
+ });
+
+ testThrowsNoModification(() {
+ map.update(2, (Object value) => 42);
+ });
+
+ testThrowsNoModification(() {
+ map.updateAll((Object? key, Object? value) => '123');
+ });
+
+ testThrowsNoModification(() {
+ map.removeWhere((Object? key, Object? value) => true);
+ });
}
diff --git a/tests/language_2/const/map_test.dart b/tests/language_2/const/map_test.dart
index b0df3bc..bbd4a8f 100644
--- a/tests/language_2/const/map_test.dart
+++ b/tests/language_2/const/map_test.dart
@@ -4,7 +4,7 @@
// @dart = 2.9
-import "package:expect/expect.dart";
+import 'package:expect/expect.dart';
/// Returns its argument.
///
@@ -17,7 +17,6 @@
main() {
// TODO(terry): Should check:
- // - const map is immutable
// - simple expressions are const e.g., 2 + 3, true && !false, etc.
// - const with final and/or static with same const attributes
// Additionally new class instances with a static const same identity
@@ -32,9 +31,65 @@
// Make sure that const maps use the == operator and not object identity. The
// specification does not explicitly require it, otherwise ints and Strings
// wouldn't make much sense as keys.
- var m = const {1: 42, "foo": 499, 2: "bar"};
- Expect.equals(42, m[getValueNonOptimized(1.0)]);
+ final map = const {1: 42, 'foo': 499, 2: 'bar'};
+ Expect.equals(42, map[getValueNonOptimized(1.0)]);
Expect.equals(
- 499, m[getValueNonOptimized(new String.fromCharCodes("foo".runes))]);
- Expect.equals('bar', m[getValueNonOptimized(2)]);
+ 499, map[getValueNonOptimized(new String.fromCharCodes('foo'.runes))]);
+ Expect.equals('bar', map[getValueNonOptimized(2)]);
+
+ void testThrowsNoModification(void Function() f) {
+ Expect.throws(f, (e) {
+ return e is UnsupportedError;
+ });
+
+ Expect.equals(42, map[getValueNonOptimized(1.0)]);
+ Expect.equals(
+ 499, map[getValueNonOptimized(new String.fromCharCodes('foo'.runes))]);
+ Expect.equals('bar', map[getValueNonOptimized(2)]);
+ Expect.isNull(map[1024]);
+ }
+
+ testThrowsNoModification(() {
+ map[1024] = 'something';
+ });
+
+ testThrowsNoModification(() {
+ map.addAll({1024: 'something'});
+ });
+
+ testThrowsNoModification(() {
+ map.putIfAbsent(1024, () => 'something');
+ });
+
+ testThrowsNoModification(() {
+ map.putIfAbsent(1, () => 1024);
+ });
+
+ testThrowsNoModification(() {
+ map.clear();
+ });
+
+ testThrowsNoModification(() {
+ map.remove(1024);
+ });
+
+ testThrowsNoModification(() {
+ map.remove(1);
+ });
+
+ testThrowsNoModification(() {
+ map.addEntries([MapEntry(1024, 'something')]);
+ });
+
+ testThrowsNoModification(() {
+ map.update(2, (Object value) => 42);
+ });
+
+ testThrowsNoModification(() {
+ map.updateAll((Object key, Object value) => '123');
+ });
+
+ testThrowsNoModification(() {
+ map.removeWhere((Object key, Object value) => true);
+ });
}
diff --git a/tools/VERSION b/tools/VERSION
index 6636005..1ca8171 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 14
PATCH 0
-PRERELEASE 214
+PRERELEASE 215
PRERELEASE_PATCH 0
\ No newline at end of file