Version 2.0.0-dev.39.0
Merge commit 'b24a9d8ee6e338af83a54dfd672b387ba0978ada' into dev
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa39c4f..48ec197 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,11 +1,13 @@
+## 2.0.0-dev.39.0
+### Tool Changes
+#### Pub
+ * fixed bug in dart2js transformer when using the common front-end.
+
## 2.0.0-dev.38.0
## 2.0.0-dev.37.0
-
### Tool Changes
-
-* dart2js
-
+#### dart2js
* The dart2js compiler now uses the common front-end by default. This is a
step towards supporting Dart 2.0. At this time dart2js has no semantic
changes: the Dart 2.0 strong-mode semantics are not enabled, so dart2js
@@ -33,10 +35,13 @@
* this is the first version of dart2js that no longer supports
`--package-root`, which long ago was deprecated in favor of `--packages`.
+#### Pub
+
+* dart2js transformer runs with the common front-end.
+
## 2.0.0-dev.36.0
### Core library changes
-
* `dart:core`
* Temporarily disabled the `whereType` method until generic methods are
enabled on all platforms
diff --git a/DEPS b/DEPS
index 438d546..1c46318 100644
--- a/DEPS
+++ b/DEPS
@@ -115,7 +115,7 @@
"ply_rev": "@604b32590ffad5cbb82e4afef1d305512d06ae93",
"pool_tag": "@1.3.4",
"protobuf_tag": "@0.7.1",
- "pub_rev": "@d2755745e88b63448d0adfbf2d04af9050f45ed3",
+ "pub_rev": "@dbe8be2bb8bca9b26ba7bd583272c62f9a0153fd",
"pub_semver_tag": "@1.3.2",
"quiver_tag": "@5aaa3f58c48608af5b027444d561270b53f15dbf",
"resource_rev":"@af5a5bf65511943398146cf146e466e5f0b95cb9",
diff --git a/pkg/analysis_server/doc/api.html b/pkg/analysis_server/doc/api.html
index a656113..87a23ef 100644
--- a/pkg/analysis_server/doc/api.html
+++ b/pkg/analysis_server/doc/api.html
@@ -109,7 +109,7 @@
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
- 1.19.0
+ 1.20.0
</h1>
<p>
This document contains a specification of the API provided by the
diff --git a/pkg/analysis_server/lib/protocol/protocol_generated.dart b/pkg/analysis_server/lib/protocol/protocol_generated.dart
index 953ec2a..c5873a5 100644
--- a/pkg/analysis_server/lib/protocol/protocol_generated.dart
+++ b/pkg/analysis_server/lib/protocol/protocol_generated.dart
@@ -10952,6 +10952,8 @@
* "kind": FlutterOutlineKind
* "offset": int
* "length": int
+ * "codeOffset": int
+ * "codeLength": int
* "label": optional String
* "dartElement": optional Element
* "attributes": optional List<FlutterOutlineAttribute>
@@ -10974,6 +10976,10 @@
int _length;
+ int _codeOffset;
+
+ int _codeLength;
+
String _label;
Element _dartElement;
@@ -11042,6 +11048,34 @@
}
/**
+ * The offset of the first character of the element code, which is neither
+ * documentation, nor annotation.
+ */
+ int get codeOffset => _codeOffset;
+
+ /**
+ * The offset of the first character of the element code, which is neither
+ * documentation, nor annotation.
+ */
+ void set codeOffset(int value) {
+ assert(value != null);
+ this._codeOffset = value;
+ }
+
+ /**
+ * The length of the element code.
+ */
+ int get codeLength => _codeLength;
+
+ /**
+ * The length of the element code.
+ */
+ void set codeLength(int value) {
+ assert(value != null);
+ this._codeLength = value;
+ }
+
+ /**
* The text label of the node children of the node. It is provided for any
* FlutterOutlineKind.GENERIC node, where better information is not
* available.
@@ -11206,6 +11240,7 @@
}
FlutterOutline(FlutterOutlineKind kind, int offset, int length,
+ int codeOffset, int codeLength,
{String label,
Element dartElement,
List<FlutterOutlineAttribute> attributes,
@@ -11220,6 +11255,8 @@
this.kind = kind;
this.offset = offset;
this.length = length;
+ this.codeOffset = codeOffset;
+ this.codeLength = codeLength;
this.label = label;
this.dartElement = dartElement;
this.attributes = attributes;
@@ -11258,6 +11295,20 @@
} else {
throw jsonDecoder.mismatch(jsonPath, "length");
}
+ int codeOffset;
+ if (json.containsKey("codeOffset")) {
+ codeOffset =
+ jsonDecoder.decodeInt(jsonPath + ".codeOffset", json["codeOffset"]);
+ } else {
+ throw jsonDecoder.mismatch(jsonPath, "codeOffset");
+ }
+ int codeLength;
+ if (json.containsKey("codeLength")) {
+ codeLength =
+ jsonDecoder.decodeInt(jsonPath + ".codeLength", json["codeLength"]);
+ } else {
+ throw jsonDecoder.mismatch(jsonPath, "codeLength");
+ }
String label;
if (json.containsKey("label")) {
label = jsonDecoder.decodeString(jsonPath + ".label", json["label"]);
@@ -11319,7 +11370,7 @@
stateLength = jsonDecoder.decodeInt(
jsonPath + ".stateLength", json["stateLength"]);
}
- return new FlutterOutline(kind, offset, length,
+ return new FlutterOutline(kind, offset, length, codeOffset, codeLength,
label: label,
dartElement: dartElement,
attributes: attributes,
@@ -11342,6 +11393,8 @@
result["kind"] = kind.toJson();
result["offset"] = offset;
result["length"] = length;
+ result["codeOffset"] = codeOffset;
+ result["codeLength"] = codeLength;
if (label != null) {
result["label"] = label;
}
@@ -11390,6 +11443,8 @@
return kind == other.kind &&
offset == other.offset &&
length == other.length &&
+ codeOffset == other.codeOffset &&
+ codeLength == other.codeLength &&
label == other.label &&
dartElement == other.dartElement &&
listEqual(
@@ -11416,6 +11471,8 @@
hash = JenkinsSmiHash.combine(hash, kind.hashCode);
hash = JenkinsSmiHash.combine(hash, offset.hashCode);
hash = JenkinsSmiHash.combine(hash, length.hashCode);
+ hash = JenkinsSmiHash.combine(hash, codeOffset.hashCode);
+ hash = JenkinsSmiHash.combine(hash, codeLength.hashCode);
hash = JenkinsSmiHash.combine(hash, label.hashCode);
hash = JenkinsSmiHash.combine(hash, dartElement.hashCode);
hash = JenkinsSmiHash.combine(hash, attributes.hashCode);
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 87267c7..703297c 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -108,7 +108,7 @@
* The version of the analysis server. The value should be replaced
* automatically during the build.
*/
- static final String VERSION = '1.19.0';
+ static final String VERSION = '1.20.0';
/**
* The options of this server instance.
diff --git a/pkg/analysis_server/lib/src/flutter/flutter_outline_computer.dart b/pkg/analysis_server/lib/src/flutter/flutter_outline_computer.dart
index 5e66826..25dfe13 100644
--- a/pkg/analysis_server/lib/src/flutter/flutter_outline_computer.dart
+++ b/pkg/analysis_server/lib/src/flutter/flutter_outline_computer.dart
@@ -135,6 +135,8 @@
protocol.FlutterOutlineKind.DART_ELEMENT,
dartOutline.offset,
dartOutline.length,
+ dartOutline.codeOffset,
+ dartOutline.codeLength,
dartElement: dartOutline.element);
if (dartOutline.children != null) {
flutterOutline.children = dartOutline.children.map(_convert).toList();
@@ -206,7 +208,11 @@
}
return new protocol.FlutterOutline(
- protocol.FlutterOutlineKind.NEW_INSTANCE, node.offset, node.length,
+ protocol.FlutterOutlineKind.NEW_INSTANCE,
+ node.offset,
+ node.length,
+ node.offset,
+ node.length,
className: className,
attributes: attributes,
children: children,
@@ -229,7 +235,8 @@
}
int id = _addInstrumentationEdits(node);
- return new protocol.FlutterOutline(kind, node.offset, node.length,
+ return new protocol.FlutterOutline(
+ kind, node.offset, node.length, node.offset, node.length,
className: className,
variableName: variableName,
label: label,
diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart
index f050efa..19f1ac7 100644
--- a/pkg/analysis_server/test/abstract_context.dart
+++ b/pkg/analysis_server/test/abstract_context.dart
@@ -57,6 +57,8 @@
AnalysisDriver get driver => _driver;
+ bool get previewDart2 => driver.analysisOptions.previewDart2;
+
void addFlutterPackage() {
Folder libFolder = configureFlutterPackage(resourceProvider);
packageMap['flutter'] = [libFolder];
diff --git a/pkg/analysis_server/test/integration/support/protocol_matchers.dart b/pkg/analysis_server/test/integration/support/protocol_matchers.dart
index 20794fb..ae078f3 100644
--- a/pkg/analysis_server/test/integration/support/protocol_matchers.dart
+++ b/pkg/analysis_server/test/integration/support/protocol_matchers.dart
@@ -477,6 +477,8 @@
* "kind": FlutterOutlineKind
* "offset": int
* "length": int
+ * "codeOffset": int
+ * "codeLength": int
* "label": optional String
* "dartElement": optional Element
* "attributes": optional List<FlutterOutlineAttribute>
@@ -494,7 +496,9 @@
new LazyMatcher(() => new MatchesJsonObject("FlutterOutline", {
"kind": isFlutterOutlineKind,
"offset": isInt,
- "length": isInt
+ "length": isInt,
+ "codeOffset": isInt,
+ "codeLength": isInt
}, optionalFields: {
"label": isString,
"dartElement": isElement,
diff --git a/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart b/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart
index e3b1de3..6f5f0d9 100644
--- a/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart
+++ b/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart
@@ -169,6 +169,7 @@
importUri: importUri,
isDeprecated: isDeprecated,
elemFile: elemFile,
+ elemKind: ElementKind.CLASS,
elemOffset: elemOffset);
Element element = cs.element;
expect(element, isNotNull);
@@ -205,6 +206,7 @@
CompletionSuggestion cs = assertSuggest(name,
relevance: relevance,
importUri: importUri,
+ elemKind: ElementKind.CONSTRUCTOR,
elemOffset: elemOffset,
defaultArgListString: defaultArgListString,
defaultArgumentListTextRanges: defaultArgumentListTextRanges);
diff --git a/pkg/analysis_server/test/services/completion/dart/imported_reference_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/imported_reference_contributor_test.dart
index 6ae7e6b..41feab8 100644
--- a/pkg/analysis_server/test/services/completion/dart/imported_reference_contributor_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/imported_reference_contributor_test.dart
@@ -529,6 +529,9 @@
assertNotSuggested('a');
assertNotSuggested('main');
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertSuggestClass('Object');
assertNotSuggested('y');
}
@@ -618,6 +621,9 @@
assertNotSuggested('partT8');
assertSuggestClass('A', elemFile: '/testAB.dart');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertNotSuggested('_B');
assertSuggestClass('C');
assertNotSuggested('partBoo');
@@ -1188,6 +1194,9 @@
class Z { }''');
await computeSuggestions();
assertSuggestClass('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ }
assertNotSuggested('H');
}
@@ -1571,6 +1580,9 @@
assertNotSuggested('F2');
assertNotSuggested('T2');
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertSuggestFunction('F1', 'dynamic');
// TODO (danrubel) getter is being suggested instead of top level var
//assertSuggestImportedTopLevelVar('T1', 'int');
@@ -1617,6 +1629,9 @@
assertNotSuggested('F2');
assertNotSuggested('T2');
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertSuggestFunction('F1', 'dynamic');
// TODO (danrubel) getter is being suggested instead of top level var
//assertSuggestImportedTopLevelVar('T1', 'int');
@@ -1787,6 +1802,9 @@
expect(suggestion.docSummary, 'My class.\nShort description.');
expect(suggestion.docComplete,
'My class.\nShort description.\n\nLonger description.');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
}
test_doc_function() async {
@@ -1890,6 +1908,9 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertSuggestFunction('F1', '_B');
assertNotSuggested('C');
assertNotSuggested('foo');
@@ -2467,6 +2488,9 @@
assertNotSuggested('F2');
assertNotSuggested('T2');
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertSuggestFunction('F1', 'dynamic');
// TODO (danrubel) getter is being suggested instead of top level var
//assertSuggestImportedTopLevelVar('T1', 'int');
@@ -2687,11 +2711,16 @@
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
- assertNotSuggested('Object');
+ if (previewDart2) {
+ assertSuggestConstructor('Object');
+ assertSuggestConstructor('C1');
+ } else {
+ assertNotSuggested('Object');
+ assertNotSuggested('C1');
+ }
assertSuggestTopLevelVar('T1', null);
assertSuggestFunction('F1', null);
assertNotSuggested('D1');
- assertNotSuggested('C1');
assertNotSuggested('T2');
assertNotSuggested('F2');
assertNotSuggested('D2');
@@ -2966,6 +2995,9 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('Object');
+ if (previewDart2) {
+ assertSuggestConstructor('Object');
+ }
// Simulate unresolved imported library,
// in which case suggestions will have null return types (unresolved)
// The current DartCompletionRequest#resolveExpression resolves
@@ -3214,6 +3246,11 @@
assertNotSuggested('f');
assertNotSuggested('_g');
assertSuggestClass('bool');
+ if (previewDart2) {
+ // TODO(brianwilkerson) Should not suggest constructors for classes that
+ // cannot be instantiated.
+ assertSuggestConstructor('bool');
+ }
}
test_MethodDeclaration_parameters_named() async {
@@ -3457,6 +3494,9 @@
await computeSuggestions();
assertSuggestClass('ClassInLocalContext');
+ if (previewDart2) {
+ assertSuggestConstructor('ClassInLocalContext');
+ }
// Assert contributor does not include results from 2nd context.
assertNotSuggested('ClassFromAnotherContext');
}
@@ -3836,6 +3876,9 @@
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertNotSuggested('X');
assertNotSuggested('foo');
assertNotSuggested('bar');
diff --git a/pkg/analysis_server/test/services/completion/dart/local_constructor_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/local_constructor_contributor_test.dart
index 8f42b69..e6dfb14 100644
--- a/pkg/analysis_server/test/services/completion/dart/local_constructor_contributor_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/local_constructor_contributor_test.dart
@@ -91,7 +91,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('Object');
assertNotSuggested('main');
assertNotSuggested('baz');
@@ -118,7 +122,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('Object');
assertNotSuggested('main');
assertNotSuggested('baz');
@@ -146,7 +154,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('main');
@@ -176,7 +188,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('main');
@@ -204,7 +220,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('Object');
assertNotSuggested('main');
assertNotSuggested('baz');
@@ -231,7 +251,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('Object');
assertNotSuggested('main');
assertNotSuggested('baz');
@@ -259,7 +283,11 @@
assertNotSuggested('bar');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('main');
@@ -286,7 +314,11 @@
assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
assertNotSuggested('hasLength');
assertNotSuggested('identical');
- assertNotSuggested('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ } else {
+ assertNotSuggested('B');
+ }
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('main');
@@ -347,7 +379,11 @@
expect(replacementLength, 0);
assertNotSuggested('a');
assertNotSuggested('main');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('Object');
}
@@ -363,7 +399,11 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('int');
// TODO (danrubel) When entering 1st of 2 identifiers on assignment LHS
// the user may be either (1) entering a type for the assignment
@@ -388,7 +428,11 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('int');
// Allow non-types preceding an identifier on LHS of assignment
// if newline follows first identifier
@@ -410,7 +454,11 @@
expect(replacementOffset, completionOffset - 3);
expect(replacementLength, 3);
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('int');
// TODO (danrubel) When entering 1st of 2 identifiers on assignment LHS
// the user may be either (1) entering a type for the assignment
@@ -435,7 +483,11 @@
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('int');
// Allow non-types preceding an identifier on LHS of assignment
// if newline follows first identifier
@@ -456,7 +508,11 @@
expect(replacementLength, 0);
assertNotSuggested('a');
assertNotSuggested('main');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('Object');
}
@@ -533,8 +589,13 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
- assertNotSuggested('X');
- assertNotSuggested('Z');
+ if (previewDart2) {
+ assertSuggestConstructor('X');
+ assertSuggestConstructor('Z');
+ } else {
+ assertNotSuggested('X');
+ assertNotSuggested('Z');
+ }
assertNotSuggested('a');
assertNotSuggested('b');
assertNotSuggested('localF');
@@ -926,8 +987,13 @@
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
- assertNotSuggested('X');
- assertNotSuggested('Z');
+ if (previewDart2) {
+ assertSuggestConstructor('X');
+ assertSuggestConstructor('Z');
+ } else {
+ assertNotSuggested('X');
+ assertNotSuggested('Z');
+ }
assertNotSuggested('a');
assertNotSuggested('b');
assertNotSuggested('f');
@@ -1175,8 +1241,13 @@
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('a');
- assertNotSuggested('A');
- assertNotSuggested('X');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ assertSuggestConstructor('X');
+ } else {
+ assertNotSuggested('A');
+ assertNotSuggested('X');
+ }
// top level results are partially filtered
//assertNotSuggested('Object');
assertNotSuggested('==');
@@ -1447,7 +1518,11 @@
assertNotSuggested('x');
assertNotSuggested('f');
assertNotSuggested('foo');
- assertNotSuggested('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ } else {
+ assertNotSuggested('C');
+ }
assertNotSuggested('F2');
assertNotSuggested('T2');
assertNotSuggested('A');
@@ -1493,7 +1568,11 @@
assertNotSuggested('x');
assertNotSuggested('f');
assertNotSuggested('foo');
- assertNotSuggested('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ } else {
+ assertNotSuggested('C');
+ }
assertNotSuggested('F2');
assertNotSuggested('T2');
assertNotSuggested('A');
@@ -1679,7 +1758,11 @@
expect(replacementLength, 0);
assertNotSuggested('foo');
assertNotSuggested('a');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('String');
assertNotSuggested('identical');
assertNotSuggested('bar');
@@ -1718,12 +1801,15 @@
expect(replacementLength, 0);
assertNotSuggested('A');
assertNotSuggested('F1');
- assertNotSuggested('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ } else {
+ assertNotSuggested('C');
+ }
assertNotSuggested('foo');
assertNotSuggested('bar');
assertNotSuggested('F2');
assertNotSuggested('Clz');
- assertNotSuggested('C');
assertNotSuggested('x');
assertNotSuggested('_B');
}
@@ -2104,7 +2190,11 @@
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('Object');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('==');
}
@@ -2119,7 +2209,11 @@
expect(replacementLength, 0);
assertNotSuggested('a');
assertNotSuggested('main');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('Object');
}
@@ -2134,7 +2228,11 @@
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('Object');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('==');
}
@@ -2218,7 +2316,11 @@
assertNotSuggested('x');
assertNotSuggested('f');
assertNotSuggested('foo');
- assertNotSuggested('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ } else {
+ assertNotSuggested('C');
+ }
assertNotSuggested('F2');
assertNotSuggested('T2');
assertNotSuggested('A');
@@ -2506,7 +2608,11 @@
assertNotSuggested('T2');
assertNotSuggested('F2');
assertNotSuggested('D2');
- assertNotSuggested('C2');
+ if (previewDart2) {
+ assertSuggestConstructor('C2');
+ } else {
+ assertNotSuggested('C2');
+ }
assertNotSuggested('name');
}
@@ -2536,7 +2642,11 @@
assertNotSuggested('T2');
assertNotSuggested('F2');
assertNotSuggested('D2');
- assertNotSuggested('C2');
+ if (previewDart2) {
+ assertSuggestConstructor('C2');
+ } else {
+ assertNotSuggested('C2');
+ }
assertNotSuggested('name');
}
@@ -2618,7 +2728,11 @@
assertNotSuggested('main');
assertNotSuggested('foo');
assertNotSuggested('bar');
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('Object');
}
@@ -2739,7 +2853,11 @@
assertNotSuggested('T2');
assertNotSuggested('F2');
assertNotSuggested('D2');
- assertNotSuggested('C2');
+ if (previewDart2) {
+ assertSuggestConstructor('C2');
+ } else {
+ assertNotSuggested('C2');
+ }
}
test_MapLiteralEntry1() async {
@@ -3461,7 +3579,11 @@
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertNotSuggested('A');
- assertNotSuggested('X');
+ if (previewDart2) {
+ assertSuggestConstructor('X');
+ } else {
+ assertNotSuggested('X');
+ }
assertNotSuggested('foo');
assertNotSuggested('bar');
assertNotSuggested('_B');
@@ -3663,7 +3785,11 @@
addTestSource('class A {String g(int x) {var t; switch(x) {case 0: ^}}}');
await computeSuggestions();
- assertNotSuggested('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ } else {
+ assertNotSuggested('A');
+ }
assertNotSuggested('g');
assertNotSuggested('t');
assertNotSuggested('String');
@@ -4009,7 +4135,11 @@
assertNotSuggested('X');
assertNotSuggested('_B');
assertNotSuggested('Y');
- assertNotSuggested('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ } else {
+ assertNotSuggested('C');
+ }
assertNotSuggested('f');
assertNotSuggested('x');
assertNotSuggested('e');
@@ -4041,7 +4171,11 @@
assertNotSuggested('bar2');
assertNotSuggested('_B');
assertNotSuggested('Y');
- assertNotSuggested('C');
+ if (previewDart2) {
+ assertSuggestConstructor('C');
+ } else {
+ assertNotSuggested('C');
+ }
assertNotSuggested('f');
assertNotSuggested('x');
assertNotSuggested('e');
diff --git a/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart
index abe72fc..0df1a0b 100644
--- a/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart
@@ -219,6 +219,9 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
+ if (previewDart2) {
+ assertSuggestConstructor('A');
+ }
assertSuggestFunction('af', 'int',
relevance: DART_RELEVANCE_LOCAL_FUNCTION);
assertSuggestTopLevelVar('m', null,
@@ -263,6 +266,9 @@
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('B');
+ if (previewDart2) {
+ assertSuggestConstructor('B');
+ }
assertSuggestFunction('bf', 'int',
relevance: DART_RELEVANCE_LOCAL_FUNCTION);
assertSuggestTopLevelVar('n', null,
diff --git a/pkg/analysis_server/test/services/correction/assist_test.dart b/pkg/analysis_server/test/services/correction/assist_test.dart
index 005f97e..7567e4b 100644
--- a/pkg/analysis_server/test/services/correction/assist_test.dart
+++ b/pkg/analysis_server/test/services/correction/assist_test.dart
@@ -3513,7 +3513,17 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_CENTER, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_CENTER, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {
+ main() {
+ return /*caret*/Center(child: new Container());
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_CENTER, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
main() {
@@ -3521,6 +3531,7 @@
}
}
''');
+ }
}
test_flutterWrapCenter_OK_implicitNew() async {
@@ -3559,7 +3570,24 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_COLUMN, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_COLUMN, '''
+import 'package:flutter/widgets.dart';
+
+class FakeFlutter {
+ main() {
+ return new Container(
+ child: Column(
+ children: <Widget>[
+ new /*caret*/Text('aaa'),
+ ],
+ ),
+ );
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_COLUMN, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
@@ -3574,6 +3602,7 @@
}
}
''');
+ }
}
test_flutterWrapColumn_OK_coversWidgets() async {
@@ -3595,7 +3624,29 @@
}
''');
_setStartEndSelection();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_COLUMN, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_COLUMN, '''
+import 'package:flutter/widgets.dart';
+
+class FakeFlutter {
+ main() {
+ return new Row(children: [
+ new Text('aaa'),
+// start
+ Column(
+ children: <Widget>[
+ new Text('bbb'),
+ new Text('ccc'),
+ ],
+ ),
+// end
+ new Text('ddd'),
+ ]);
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_COLUMN, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
@@ -3615,6 +3666,7 @@
}
}
''');
+ }
}
test_flutterWrapColumn_OK_implicitNew() async {
@@ -3670,7 +3722,20 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_PADDING, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_PADDING, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {
+ main() {
+ return /*caret*/Padding(
+ padding: const EdgeInsets.all(8.0),
+ child: new Container(),
+ );
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_PADDING, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
main() {
@@ -3681,6 +3746,7 @@
}
}
''');
+ }
}
test_flutterWrapRow_OK() async {
@@ -3702,7 +3768,29 @@
}
''');
_setStartEndSelection();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_ROW, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_ROW, '''
+import 'package:flutter/widgets.dart';
+
+class FakeFlutter {
+ main() {
+ return new Column(children: [
+ new Text('aaa'),
+// start
+ Row(
+ children: <Widget>[
+ new Text('bbb'),
+ new Text('ccc'),
+ ],
+ ),
+// end
+ new Text('ddd'),
+ ]);
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_ROW, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
@@ -3722,6 +3810,7 @@
}
}
''');
+ }
}
test_flutterWrapWidget_BAD_minimal() async {
@@ -3836,7 +3925,30 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {
+ main() {
+ return new Container(
+// start
+ child: widget(
+ child: new /*caret*/DefaultTextStyle(
+ child: new Row(
+ children: <Widget>[
+ new Container(
+ ),
+ ],
+ ),
+ ),
+ ),
+// end
+ );
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
main() {
@@ -3857,6 +3969,7 @@
}
}
''');
+ }
}
test_flutterWrapWidget_OK_multiLines_eol2() async {
@@ -3881,7 +3994,30 @@
}\r
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {\r
+ main() {\r
+ return new Container(\r
+// start\r
+ child: widget(\r
+ child: new /*caret*/DefaultTextStyle(\r
+ child: new Row(\r
+ children: <Widget>[\r
+ new Container(\r
+ ),\r
+ ],\r
+ ),\r
+ ),\r
+ ),\r
+// end\r
+ );\r
+ }\r
+}\r
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {\r
main() {\r
@@ -3902,6 +4038,7 @@
}\r
}\r
''');
+ }
}
test_flutterWrapWidget_OK_singleLine1() async {
@@ -3917,7 +4054,19 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {
+ main() {
+// start
+ return /*caret*/widget(child: new Container());
+// end
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
main() {
@@ -3927,6 +4076,7 @@
}
}
''');
+ }
}
test_flutterWrapWidget_OK_singleLine2() async {
@@ -3940,7 +4090,17 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {
+ main() {
+ return widget(child: new ClipRect./*caret*/rect());
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
main() {
@@ -3948,6 +4108,7 @@
}
}
''');
+ }
}
test_flutterWrapWidget_OK_variable() async {
@@ -3962,7 +4123,18 @@
}
''');
_setCaretLocation();
- await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+ if (previewDart2) {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
+import 'package:flutter/widgets.dart';
+class FakeFlutter {
+ main() {
+ var container = new Container();
+ return /*caret*/widget(child: container);
+ }
+}
+''');
+ } else {
+ await assertHasAssist(DartAssistKind.FLUTTER_WRAP_GENERIC, '''
import 'package:flutter/widgets.dart';
class FakeFlutter {
main() {
@@ -3971,6 +4143,7 @@
}
}
''');
+ }
}
test_importAddShow_BAD_hasShow() async {
diff --git a/pkg/analysis_server/test/services/correction/fix_test.dart b/pkg/analysis_server/test/services/correction/fix_test.dart
index 334b46a..2826fd6 100644
--- a/pkg/analysis_server/test/services/correction/fix_test.dart
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart
@@ -4156,6 +4156,9 @@
}
test_invokeConstructorUsingNew() async {
+ if (previewDart2) {
+ return;
+ }
await resolveTestUnit('''
class C {
C.c();
diff --git a/pkg/analysis_server/test/src/flutter/flutter_outline_computer_test.dart b/pkg/analysis_server/test/src/flutter/flutter_outline_computer_test.dart
index 1dc9fe8..218a54b 100644
--- a/pkg/analysis_server/test/src/flutter/flutter_outline_computer_test.dart
+++ b/pkg/analysis_server/test/src/flutter/flutter_outline_computer_test.dart
@@ -8,7 +8,6 @@
import 'package:analysis_server/src/protocol_server.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
-import 'package:meta/meta.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -183,24 +182,58 @@
{
int offset = testCode.indexOf('new Column');
int length = testCode.indexOf('; // Column') - offset;
- _expect(columnOutline, offset: offset, length: length);
+ expect(columnOutline.offset, offset);
+ expect(columnOutline.length, length);
}
{
var textOutline = columnOutline.children[0];
String text = "const Text('aaa')";
int offset = testCode.indexOf(text);
- _expect(textOutline, offset: offset, length: text.length);
+ expect(textOutline.offset, offset);
+ expect(textOutline.length, text.length);
}
{
var textOutline = columnOutline.children[1];
String text = "const Text('bbb')";
int offset = testCode.indexOf(text);
- _expect(textOutline, offset: offset, length: text.length);
+ expect(textOutline.offset, offset);
+ expect(textOutline.length, text.length);
}
}
+ test_codeOffsetLength() async {
+ FlutterOutline unitOutline = await _computeOutline('''
+import 'package:flutter/widgets.dart';
+
+/// Comment
+class MyWidget extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return new Container();
+ }
+}
+''');
+ var myWidget = unitOutline.children[0];
+ expect(myWidget.offset, 40);
+ expect(myWidget.length, 137);
+ expect(myWidget.codeOffset, 52);
+ expect(myWidget.codeLength, 125);
+
+ var build = myWidget.children[0];
+ expect(build.offset, 95);
+ expect(build.length, 80);
+ expect(build.codeOffset, 107);
+ expect(build.codeLength, 68);
+
+ var container = build.children[0];
+ expect(container.offset, 155);
+ expect(container.length, 15);
+ expect(container.codeOffset, 155);
+ expect(container.codeLength, 15);
+ }
+
test_genericLabel_invocation() async {
FlutterOutline unitOutline = await _computeOutline(r'''
import 'package:flutter/widgets.dart';
@@ -492,12 +525,6 @@
return computer.compute();
}
- void _expect(FlutterOutline outline,
- {@required int offset, @required int length}) {
- expect(outline.offset, offset);
- expect(outline.length, length);
- }
-
Future<FlutterOutlineAttribute> _getAttribute(
String name, String value) async {
FlutterOutline unitOutline = await _computeOutline('''
diff --git a/pkg/analysis_server/tool/spec/generated/java/types/FlutterOutline.java b/pkg/analysis_server/tool/spec/generated/java/types/FlutterOutline.java
index 8be67a3..c3cfe10 100644
--- a/pkg/analysis_server/tool/spec/generated/java/types/FlutterOutline.java
+++ b/pkg/analysis_server/tool/spec/generated/java/types/FlutterOutline.java
@@ -53,6 +53,17 @@
private final int length;
/**
+ * The offset of the first character of the element code, which is neither documentation, nor
+ * annotation.
+ */
+ private final int codeOffset;
+
+ /**
+ * The length of the element code.
+ */
+ private final int codeLength;
+
+ /**
* The text label of the node children of the node. It is provided for any
* FlutterOutlineKind.GENERIC node, where better information is not available.
*/
@@ -120,10 +131,12 @@
/**
* Constructor for {@link FlutterOutline}.
*/
- public FlutterOutline(String kind, int offset, int length, String label, Element dartElement, List<FlutterOutlineAttribute> attributes, String className, String parentAssociationLabel, String variableName, List<FlutterOutline> children, Integer id, String renderConstructor, Integer stateOffset, Integer stateLength) {
+ public FlutterOutline(String kind, int offset, int length, int codeOffset, int codeLength, String label, Element dartElement, List<FlutterOutlineAttribute> attributes, String className, String parentAssociationLabel, String variableName, List<FlutterOutline> children, Integer id, String renderConstructor, Integer stateOffset, Integer stateLength) {
this.kind = kind;
this.offset = offset;
this.length = length;
+ this.codeOffset = codeOffset;
+ this.codeLength = codeLength;
this.label = label;
this.dartElement = dartElement;
this.attributes = attributes;
@@ -145,6 +158,8 @@
ObjectUtilities.equals(other.kind, kind) &&
other.offset == offset &&
other.length == length &&
+ other.codeOffset == codeOffset &&
+ other.codeLength == codeLength &&
ObjectUtilities.equals(other.label, label) &&
ObjectUtilities.equals(other.dartElement, dartElement) &&
ObjectUtilities.equals(other.attributes, attributes) &&
@@ -164,6 +179,8 @@
String kind = jsonObject.get("kind").getAsString();
int offset = jsonObject.get("offset").getAsInt();
int length = jsonObject.get("length").getAsInt();
+ int codeOffset = jsonObject.get("codeOffset").getAsInt();
+ int codeLength = jsonObject.get("codeLength").getAsInt();
String label = jsonObject.get("label") == null ? null : jsonObject.get("label").getAsString();
Element dartElement = jsonObject.get("dartElement") == null ? null : Element.fromJson(jsonObject.get("dartElement").getAsJsonObject());
List<FlutterOutlineAttribute> attributes = jsonObject.get("attributes") == null ? null : FlutterOutlineAttribute.fromJsonArray(jsonObject.get("attributes").getAsJsonArray());
@@ -175,7 +192,7 @@
String renderConstructor = jsonObject.get("renderConstructor") == null ? null : jsonObject.get("renderConstructor").getAsString();
Integer stateOffset = jsonObject.get("stateOffset") == null ? null : jsonObject.get("stateOffset").getAsInt();
Integer stateLength = jsonObject.get("stateLength") == null ? null : jsonObject.get("stateLength").getAsInt();
- return new FlutterOutline(kind, offset, length, label, dartElement, attributes, className, parentAssociationLabel, variableName, children, id, renderConstructor, stateOffset, stateLength);
+ return new FlutterOutline(kind, offset, length, codeOffset, codeLength, label, dartElement, attributes, className, parentAssociationLabel, variableName, children, id, renderConstructor, stateOffset, stateLength);
}
public static List<FlutterOutline> fromJsonArray(JsonArray jsonArray) {
@@ -215,6 +232,21 @@
}
/**
+ * The length of the element code.
+ */
+ public int getCodeLength() {
+ return codeLength;
+ }
+
+ /**
+ * The offset of the first character of the element code, which is neither documentation, nor
+ * annotation.
+ */
+ public int getCodeOffset() {
+ return codeOffset;
+ }
+
+ /**
* If this node is a Dart element, the description of it; omitted otherwise.
*/
public Element getDartElement() {
@@ -306,6 +338,8 @@
builder.append(kind);
builder.append(offset);
builder.append(length);
+ builder.append(codeOffset);
+ builder.append(codeLength);
builder.append(label);
builder.append(dartElement);
builder.append(attributes);
@@ -325,6 +359,8 @@
jsonObject.addProperty("kind", kind);
jsonObject.addProperty("offset", offset);
jsonObject.addProperty("length", length);
+ jsonObject.addProperty("codeOffset", codeOffset);
+ jsonObject.addProperty("codeLength", codeLength);
if (label != null) {
jsonObject.addProperty("label", label);
}
@@ -379,6 +415,10 @@
builder.append(offset + ", ");
builder.append("length=");
builder.append(length + ", ");
+ builder.append("codeOffset=");
+ builder.append(codeOffset + ", ");
+ builder.append("codeLength=");
+ builder.append(codeLength + ", ");
builder.append("label=");
builder.append(label + ", ");
builder.append("dartElement=");
diff --git a/pkg/analysis_server/tool/spec/spec_input.html b/pkg/analysis_server/tool/spec/spec_input.html
index c0877a9..a151081 100644
--- a/pkg/analysis_server/tool/spec/spec_input.html
+++ b/pkg/analysis_server/tool/spec/spec_input.html
@@ -7,7 +7,7 @@
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
- <version>1.19.0</version>
+ <version>1.20.0</version>
</h1>
<p>
This document contains a specification of the API provided by the
@@ -3097,6 +3097,19 @@
The length of the element.
</p>
</field>
+ <field name="codeOffset">
+ <ref>int</ref>
+ <p>
+ The offset of the first character of the element code, which is
+ neither documentation, nor annotation.
+ </p>
+ </field>
+ <field name="codeLength">
+ <ref>int</ref>
+ <p>
+ The length of the element code.
+ </p>
+ </field>
<field name="label" optional="true">
<ref>String</ref>
<p>
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index bda0506..2b6e7ac 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -94,7 +94,7 @@
/**
* The version of data format, should be incremented on every format change.
*/
- static const int DATA_VERSION = 51;
+ static const int DATA_VERSION = 52;
/**
* The number of exception contexts allowed to write. Once this field is
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index 94fce0c..63c6633 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -6593,6 +6593,10 @@
// Verify that all of the arguments are, or could be, constant expressions.
//
for (Expression argument in argumentList.arguments) {
+ argument = argument.unParenthesized;
+ if (argument is NamedExpression) {
+ argument = (argument as NamedExpression).expression.unParenthesized;
+ }
if (argument is InstanceCreationExpression) {
if (!argument.isConst) {
return false;
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 5bdb1b3..8592273 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -8401,7 +8401,13 @@
typeSystem.instantiateTypeFormalsToBounds(element.typeParameters);
type = element.typeAfterSubstitution(typeArguments) ?? dynamicType;
} else {
- type = typeSystem.instantiateToBounds(type);
+ DartType redirectedType =
+ _inferTypeArgumentsForRedirectedConstructor(node, type);
+ if (redirectedType != null) {
+ type = redirectedType;
+ } else {
+ type = typeSystem.instantiateToBounds(type);
+ }
}
}
typeName.staticType = type;
@@ -8510,6 +8516,34 @@
}
/**
+ * If the [node] is the type name in a redirected factory constructor,
+ * infer type arguments using the enclosing class declaration. Return `null`
+ * otherwise.
+ */
+ DartType _inferTypeArgumentsForRedirectedConstructor(
+ TypeName node, DartType type) {
+ AstNode constructorName = node.parent;
+ AstNode enclosingConstructor = constructorName?.parent;
+ TypeSystem ts = typeSystem;
+ if (constructorName is ConstructorName &&
+ enclosingConstructor is ConstructorDeclaration &&
+ enclosingConstructor.redirectedConstructor == constructorName &&
+ type is InterfaceType &&
+ ts is StrongTypeSystemImpl) {
+ ClassDeclaration enclosingClassNode = enclosingConstructor.parent;
+ ClassElement enclosingClassElement = enclosingClassNode.element;
+ if (enclosingClassElement == type.element) {
+ return type;
+ } else {
+ InterfaceType contextType = enclosingClassElement.type;
+ return ts.inferGenericFunctionOrType(
+ type, const <ParameterElement>[], const <DartType>[], contextType);
+ }
+ }
+ return null;
+ }
+
+ /**
* Checks if the given [typeName] is used as the type in an as expression.
*/
bool _isTypeNameInAsExpression(TypeName typeName) {
diff --git a/pkg/analyzer/test/generated/compile_time_error_code_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
index cd32e7e..95eb753 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code_test.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
@@ -32,10 +32,15 @@
const A();
}''');
await computeAnalysisResult(source);
- assertErrors(source, [
- CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
- StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC
- ]);
+ if (previewDart2) {
+ assertErrors(
+ source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
+ } else {
+ assertErrors(source, [
+ CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
+ StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC
+ ]);
+ }
verify([source]);
}
@@ -46,10 +51,15 @@
const A();
}''');
await computeAnalysisResult(source);
- assertErrors(source, [
- CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
- StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC
- ]);
+ if (previewDart2) {
+ assertErrors(
+ source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
+ } else {
+ assertErrors(source, [
+ CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
+ StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC
+ ]);
+ }
verify([source]);
}
@@ -61,8 +71,12 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(
+ source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]);
+ }
verify([source]);
}
@@ -74,8 +88,12 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(
+ source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]);
+ }
verify([source]);
}
@@ -84,14 +102,23 @@
class A {}
class C = A with String, num;''');
await computeAnalysisResult(source);
- assertErrors(source, [
- useCFE
- ? CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS
- : CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
- useCFE
- ? CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS
- : CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS
- ]);
+ if (previewDart2) {
+ assertErrors(source, [
+ StrongModeCode.INVALID_METHOD_OVERRIDE_FROM_MIXIN,
+ CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
+ CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS
+ ]);
+ } else if (useCFE) {
+ assertErrors(source, [
+ CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
+ CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS
+ ]);
+ } else {
+ assertErrors(source, [
+ CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
+ CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS
+ ]);
+ }
verify([source]);
}
}
@@ -1360,16 +1387,26 @@
test_constInitializedWithNonConstValue_missingConstInListLiteral() async {
Source source = addSource("const List L = [0];");
await computeAnalysisResult(source);
- assertErrors(source,
- [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
+ if ((analysisContext?.analysisOptions ?? driver.analysisOptions)
+ .previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source,
+ [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
+ }
verify([source]);
}
test_constInitializedWithNonConstValue_missingConstInMapLiteral() async {
Source source = addSource("const Map M = {'a' : 0};");
await computeAnalysisResult(source);
- assertErrors(source,
- [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
+ if ((analysisContext?.analysisOptions ?? driver.analysisOptions)
+ .previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source,
+ [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
+ }
verify([source]);
}
diff --git a/pkg/analyzer/test/generated/hint_code_test.dart b/pkg/analyzer/test/generated/hint_code_test.dart
index 69042ff..0385dba 100644
--- a/pkg/analyzer/test/generated/hint_code_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_test.dart
@@ -172,7 +172,11 @@
n(void f(int i)) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ if (previewDart2) {
+ assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ } else {
+ assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ }
verify([source]);
}
@@ -191,7 +195,44 @@
}
n(int i) {}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ if (previewDart2) {
+ assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ } else {
+ assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ }
+ verify([source]);
+ }
+
+ test_canBeNullAfterNullAware_after_cascade() async {
+ Source source = addSource(r'''
+m(x) {
+ x..a?.b.c;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
+ verify([source]);
+ }
+
+ test_canBeNullAfterNullAware_before_cascade() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a..m();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
+ verify([source]);
+ }
+
+ test_canBeNullAfterNullAware_cascade_parenthesis() async {
+ Source source = addSource(r'''
+m(x) {
+ (x?.a)..m();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
verify([source]);
}
@@ -266,39 +307,6 @@
verify([source]);
}
- test_canBeNullAfterNullAware_after_cascade() async {
- Source source = addSource(r'''
-m(x) {
- x..a?.b.c;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
- verify([source]);
- }
-
- test_canBeNullAfterNullAware_before_cascade() async {
- Source source = addSource(r'''
-m(x) {
- x?.a..m();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
- verify([source]);
- }
-
- test_canBeNullAfterNullAware_cascade_parenthesis() async {
- Source source = addSource(r'''
-m(x) {
- (x?.a)..m();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
- verify([source]);
- }
-
test_canBeNullAfterNullAware_several() async {
Source source = addSource(r'''
m(x) {
@@ -1163,7 +1171,11 @@
var v = (x / y).toInt();
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
+ }
verify([source]);
}
@@ -1429,7 +1441,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
+ } else {
+ assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ }
verify([source]);
}
@@ -1441,7 +1457,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
+ } else {
+ assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ }
verify([source]);
}
@@ -1463,7 +1483,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
+ } else {
+ assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ }
verify([source]);
}
@@ -1483,7 +1507,11 @@
int n = p1 + p2;
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
+ } else {
+ assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
+ }
verify([source]);
}
@@ -2299,26 +2327,6 @@
verify([source]);
}
- test_no_missingReturn_async_futureVoid() async {
- Source source = addSource('''
-import 'dart:async';
-Future<void> f() async {}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_no_missingReturn_async_futureOrVoid() async {
- Source source = addSource('''
-import 'dart:async';
-FutureOr<void> f(Future f) async {}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
test_missingReturn_factory() async {
Source source = addSource(r'''
class A {
@@ -2526,6 +2534,107 @@
verify([source]);
}
+ test_no_missingReturn_async_futureOrVoid() async {
+ Source source = addSource('''
+import 'dart:async';
+FutureOr<void> f(Future f) async {}
+''');
+ await computeAnalysisResult(source);
+ if (previewDart2) {
+ assertErrors(source, [HintCode.MISSING_RETURN]);
+ } else {
+ assertNoErrors(source);
+ }
+ verify([source]);
+ }
+
+ test_no_missingReturn_async_futureVoid() async {
+ Source source = addSource('''
+import 'dart:async';
+Future<void> f() async {}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_minus() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a - '';
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.NULL_AWARE_BEFORE_OPERATOR]);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_ok_assignment() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a = '';
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_ok_equal_equal() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a == '';
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_ok_is() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a is String;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_ok_is_not() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a is! String;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_ok_not_equal() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a != '';
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_nullAwareBeforeOperator_ok_question_question() async {
+ Source source = addSource(r'''
+m(x) {
+ x?.a ?? true;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
test_nullAwareInCondition_assert() async {
Source source = addSource(r'''
m(x) {
@@ -2680,83 +2789,6 @@
verify([source]);
}
- test_nullAwareBeforeOperator_minus() async {
- Source source = addSource(r'''
-m(x) {
- x?.a - '';
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.NULL_AWARE_BEFORE_OPERATOR]);
- verify([source]);
- }
-
- test_nullAwareBeforeOperator_ok_equal_equal() async {
- Source source = addSource(r'''
-m(x) {
- x?.a == '';
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_nullAwareBeforeOperator_ok_not_equal() async {
- Source source = addSource(r'''
-m(x) {
- x?.a != '';
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_nullAwareBeforeOperator_ok_question_question() async {
- Source source = addSource(r'''
-m(x) {
- x?.a ?? true;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_nullAwareBeforeOperator_ok_assignment() async {
- Source source = addSource(r'''
-m(x) {
- x?.a = '';
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_nullAwareBeforeOperator_ok_is() async {
- Source source = addSource(r'''
-m(x) {
- x?.a is String;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_nullAwareBeforeOperator_ok_is_not() async {
- Source source = addSource(r'''
-m(x) {
- x?.a is! String;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
@failingTest
test_overrideEqualsButNotHashCode() async {
Source source = addSource(r'''
@@ -3786,7 +3818,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_GETTER]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_GETTER]);
+ }
}
test_undefinedGetter_message() async {
@@ -3846,7 +3882,11 @@
a.notAMethodOnString();
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_METHOD]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_METHOD]);
+ }
}
test_undefinedMethod_assignmentExpression() async {
@@ -3860,7 +3900,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_METHOD]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_METHOD]);
+ }
}
test_undefinedOperator_binaryExpression() async {
@@ -3872,7 +3916,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ }
}
test_undefinedOperator_indexBoth() async {
@@ -3884,7 +3932,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ }
}
test_undefinedOperator_indexGetter() async {
@@ -3896,7 +3948,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ }
}
test_undefinedOperator_indexSetter() async {
@@ -3908,7 +3964,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ }
}
test_undefinedOperator_postfixExpression() async {
@@ -3920,7 +3980,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ }
}
test_undefinedOperator_prefixExpression() async {
@@ -3932,7 +3996,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
+ }
}
test_undefinedSetter() async {
@@ -3944,7 +4012,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [HintCode.UNDEFINED_SETTER]);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
+ } else {
+ assertErrors(source, [HintCode.UNDEFINED_SETTER]);
+ }
}
test_undefinedSetter_message() async {
diff --git a/pkg/analyzer/test/generated/inheritance_manager_test.dart b/pkg/analyzer/test/generated/inheritance_manager_test.dart
index 9cae945..41458da 100644
--- a/pkg/analyzer/test/generated/inheritance_manager_test.dart
+++ b/pkg/analyzer/test/generated/inheritance_manager_test.dart
@@ -11,6 +11,7 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/dart/element/element.dart';
+import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart';
@@ -55,6 +56,9 @@
*/
int _numOfMembersInObject = 0;
+ bool get previewDart2 =>
+ _definingLibrary.context.analysisOptions.previewDart2;
+
void setUp() {
_typeProvider = new TestTypeProvider();
_inheritanceManager = _createInheritanceManager();
@@ -568,8 +572,14 @@
Map<String, ExecutableElement> mapA =
_inheritanceManager.getMembersInheritedFromInterfaces(classA);
expect(mapA.length, _numOfMembersInObject + 1);
- PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(
- accessorName, false, _typeProvider.dynamicType);
+ PropertyAccessorElement syntheticAccessor;
+ if (previewDart2) {
+ syntheticAccessor = ElementFactory.getterElement(
+ accessorName, false, _typeProvider.intType);
+ } else {
+ syntheticAccessor = ElementFactory.getterElement(
+ accessorName, false, _typeProvider.dynamicType);
+ }
expect(mapA[accessorName].type, syntheticAccessor.type);
_assertNoErrors(classA);
}
@@ -603,8 +613,14 @@
Map<String, ExecutableElement> mapA =
_inheritanceManager.getMembersInheritedFromInterfaces(classA);
expect(mapA.length, _numOfMembersInObject + 1);
- MethodElement syntheticMethod = ElementFactory.methodElement(
- methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
+ MethodElement syntheticMethod;
+ if (previewDart2) {
+ syntheticMethod = ElementFactory.methodElement(
+ methodName, _typeProvider.dynamicType, [_typeProvider.numType]);
+ } else {
+ syntheticMethod = ElementFactory.methodElement(
+ methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
+ }
expect(mapA[methodName].type, syntheticMethod.type);
_assertNoErrors(classA);
}
@@ -628,9 +644,16 @@
Map<String, ExecutableElement> mapA =
_inheritanceManager.getMembersInheritedFromInterfaces(classA);
expect(mapA.length, _numOfMembersInObject + 1);
- PropertyAccessorElementImpl syntheticAccessor = ElementFactory
- .setterElement(accessorName, false, _typeProvider.dynamicType);
- syntheticAccessor.returnType = _typeProvider.dynamicType;
+ PropertyAccessorElementImpl syntheticAccessor;
+ if (previewDart2) {
+ syntheticAccessor = ElementFactory.setterElement(
+ accessorName, false, _typeProvider.numType);
+ syntheticAccessor.returnType = VoidTypeImpl.instance;
+ } else {
+ syntheticAccessor = ElementFactory.setterElement(
+ accessorName, false, _typeProvider.dynamicType);
+ syntheticAccessor.returnType = _typeProvider.dynamicType;
+ }
expect(mapA["$accessorName="].type, syntheticAccessor.type);
_assertNoErrors(classA);
}
@@ -669,8 +692,14 @@
Map<String, ExecutableElement> mapD =
_inheritanceManager.getMembersInheritedFromInterfaces(classD);
expect(mapD.length, _numOfMembersInObject + 1);
- PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(
- accessorName, false, _typeProvider.dynamicType);
+ PropertyAccessorElement syntheticAccessor;
+ if (previewDart2) {
+ syntheticAccessor =
+ ElementFactory.getterElement(accessorName, false, classC.type);
+ } else {
+ syntheticAccessor = ElementFactory.getterElement(
+ accessorName, false, _typeProvider.dynamicType);
+ }
expect(mapD[accessorName].type, syntheticAccessor.type);
_assertNoErrors(classD);
}
@@ -724,8 +753,14 @@
Map<String, ExecutableElement> mapD =
_inheritanceManager.getMembersInheritedFromInterfaces(classD);
expect(mapD.length, _numOfMembersInObject + 1);
- MethodElement syntheticMethod = ElementFactory.methodElement(
- methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
+ MethodElement syntheticMethod;
+ if (previewDart2) {
+ syntheticMethod = ElementFactory
+ .methodElement(methodName, _typeProvider.dynamicType, [classA.type]);
+ } else {
+ syntheticMethod = ElementFactory.methodElement(
+ methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
+ }
expect(mapD[methodName].type, syntheticMethod.type);
_assertNoErrors(classD);
}
@@ -764,9 +799,16 @@
Map<String, ExecutableElement> mapD =
_inheritanceManager.getMembersInheritedFromInterfaces(classD);
expect(mapD.length, _numOfMembersInObject + 1);
- PropertyAccessorElementImpl syntheticAccessor = ElementFactory
- .setterElement(accessorName, false, _typeProvider.dynamicType);
- syntheticAccessor.returnType = _typeProvider.dynamicType;
+ PropertyAccessorElementImpl syntheticAccessor;
+ if (previewDart2) {
+ syntheticAccessor =
+ ElementFactory.setterElement(accessorName, false, classA.type);
+ syntheticAccessor.returnType = VoidTypeImpl.instance;
+ } else {
+ syntheticAccessor = ElementFactory.setterElement(
+ accessorName, false, _typeProvider.dynamicType);
+ syntheticAccessor.returnType = _typeProvider.dynamicType;
+ }
expect(mapD["$accessorName="].type, syntheticAccessor.type);
_assertNoErrors(classD);
}
diff --git a/pkg/analyzer/test/generated/non_hint_code_test.dart b/pkg/analyzer/test/generated/non_hint_code_test.dart
index 089c32b..6ba10ce 100644
--- a/pkg/analyzer/test/generated/non_hint_code_test.dart
+++ b/pkg/analyzer/test/generated/non_hint_code_test.dart
@@ -622,7 +622,11 @@
int c;
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertNoErrors(source);
+ }
verify([source]);
}
@@ -642,7 +646,11 @@
int c;
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertNoErrors(source);
+ }
verify([source]);
}
@@ -831,7 +839,11 @@
}
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_undefinedMethod_assignmentExpression_inSubtype() async {
@@ -870,7 +882,11 @@
a.b();
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_undefinedMethod_unionType_all() async {
@@ -925,7 +941,11 @@
}
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_undefinedOperator_indexBoth_inSubtype() async {
@@ -940,7 +960,11 @@
}
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_undefinedOperator_indexGetter_inSubtype() async {
@@ -955,7 +979,11 @@
}
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_undefinedOperator_indexSetter_inSubtype() async {
@@ -970,7 +998,11 @@
}
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_undefinedOperator_postfixExpression() async {
@@ -1010,12 +1042,16 @@
set b(x) {}
}
f(var a) {
- if(a is A) {
+ if (a is A) {
a.b = 0;
}
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2) {
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
+ } else {
+ assertNoErrors(source);
+ }
}
test_unnecessaryCast_13855_parameter_A() async {
@@ -1067,7 +1103,11 @@
(c ? f(): new Future.value(0) as Future<int>).then((int value) {});
}''');
await computeAnalysisResult(source);
- assertNoErrors(source);
+ if (previewDart2 && enableNewAnalysisDriver) {
+ assertErrors(source, [HintCode.UNNECESSARY_CAST]);
+ } else {
+ assertNoErrors(source);
+ }
verify([source]);
}
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index d9edb36..af95154 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -1103,6 +1103,9 @@
}
test_as() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {
bool get g => true;
@@ -1129,6 +1132,9 @@
}
test_assert() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1148,6 +1154,9 @@
}
test_assignment() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v;
@@ -1164,6 +1173,9 @@
}
test_assignment_afterInitializer() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = 0;
@@ -1215,6 +1227,9 @@
}
test_assignment_throwExpression() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = 1;
@@ -1231,6 +1246,9 @@
}
test_CanvasElement_getContext() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
import 'dart:html';
main(CanvasElement canvas) {
@@ -1245,6 +1263,9 @@
}
test_forEach() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
main() {
var list = <String> [];
@@ -1269,6 +1290,9 @@
}
test_forEach_async() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
import 'dart:async';
f(Stream<String> stream) async {
@@ -1293,6 +1317,9 @@
}
test_forEach_async_inheritedStream() async {
+ if (previewDart2) {
+ return;
+ }
// From https://github.com/dart-lang/sdk/issues/24191, this ensures that
// `await for` works for types where the generic parameter doesn't
// correspond to the type of the Stream's data.
@@ -1323,6 +1350,9 @@
}
test_functionExpression_asInvocationArgument() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
class MyMap<K, V> {
forEach(f(K key, V value)) {}
@@ -1354,6 +1384,9 @@
}
test_functionExpression_asInvocationArgument_fromInferredInvocation() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
class MyMap<K, V> {
forEach(f(K key, V value)) {}
@@ -1375,6 +1408,9 @@
}
test_functionExpression_asInvocationArgument_functionExpressionInvocation() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
main() {
(f(String value)) {} ((v) {
@@ -1395,6 +1431,9 @@
}
test_functionExpression_asInvocationArgument_keepIfLessSpecific() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
class MyList {
forEach(f(Object value)) {}
@@ -1438,6 +1477,9 @@
}
test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
class MyList<E> {
forEach(f(E value)) {}
@@ -1460,6 +1502,9 @@
}
test_Future_then() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
import 'dart:async';
main(Future<int> firstFuture) {
@@ -1487,6 +1532,9 @@
}
test_initializer() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = 0;
@@ -1514,6 +1562,9 @@
}
test_initializer_dereference() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = 'String';
@@ -1645,6 +1696,9 @@
}
test_is_conditional() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1666,6 +1720,9 @@
}
test_is_if() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1724,6 +1781,9 @@
}
test_is_if_logicalAnd() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1748,6 +1808,9 @@
}
test_is_postConditional() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1767,6 +1830,9 @@
}
test_is_postIf() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1814,6 +1880,9 @@
}
test_is_while() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1837,6 +1906,9 @@
}
test_isNot_conditional() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1858,6 +1930,9 @@
}
test_isNot_if() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1882,6 +1957,9 @@
}
test_isNot_if_logicalOr() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1906,6 +1984,9 @@
}
test_isNot_postConditional() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -1925,6 +2006,9 @@
}
test_isNot_postIf() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
class A {}
A f(var p) {
@@ -2017,6 +2101,9 @@
}
test_listLiteral_same() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = [0, 1, 2];
@@ -2038,6 +2125,9 @@
}
test_mapLiteral_different() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = {'0' : 0, 1 : '1', '2' : 2};
@@ -2058,6 +2148,9 @@
}
test_mapLiteral_same() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
f() {
var v = {'a' : 0, 'b' : 1, 'c' : 2};
@@ -2078,6 +2171,9 @@
}
test_mergePropagatedTypes_afterIfThen_different() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
main() {
var v = 0;
@@ -2098,6 +2194,9 @@
}
test_mergePropagatedTypes_afterIfThen_same() async {
+ if (previewDart2) {
+ return;
+ }
var code = r'''
main() {
var v = 1;
@@ -2126,6 +2225,9 @@
}
test_mergePropagatedTypes_afterIfThenElse_same() async {
+ if (previewDart2) {
+ return;
+ }
var code = r'''
main() {
var v = 1;
@@ -2142,6 +2244,9 @@
test_mergePropagatedTypesAtJoinPoint_4() async {
// https://code.google.com/p/dart/issues/detail?id=19929
+ if (previewDart2) {
+ return;
+ }
var code = r'''
f5(x) {
var y = [];
@@ -2221,6 +2326,9 @@
}
test_objectAccessInference_enabled_for_cascades() async {
+ if (previewDart2) {
+ return;
+ }
String name = 'hashCode';
String code = '''
main() {
@@ -2273,6 +2381,9 @@
}
test_objectMethodInference_enabled_for_cascades() async {
+ if (previewDart2) {
+ return;
+ }
String name = 'toString';
String code = '''
main() {
@@ -2295,6 +2406,9 @@
// static type of [bool] for [==] comparison and the implementation
// was already consistent with the spec there. But, it's another
// [Object] method, so it's included here.
+ if (previewDart2) {
+ return;
+ }
var code = r'''
f1(x) {
var v = (x == x);
@@ -2306,6 +2420,9 @@
test_objectMethodOnDynamicExpression_hashCode() async {
// https://code.google.com/p/dart/issues/detail?id=20342
+ if (previewDart2) {
+ return;
+ }
var code = r'''
f1(x) {
var v = x.hashCode;
@@ -2317,6 +2434,9 @@
test_objectMethodOnDynamicExpression_runtimeType() async {
// https://code.google.com/p/dart/issues/detail?id=20342
+ if (previewDart2) {
+ return;
+ }
var code = r'''
f1(x) {
var v = x.runtimeType;
@@ -2328,6 +2448,9 @@
test_objectMethodOnDynamicExpression_toString() async {
// https://code.google.com/p/dart/issues/detail?id=20342
+ if (previewDart2) {
+ return;
+ }
var code = r'''
f1(x) {
var v = x.toString();
@@ -2338,6 +2461,9 @@
}
test_propagatedReturnType_localFunction() async {
+ if (previewDart2) {
+ return;
+ }
String code = r'''
main() {
f() => 42;
@@ -2349,6 +2475,9 @@
}
test_query() async {
+ if (previewDart2) {
+ return;
+ }
Source source = addSource(r'''
import 'dart:html';
diff --git a/pkg/analyzer/test/generated/resolver_test_case.dart b/pkg/analyzer/test/generated/resolver_test_case.dart
index b2690a0..4f9f022 100644
--- a/pkg/analyzer/test/generated/resolver_test_case.dart
+++ b/pkg/analyzer/test/generated/resolver_test_case.dart
@@ -341,6 +341,9 @@
AnalysisContext get analysisContext => analysisContext2;
+ AnalysisOptions get analysisOptions =>
+ analysisContext?.analysisOptions ?? driver?.analysisOptions;
+
/**
* The default [AnalysisOptions] that should be used by [reset].
*/
@@ -350,7 +353,7 @@
bool get enableNewAnalysisDriver => false;
- bool get useCFE => false;
+ bool get previewDart2 => analysisOptions.previewDart2;
/**
* Return a type provider that can be used to test the results of resolution.
@@ -376,6 +379,8 @@
*/
TypeSystem get typeSystem => analysisContext2.typeSystem;
+ bool get useCFE => false;
+
/**
* Add a source file with the given [filePath] in the root of the file system.
* The file path should be absolute. The file will have the given [contents]
@@ -440,11 +445,14 @@
* Like [assertErrors], but takes a string of source code.
*/
// TODO(rnystrom): Use this in more tests that have the same structure.
- Future<Null> assertErrorsInCode(String code, List<ErrorCode> errors) async {
+ Future<Null> assertErrorsInCode(String code, List<ErrorCode> errors,
+ {bool verify: true}) async {
Source source = addSource(code);
await computeAnalysisResult(source);
assertErrors(source, errors);
- verify([source]);
+ if (verify) {
+ this.verify([source]);
+ }
}
/**
diff --git a/pkg/analyzer/test/generated/sdk_test.dart b/pkg/analyzer/test/generated/sdk_test.dart
index 73b17f5..9a317e9 100644
--- a/pkg/analyzer/test/generated/sdk_test.dart
+++ b/pkg/analyzer/test/generated/sdk_test.dart
@@ -88,9 +88,12 @@
void test_equals_samePaths_differentOptions() {
String path = '/a/b/c';
- AnalysisOptionsImpl leftOptions = new AnalysisOptionsImpl();
- AnalysisOptionsImpl rightOptions = new AnalysisOptionsImpl();
- rightOptions.strongMode = !leftOptions.strongMode;
+ AnalysisOptionsImpl leftOptions = new AnalysisOptionsImpl()
+ ..previewDart2 = false
+ ..strongMode = false;
+ AnalysisOptionsImpl rightOptions = new AnalysisOptionsImpl()
+ ..previewDart2 = true
+ ..strongMode = true;
SdkDescription left = new SdkDescription(<String>[path], leftOptions);
SdkDescription right = new SdkDescription(<String>[path], rightOptions);
expect(left == right, isFalse);
diff --git a/pkg/analyzer/test/generated/simple_resolver_test.dart b/pkg/analyzer/test/generated/simple_resolver_test.dart
index d49c128..43a50ee 100644
--- a/pkg/analyzer/test/generated/simple_resolver_test.dart
+++ b/pkg/analyzer/test/generated/simple_resolver_test.dart
@@ -145,14 +145,18 @@
}
// get parameter
Expression rhs = assignment.rightHandSide;
- expect(rhs.staticParameterElement, isNull);
+ expect(rhs.staticParameterElement, previewDart2 ? isNotNull : isNull);
ParameterElement parameter = rhs.propagatedParameterElement;
- expect(parameter, isNotNull);
- expect(parameter.displayName, "x");
- // validate
- ClassElement classA = unit.element.types[0];
- PropertyAccessorElement setter = classA.accessors[0];
- expect(setter.parameters[0], same(parameter));
+ if (previewDart2) {
+ expect(parameter, isNull);
+ } else {
+ expect(parameter, isNotNull);
+ expect(parameter.displayName, "x");
+ // validate
+ ClassElement classA = unit.element.types[0];
+ PropertyAccessorElement setter = classA.accessors[0];
+ expect(setter.parameters[0], same(parameter));
+ }
}
test_argumentResolution_setter_propagated_propertyAccess() async {
@@ -176,14 +180,18 @@
}
// get parameter
Expression rhs = assignment.rightHandSide;
- expect(rhs.staticParameterElement, isNull);
+ expect(rhs.staticParameterElement, previewDart2 ? isNotNull : isNull);
ParameterElement parameter = rhs.propagatedParameterElement;
- expect(parameter, isNotNull);
- expect(parameter.displayName, "x");
- // validate
- ClassElement classB = unit.element.types[1];
- PropertyAccessorElement setter = classB.accessors[0];
- expect(setter.parameters[0], same(parameter));
+ if (previewDart2) {
+ expect(parameter, isNull);
+ } else {
+ expect(parameter, isNotNull);
+ expect(parameter.displayName, "x");
+ // validate
+ ClassElement classB = unit.element.types[1];
+ PropertyAccessorElement setter = classB.accessors[0];
+ expect(setter.parameters[0], same(parameter));
+ }
}
test_argumentResolution_setter_static() async {
@@ -1838,10 +1846,22 @@
found[0] = true;
// check static type
DartType staticType = node.staticType;
- expect(staticType, same(test.typeProvider.dynamicType));
+ if (test.previewDart2) {
+ expect(staticType is FunctionType, isTrue);
+ FunctionType functionType = staticType;
+ expect(
+ functionType.parameters[0].type, same(test.typeProvider.intType));
+ expect(functionType.returnType, same(test.typeProvider.stringType));
+ } else {
+ expect(staticType, same(test.typeProvider.dynamicType));
+ }
// check propagated type
FunctionType propagatedType = node.propagatedType as FunctionType;
- expect(propagatedType.returnType, test.typeProvider.stringType);
+ if (test.previewDart2) {
+ expect(propagatedType, isNull);
+ } else {
+ expect(propagatedType.returnType, test.typeProvider.stringType);
+ }
} on AnalysisException catch (e, stackTrace) {
thrownException[0] = new CaughtException(e, stackTrace);
}
diff --git a/pkg/analyzer/test/generated/static_type_analyzer_test.dart b/pkg/analyzer/test/generated/static_type_analyzer_test.dart
index a324452..0d314be 100644
--- a/pkg/analyzer/test/generated/static_type_analyzer_test.dart
+++ b/pkg/analyzer/test/generated/static_type_analyzer_test.dart
@@ -57,7 +57,7 @@
}
''';
await resolveTestUnit(code);
- expectInitializerType('foo', 'dynamic', isNull);
+ expectInitializerType('foo', previewDart2 ? 'int' : 'dynamic', isNull);
}
test_FunctionExpressionInvocation_curried() async {
@@ -117,8 +117,12 @@
}
""";
await resolveTestUnit(code);
- expectIdentifierType("p()", DynamicTypeImpl.instance,
- predicate((type) => type.displayName == '() → dynamic'));
+ if (previewDart2) {
+ expectIdentifierType("p()", '() → dynamic');
+ } else {
+ expectIdentifierType("p()", DynamicTypeImpl.instance,
+ predicate((type) => type.displayName == '() → dynamic'));
+ }
}
test_staticMethods_classTypeParameters() async {
@@ -153,7 +157,7 @@
FunctionTypeImpl type = expectFunctionType('m);', '<S>(S) → void',
elementTypeParams: '[S]',
typeFormals: '[S]',
- identifierType: '(dynamic) → void');
+ identifierType: previewDart2 ? '<S>(S) → void' : '(dynamic) → void');
typeS = type.typeFormals[0].type;
type = type.instantiate([DynamicTypeImpl.instance]);
@@ -169,7 +173,8 @@
typeParams: '[S]',
typeArgs: '[S]',
typeFormals: '[U]',
- identifierType: '(S, dynamic) → void');
+ identifierType:
+ previewDart2 ? '<U>(S, U) → void' : '(S, dynamic) → void');
type = type.instantiate([DynamicTypeImpl.instance]);
expect(type.toString(), '(S, dynamic) → void');
@@ -202,6 +207,10 @@
*/
TypeProvider _typeProvider;
+ AnalysisOptions _analysisOptions;
+
+ bool get previewDart2 => _analysisOptions.previewDart2;
+
/**
* The type system used to analyze the test cases.
*/
@@ -532,7 +541,8 @@
_propagatedVariable(_typeProvider.doubleType, 'b'));
node.propagatedElement = getMethod(_typeProvider.numType, "+");
_analyze(node);
- expect(node.propagatedType, same(_typeProvider.doubleType));
+ expect(node.propagatedType,
+ previewDart2 ? isNull : same(_typeProvider.doubleType));
_listener.assertNoErrors();
}
@@ -570,7 +580,8 @@
_propagatedVariable(_typeProvider.intType, 'b'));
node.propagatedElement = getMethod(_typeProvider.numType, "+");
_analyze(node);
- expect(node.propagatedType, same(_typeProvider.intType));
+ expect(node.propagatedType,
+ previewDart2 ? isNull : same(_typeProvider.intType));
_listener.assertNoErrors();
}
@@ -685,7 +696,17 @@
FunctionExpression node = _resolvedFunctionExpression(
AstTestFactory.formalParameterList([]), body);
DartType resultType = _analyze(node);
- _assertFunctionType(futureIntType, null, null, null, resultType);
+ if (previewDart2) {
+ _assertFunctionType(
+ _typeProvider.futureType
+ .instantiate(<DartType>[_typeProvider.dynamicType]),
+ null,
+ null,
+ null,
+ resultType);
+ } else {
+ _assertFunctionType(futureIntType, null, null, null, resultType);
+ }
_listener.assertNoErrors();
}
@@ -701,7 +722,17 @@
FunctionExpression node = _resolvedFunctionExpression(
AstTestFactory.formalParameterList([]), body);
DartType resultType = _analyze(node);
- _assertFunctionType(futureIntType, null, null, null, resultType);
+ if (previewDart2) {
+ _assertFunctionType(
+ _typeProvider.futureType
+ .instantiate(<DartType>[_typeProvider.dynamicType]),
+ null,
+ null,
+ null,
+ resultType);
+ } else {
+ _assertFunctionType(futureIntType, null, null, null, resultType);
+ }
_listener.assertNoErrors();
}
@@ -719,7 +750,17 @@
FunctionExpression node = _resolvedFunctionExpression(
AstTestFactory.formalParameterList([]), body);
DartType resultType = _analyze(node);
- _assertFunctionType(futureIntType, null, null, null, resultType);
+ if (previewDart2) {
+ _assertFunctionType(
+ _typeProvider.futureType
+ .instantiate(<DartType>[_typeProvider.dynamicType]),
+ null,
+ null,
+ null,
+ resultType);
+ } else {
+ _assertFunctionType(futureIntType, null, null, null, resultType);
+ }
_listener.assertNoErrors();
}
@@ -785,8 +826,13 @@
DartType resultType = _analyze(node);
Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
expectedNamedTypes["p"] = dynamicType;
- _assertFunctionType(
- _typeProvider.intType, null, null, expectedNamedTypes, resultType);
+ if (previewDart2) {
+ _assertFunctionType(
+ dynamicType, null, null, expectedNamedTypes, resultType);
+ } else {
+ _assertFunctionType(
+ _typeProvider.intType, null, null, expectedNamedTypes, resultType);
+ }
_listener.assertNoErrors();
}
@@ -818,8 +864,13 @@
AstTestFactory.expressionFunctionBody(_resolvedInteger(0)));
_analyze5(p);
DartType resultType = _analyze(node);
- _assertFunctionType(
- _typeProvider.intType, <DartType>[dynamicType], null, null, resultType);
+ if (previewDart2) {
+ _assertFunctionType(
+ dynamicType, <DartType>[dynamicType], null, null, resultType);
+ } else {
+ _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], null,
+ null, resultType);
+ }
_listener.assertNoErrors();
}
@@ -858,8 +909,13 @@
DartType resultType = _analyze(node);
Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
expectedNamedTypes["p2"] = dynamicType;
- _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], null,
- expectedNamedTypes, resultType);
+ if (previewDart2) {
+ _assertFunctionType(dynamicType, <DartType>[dynamicType], null,
+ expectedNamedTypes, resultType);
+ } else {
+ _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], null,
+ expectedNamedTypes, resultType);
+ }
_listener.assertNoErrors();
}
@@ -896,8 +952,13 @@
_analyze5(p1);
_analyze5(p2);
DartType resultType = _analyze(node);
- _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType],
- <DartType>[dynamicType], null, resultType);
+ if (previewDart2) {
+ _assertFunctionType(dynamicType, <DartType>[dynamicType],
+ <DartType>[dynamicType], null, resultType);
+ } else {
+ _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType],
+ <DartType>[dynamicType], null, resultType);
+ }
_listener.assertNoErrors();
}
@@ -922,7 +983,7 @@
}
void test_visitFunctionExpression_positional_expression() {
- // ([p1 = 0, p2 = 0]) -> 0
+ // ([p = 0]) -> 0
DartType dynamicType = _typeProvider.dynamicType;
FormalParameter p = AstTestFactory.positionalFormalParameter(
AstTestFactory.simpleFormalParameter3("p"), _resolvedInteger(0));
@@ -932,8 +993,13 @@
AstTestFactory.expressionFunctionBody(_resolvedInteger(0)));
_analyze5(p);
DartType resultType = _analyze(node);
- _assertFunctionType(
- _typeProvider.intType, null, <DartType>[dynamicType], null, resultType);
+ if (previewDart2) {
+ _assertFunctionType(
+ dynamicType, null, <DartType>[dynamicType], null, resultType);
+ } else {
+ _assertFunctionType(_typeProvider.intType, null, <DartType>[dynamicType],
+ null, resultType);
+ }
_listener.assertNoErrors();
}
@@ -1099,10 +1165,16 @@
// [0]
Expression node = AstTestFactory.listLiteral([_resolvedInteger(0)]);
DartType resultType = _analyze(node);
- _assertType2(
- _typeProvider.listType
- .instantiate(<DartType>[_typeProvider.dynamicType]),
- resultType);
+ if (previewDart2) {
+ _assertType2(
+ _typeProvider.listType.instantiate(<DartType>[_typeProvider.intType]),
+ resultType);
+ } else {
+ _assertType2(
+ _typeProvider.listType
+ .instantiate(<DartType>[_typeProvider.dynamicType]),
+ resultType);
+ }
_listener.assertNoErrors();
}
@@ -1148,10 +1220,17 @@
Expression node = AstTestFactory.mapLiteral2(
[AstTestFactory.mapLiteralEntry("k", _resolvedInteger(0))]);
DartType resultType = _analyze(node);
- _assertType2(
- _typeProvider.mapType.instantiate(
- <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
- resultType);
+ if (previewDart2) {
+ _assertType2(
+ _typeProvider.mapType.instantiate(
+ <DartType>[_typeProvider.dynamicType, _typeProvider.intType]),
+ resultType);
+ } else {
+ _assertType2(
+ _typeProvider.mapType.instantiate(
+ <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
+ resultType);
+ }
_listener.assertNoErrors();
}
@@ -1294,7 +1373,7 @@
PropertyAccess node =
AstTestFactory.propertyAccess2(AstTestFactory.identifier3("a"), "b");
node.propertyName.propagatedElement = getter;
- expect(_analyze2(node, false), same(boolType));
+ expect(_analyze2(node, false), previewDart2 ? isNull : same(boolType));
_listener.assertNoErrors();
}
@@ -1306,7 +1385,7 @@
PropertyAccess node =
AstTestFactory.propertyAccess2(AstTestFactory.identifier3("a"), "b");
node.propertyName.propagatedElement = setter;
- expect(_analyze2(node, false), same(boolType));
+ expect(_analyze2(node, false), previewDart2 ? isNull : same(boolType));
_listener.assertNoErrors();
}
@@ -1552,6 +1631,7 @@
context = AnalysisContextFactory.contextWithCore(
resourceProvider: resourceProvider);
}
+ _analysisOptions = context.analysisOptions;
Source source = new FileSource(resourceProvider.getFile("/lib.dart"));
CompilationUnitElementImpl definingCompilationUnit =
new CompilationUnitElementImpl("lib.dart");
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
index bff9300..ca84d57 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -742,7 +742,7 @@
void m() {
A();
}
-}''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
+}''', previewDart2 ? [] : [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
test_invocationOfNonFunction_localGenericFunction() async {
@@ -1527,10 +1527,12 @@
test_undefinedGetter_typeLiteral_conditionalAccess() async {
// When applied to a type literal, the conditional access operator '?.'
// cannot be used to access instance getters of Type.
+ // TODO(brianwilkerson) We cannot verify in previewDart2 because hashCode
+ // isn't resolved.
await assertErrorsInCode('''
class A {}
f() => A?.hashCode;
-''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
+''', [StaticTypeWarningCode.UNDEFINED_GETTER], verify: !previewDart2);
}
test_undefinedGetter_wrongNumberOfTypeArguments_tooLittle() async {
@@ -1681,13 +1683,20 @@
}
test_undefinedMethodWithConstructor() async {
- await assertErrorsInCode(r'''
+ // TODO(brianwilkerson) We cannot verify in previewDart2 because 'C' could
+ // not be resolved.
+ await assertErrorsInCode(
+ r'''
class C {
C.m();
}
f() {
C c = C.m();
-}''', [StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR]);
+}''',
+ previewDart2
+ ? []
+ : [StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR],
+ verify: !previewDart2);
}
test_undefinedOperator_indexBoth() async {
@@ -1809,13 +1818,20 @@
}
test_undefinedSuperOperator_indexSetter() async {
- await assertErrorsInUnverifiedCode(r'''
+ await assertErrorsInUnverifiedCode(
+ r'''
class A {}
class B extends A {
operator []=(index, value) {
return super[index] = 0;
}
-}''', [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
+}''',
+ previewDart2
+ ? [
+ StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
+ StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR
+ ]
+ : [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
}
test_undefinedSuperSetter() async {
diff --git a/pkg/analyzer/test/generated/static_warning_code_test.dart b/pkg/analyzer/test/generated/static_warning_code_test.dart
index 8478566..ea87317 100644
--- a/pkg/analyzer/test/generated/static_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_warning_code_test.dart
@@ -323,8 +323,10 @@
expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, error.errorCode);
String message = error.message;
expect(message.indexOf("_A") != -1, isTrue);
- expect(message.indexOf("lib1.dart") != -1, isTrue);
- expect(message.indexOf("lib2.dart") != -1, isTrue);
+ if (!previewDart2) {
+ expect(message.indexOf("lib1.dart") != -1, isTrue);
+ expect(message.indexOf("lib2.dart") != -1, isTrue);
+ }
}
test_argumentTypeNotAssignable_annotation_namedConstructor() async {
@@ -494,7 +496,11 @@
acceptFunNumOptBool(funNumBool);
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_CAST_FUNCTION]);
+ } else {
+ assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ }
verify([source]);
}
@@ -1321,8 +1327,15 @@
A(String this.x) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]);
+ if (previewDart2) {
+ assertErrors(source, [
+ StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE,
+ StrongModeCode.INVALID_PARAMETER_DECLARATION
+ ]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]);
+ }
verify([source]);
}
@@ -1513,6 +1526,487 @@
verify([source]);
}
+ test_generalizedVoid_assignmentToVoidParameterOk() async {
+ // Note: the spec may decide to disallow this, but at this point that seems
+ // highly unlikely.
+ Source source = addSource(r'''
+void main() {
+ void x;
+ f(x);
+}
+void f(void x) {}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_assignToVoid_notStrong_error() async {
+ // See StrongModeStaticTypeAnalyzer2Test.test_generalizedVoid_assignToVoidOk
+ // for testing that this does not have errors in strong mode.
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x = 42;
+}
+''');
+ await computeAnalysisResult(source);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
+ }
+ }
+
+ test_generalizedVoid_invocationOfVoidFieldError() async {
+ Source source = addSource(r'''
+class Container<T>{
+ T value;
+}
+void main(Container<void> voidContainer) {
+ voidContainer.value();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_invocationOfVoidLocalError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_invocationOfVoidResultError() async {
+ Source source = addSource(r'''
+void main() {
+ main()();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_invocationOfVoidToplevelError() async {
+ Source source = addSource(r'''
+void x;
+void main() {
+ x();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_throwVoidValueError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ throw x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfInForeachIterableError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ for (var v in x) {}
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidAsIndexAssignError() async {
+ Source source = addSource(r'''
+void main(List list) {
+ void x;
+ list[x] = null;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidAsIndexError() async {
+ Source source = addSource(r'''
+void main(List list) {
+ void x;
+ list[x];
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidAssignedToDynamicError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ dynamic z = x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidByIndexingError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x[0];
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidCallMethodError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x.toString();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidCallMethodWithNullError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x?.toString();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidCallSetterError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x.foo = null;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidCascadeError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x..toString();
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidCastsOk() async {
+ Source source = addSource(r'''
+void use(dynamic x) { }
+void main() {
+ void x;
+ use(x as int);
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidInConditionalConditionError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x ? null : null;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ @failingTest
+ test_generalizedVoid_useOfVoidInConditionalLhsError() async {
+ // TODO(mfairhurst) Enable this.
+ Source source = addSource(r'''
+void main(bool c) {
+ void x;
+ c ? x : null;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ @failingTest
+ test_generalizedVoid_useOfVoidInConditionalRhsError() async {
+ // TODO(mfairhurst) Enable this.
+ Source source = addSource(r'''
+void main(bool c) {
+ void x;
+ c ? null : x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInDoWhileConditionError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ do {} while (x);
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInExpStmtOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ @failingTest // This test may be completely invalid.
+ test_generalizedVoid_useOfVoidInForeachVariableError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ for (x in [1, 2]) {}
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInForPartsOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ for (x; false; x) {}
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidInIsTestError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x is int;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInListLiteralError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ <dynamic>[x];
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInListLiteralOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ <void>[x]; // not strong mode; we have to specify <void>.
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidInMapLiteralKeyError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ var m2 = <dynamic, int>{x : 4};
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInMapLiteralKeyOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ var m2 = <void, int>{x : 4}; // not strong mode; we have to specify <void>.
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidInMapLiteralValueError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ var m1 = <int, dynamic>{4: x};
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInMapLiteralValueOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ var m1 = <int, void>{4: x}; // not strong mode; we have to specify <void>.
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidInNullOperatorLhsError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x ?? 499;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInNullOperatorRhsOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ null ?? x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidInSpecialAssignmentError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x += 1;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInSwitchExpressionError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ switch(x) {}
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidInWhileConditionError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ while (x) {};
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidNullPropertyAccessError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x?.foo;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidPropertyAccessError() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ x.foo;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ @failingTest
+ test_generalizedVoid_useOfVoidReturnInNonVoidFunctionError() async {
+ // TODO(mfairhurst) Get this test to pass once codebase is compliant.
+ Source source = addSource(r'''
+dynamic main() {
+ void x;
+ return x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
+ }
+
+ test_generalizedVoid_useOfVoidReturnInVoidFunctionOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ return x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_generalizedVoid_useOfVoidWhenArgumentError() async {
+ Source source = addSource(r'''
+void use(dynamic x) { }
+void main() {
+ void x;
+ use(x);
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ }
+
+ test_generalizedVoid_useOfVoidWithInitializerOk() async {
+ Source source = addSource(r'''
+void main() {
+ void x;
+ void y = x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
test_importDuplicatedLibraryNamed() async {
Source source = addSource(r'''
library test;
@@ -1568,8 +2062,12 @@
String get g { return 'a'; }
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1582,10 +2080,17 @@
int f;
}''');
await computeAnalysisResult(source);
- assertErrors(source, [
- StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE,
- StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE
- ]);
+ if (previewDart2) {
+ assertErrors(source, [
+ StrongModeCode.INVALID_METHOD_OVERRIDE,
+ StrongModeCode.INVALID_METHOD_OVERRIDE
+ ]);
+ } else {
+ assertErrors(source, [
+ StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE,
+ StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE
+ ]);
+ }
verify([source]);
}
@@ -1603,8 +2108,12 @@
String get getter => null;
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1620,8 +2129,12 @@
double get g => null;
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1634,8 +2147,12 @@
m({String a}) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1648,8 +2165,12 @@
m(String a) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1662,8 +2183,12 @@
m(String a) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1679,8 +2204,15 @@
m(double d) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [
+ StrongModeCode.INVALID_METHOD_OVERRIDE,
+ StrongModeCode.INVALID_METHOD_OVERRIDE
+ ]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1697,8 +2229,12 @@
m(String n) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1715,8 +2251,12 @@
m(double d) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1729,8 +2269,12 @@
m([String a]) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source,
- [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1747,8 +2291,12 @@
m([String n]) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source,
- [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -1761,8 +2309,12 @@
String m() { return 'a'; }
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1777,8 +2329,12 @@
String m() { return 'a'; }
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1791,8 +2347,12 @@
String m() { return 'a'; }
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1805,8 +2365,12 @@
String m() { return 'a'; }
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1821,8 +2385,12 @@
String m() { return 'a'; }
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1839,8 +2407,12 @@
String m() => '';
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1853,8 +2425,12 @@
void m() {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(
+ source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
+ }
verify([source]);
}
@@ -1871,9 +2447,13 @@
}
''');
await computeAnalysisResult(source);
- assertErrors(source, [
- StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL
- ]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [
+ StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL
+ ]);
+ }
verify([source]);
}
@@ -1890,8 +2470,12 @@
}
''');
await computeAnalysisResult(source);
- assertErrors(source,
- [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
+ }
verify([source]);
}
@@ -1974,8 +2558,12 @@
m({int p : 1}) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source,
- [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
+ }
verify([source]);
}
@@ -1988,9 +2576,13 @@
m([int p = 1]) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [
- StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL
- ]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [
+ StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL
+ ]);
+ }
verify([source]);
}
@@ -2003,7 +2595,11 @@
m({a}) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]);
+ }
verify([source]);
}
@@ -2016,7 +2612,11 @@
m({a, c}) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]);
+ }
verify([source]);
}
@@ -2029,7 +2629,11 @@
m([a]) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
+ }
verify([source]);
}
@@ -2042,7 +2646,11 @@
m(a, b, [c]) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
+ }
verify([source]);
}
@@ -2055,7 +2663,11 @@
m(a, [c, d]) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
+ }
verify([source]);
}
@@ -2068,7 +2680,11 @@
m(a, b) {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_REQUIRED]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_REQUIRED]);
+ }
verify([source]);
}
@@ -2081,8 +2697,12 @@
void set s(String v) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -2099,8 +2719,16 @@
set setter14(String _) => null;
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [
+ StrongModeCode.INVALID_METHOD_OVERRIDE,
+ StrongModeCode.INVALID_METHOD_OVERRIDE,
+ StrongModeCode.INVALID_METHOD_OVERRIDE_FROM_BASE
+ ]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -2118,8 +2746,12 @@
set setter14(String _) => null;
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -2135,8 +2767,12 @@
set s(double d) {}
}''');
await computeAnalysisResult(source);
- assertErrors(
- source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
+ }
verify([source]);
}
@@ -2242,10 +2878,14 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [
- StaticWarningCode.MIXED_RETURN_TYPES,
- StaticWarningCode.MIXED_RETURN_TYPES
- ]);
+ if (previewDart2) {
+ assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
+ } else {
+ assertErrors(source, [
+ StaticWarningCode.MIXED_RETURN_TYPES,
+ StaticWarningCode.MIXED_RETURN_TYPES
+ ]);
+ }
verify([source]);
}
@@ -2467,8 +3107,12 @@
}
class E extends C implements D {}''');
await computeAnalysisResult(source);
- assertErrors(source,
- [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
+ if (previewDart2) {
+ assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE_FROM_BASE]);
+ } else {
+ assertErrors(source,
+ [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
+ }
verify([source]);
}
@@ -3025,7 +3669,11 @@
Null f() {return;}
''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
+ }
}
test_staticAccessToInstanceMember_method_invocation() async {
@@ -3369,7 +4017,11 @@
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ if (previewDart2) {
+ assertNoErrors(source);
+ } else {
+ assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
+ }
}
test_typeTestNonType() async {
@@ -3586,492 +4238,6 @@
assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
}
- test_voidReturnForGetter() async {
- Source source = addSource(r'''
-class S {
- void get value {}
-}''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_assignToVoid_notStrong_error() async {
- // See StrongModeStaticTypeAnalyzer2Test.test_generalizedVoid_assignToVoidOk
- // for testing that this does not have errors in strong mode.
- Source source = addSource(r'''
-void main() {
- void x;
- x = 42;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- }
-
- test_generalizedVoid_useOfVoidInExpStmtOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidInForPartsOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- for (x; false; x) {}
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidCastsOk() async {
- Source source = addSource(r'''
-void use(dynamic x) { }
-void main() {
- void x;
- use(x as int);
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidInIsTestError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x is int;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInConditionalConditionError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x ? null : null;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- @failingTest
- test_generalizedVoid_useOfVoidInConditionalLhsError() async {
- // TODO(mfairhurst) Enable this.
- Source source = addSource(r'''
-void main(bool c) {
- void x;
- c ? x : null;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- @failingTest
- test_generalizedVoid_useOfVoidInConditionalRhsError() async {
- // TODO(mfairhurst) Enable this.
- Source source = addSource(r'''
-void main(bool c) {
- void x;
- c ? null : x;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidWhenArgumentError() async {
- Source source = addSource(r'''
-void use(dynamic x) { }
-void main() {
- void x;
- use(x);
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidWithInitializerOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- void y = x;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidAssignedToDynamicError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- dynamic z = x;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_throwVoidValueError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- throw x;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInListLiteralOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- <void>[x]; // not strong mode; we have to specify <void>.
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidInListLiteralError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- <dynamic>[x];
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInMapLiteralValueOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- var m1 = <int, void>{4: x}; // not strong mode; we have to specify <void>.
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidInMapLiteralValueError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- var m1 = <int, dynamic>{4: x};
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInMapLiteralKeyOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- var m2 = <void, int>{x : 4}; // not strong mode; we have to specify <void>.
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidInMapLiteralKeyError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- var m2 = <dynamic, int>{x : 4};
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInNullOperatorLhsError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x ?? 499;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInNullOperatorRhsOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- null ?? x;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- @failingTest
- test_generalizedVoid_useOfVoidReturnInNonVoidFunctionError() async {
- // TODO(mfairhurst) Get this test to pass once codebase is compliant.
- Source source = addSource(r'''
-dynamic main() {
- void x;
- return x;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- }
-
- test_generalizedVoid_useOfVoidReturnInVoidFunctionOk() async {
- Source source = addSource(r'''
-void main() {
- void x;
- return x;
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_generalizedVoid_useOfVoidInWhileConditionError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- while (x) {};
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInDoWhileConditionError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- do {} while (x);
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfInForeachIterableError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- for (var v in x) {}
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- @failingTest // This test may be completely invalid.
- test_generalizedVoid_useOfVoidInForeachVariableError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- for (x in [1, 2]) {}
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInSpecialAssignmentError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x += 1;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidCallMethodError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x.toString();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidCallMethodWithNullError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x?.toString();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidCascadeError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x..toString();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_invocationOfVoidToplevelError() async {
- Source source = addSource(r'''
-void x;
-void main() {
- x();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_invocationOfVoidLocalError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_invocationOfVoidFieldError() async {
- Source source = addSource(r'''
-class Container<T>{
- T value;
-}
-void main(Container<void> voidContainer) {
- voidContainer.value();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_invocationOfVoidResultError() async {
- Source source = addSource(r'''
-void main() {
- main()();
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidByIndexingError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x[0];
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidAsIndexError() async {
- Source source = addSource(r'''
-void main(List list) {
- void x;
- list[x];
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidAsIndexAssignError() async {
- Source source = addSource(r'''
-void main(List list) {
- void x;
- list[x] = null;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidInSwitchExpressionError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- switch(x) {}
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidPropertyAccessError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x.foo;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidCallSetterError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x.foo = null;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_useOfVoidNullPropertyAccessError() async {
- Source source = addSource(r'''
-void main() {
- void x;
- x?.foo;
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
- }
-
- test_generalizedVoid_assignmentToVoidParameterOk() async {
- // Note: the spec may decide to disallow this, but at this point that seems
- // highly unlikely.
- Source source = addSource(r'''
-void main() {
- void x;
- f(x);
-}
-void f(void x) {}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
test_useOfVoidResult_assignmentExpression_function() async {
Source source = addSource(r'''
void f() {}
@@ -4100,6 +4266,19 @@
verify([source]);
}
+ test_useOfVoidResult_inForLoop_error() async {
+ Source source = addSource(r'''
+class A {
+ void m() {}
+ n() {
+ for(Object a = m();;) {}
+ }
+}''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ verify([source]);
+ }
+
test_useOfVoidResult_inForLoop_ok() async {
Source source = addSource(r'''
class A {
@@ -4113,12 +4292,12 @@
verify([source]);
}
- test_useOfVoidResult_inForLoop_error() async {
+ test_useOfVoidResult_variableDeclaration_function_error() async {
Source source = addSource(r'''
+void f() {}
class A {
- void m() {}
n() {
- for(Object a = m();;) {}
+ Object a = f();
}
}''');
await computeAnalysisResult(source);
@@ -4139,16 +4318,19 @@
verify([source]);
}
- test_useOfVoidResult_variableDeclaration_function_error() async {
+ test_useOfVoidResult_variableDeclaration_method2() async {
Source source = addSource(r'''
-void f() {}
class A {
+ void m() {}
n() {
- Object a = f();
+ Object a = m(), b = m();
}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]);
+ assertErrors(source, [
+ StaticWarningCode.USE_OF_VOID_RESULT,
+ StaticWarningCode.USE_OF_VOID_RESULT
+ ]);
verify([source]);
}
@@ -4178,19 +4360,12 @@
verify([source]);
}
- test_useOfVoidResult_variableDeclaration_method2() async {
+ test_voidReturnForGetter() async {
Source source = addSource(r'''
-class A {
- void m() {}
- n() {
- Object a = m(), b = m();
- }
+class S {
+ void get value {}
}''');
await computeAnalysisResult(source);
- assertErrors(source, [
- StaticWarningCode.USE_OF_VOID_RESULT,
- StaticWarningCode.USE_OF_VOID_RESULT
- ]);
- verify([source]);
+ assertNoErrors(source);
}
}
diff --git a/pkg/analyzer/test/generated/strong_mode_test.dart b/pkg/analyzer/test/generated/strong_mode_test.dart
index fa04b08..775f942 100644
--- a/pkg/analyzer/test/generated/strong_mode_test.dart
+++ b/pkg/analyzer/test/generated/strong_mode_test.dart
@@ -2476,6 +2476,68 @@
_isInstantiationOf(_hasElement(elementA))([_isNum, _isNum])(type);
}
+ test_redirectedConstructor_named() async {
+ Source source = addSource(r'''
+class A<T, U> implements B<T, U> {
+ A.named();
+}
+
+class B<T2, U2> {
+ factory B() = A.named;
+}
+ ''');
+ TestAnalysisResult result = await computeAnalysisResult(source);
+ assertNoErrors(source);
+
+ ClassDeclaration b = result.unit.declarations[1];
+ ConstructorDeclaration bConstructor = b.members[0];
+ ConstructorName redirected = bConstructor.redirectedConstructor;
+
+ TypeName typeName = redirected.type;
+ expect(typeName.type.toString(), 'A<T2, U2>');
+ expect(typeName.type.toString(), 'A<T2, U2>');
+
+ var constructorMember = redirected.staticElement;
+ expect(constructorMember.toString(), 'A.named() → A<T2, U2>');
+ expect(redirected.name.staticElement, constructorMember);
+ }
+
+ test_redirectedConstructor_self() async {
+ Source source = addSource(r'''
+class A<T> {
+ A();
+ factory A.redirected() = A;
+}
+ ''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ }
+
+ test_redirectedConstructor_unnamed() async {
+ Source source = addSource(r'''
+class A<T, U> implements B<T, U> {
+ A();
+}
+
+class B<T2, U2> {
+ factory B() = A;
+}
+ ''');
+ TestAnalysisResult result = await computeAnalysisResult(source);
+ assertNoErrors(source);
+
+ ClassDeclaration b = result.unit.declarations[1];
+ ConstructorDeclaration bConstructor = b.members[0];
+ ConstructorName redirected = bConstructor.redirectedConstructor;
+
+ TypeName typeName = redirected.type;
+ expect(typeName.type.toString(), 'A<T2, U2>');
+ expect(typeName.type.toString(), 'A<T2, U2>');
+
+ expect(redirected.name, isNull);
+ expect(redirected.staticElement.toString(), 'A() → A<T2, U2>');
+ }
+
test_redirectingConstructor_propagation() async {
String code = r'''
class A {
diff --git a/pkg/analyzer/test/source/error_processor_test.dart b/pkg/analyzer/test/source/error_processor_test.dart
index 37f2551..5f632f4 100644
--- a/pkg/analyzer/test/source/error_processor_test.dart
+++ b/pkg/analyzer/test/source/error_processor_test.dart
@@ -69,7 +69,8 @@
expect(getProcessor(invalid_assignment).severity, ErrorSeverity.ERROR);
expect(getProcessor(missing_return).severity, isNull);
expect(getProcessor(unused_local_variable), isNull);
- expect(getProcessor(use_of_void_result), isNull);
+ expect(getProcessor(use_of_void_result),
+ context.analysisOptions.strongMode ? isNotNull : isNull);
});
test('upgrades static type warnings to errors in strong mode', () {
diff --git a/pkg/analyzer/test/src/command_line/arguments_test.dart b/pkg/analyzer/test/src/command_line/arguments_test.dart
index 8ecdfeb..1d9afa9 100644
--- a/pkg/analyzer/test/src/command_line/arguments_test.dart
+++ b/pkg/analyzer/test/src/command_line/arguments_test.dart
@@ -78,7 +78,7 @@
expect(options.defaultPackagesDirectoryPath, isNull);
AnalysisOptionsImpl defaultOptions = options.defaultOptions;
expect(defaultOptions, isNotNull);
- expect(defaultOptions.strongMode, false);
+ expect(defaultOptions.strongMode, defaultOptions.previewDart2);
expect(defaultOptions.declarationCasts, true);
expect(defaultOptions.implicitCasts, true);
expect(defaultOptions.implicitDynamic, true);
diff --git a/pkg/analyzer/test/src/context/builder_test.dart b/pkg/analyzer/test/src/context/builder_test.dart
index b8c378a..9fb27cd 100644
--- a/pkg/analyzer/test/src/context/builder_test.dart
+++ b/pkg/analyzer/test/src/context/builder_test.dart
@@ -631,7 +631,11 @@
}
void test_findSdk_noPackageMap_html_spec() {
- DartSdk sdk = builder.findSdk(null, new AnalysisOptionsImpl());
+ DartSdk sdk = builder.findSdk(
+ null,
+ new AnalysisOptionsImpl()
+ ..previewDart2 = false
+ ..strongMode = false);
expect(sdk, isNotNull);
Source htmlSource = sdk.mapDartUri('dart:html');
expect(
diff --git a/pkg/analyzer/test/src/dart/ast/ast_test.dart b/pkg/analyzer/test/src/dart/ast/ast_test.dart
index 723f7e9..c037947 100644
--- a/pkg/analyzer/test/src/dart/ast/ast_test.dart
+++ b/pkg/analyzer/test/src/dart/ast/ast_test.dart
@@ -442,7 +442,7 @@
String testSource;
CompilationUnitImpl testUnit;
- void assertInContext(String snippet, bool isConst) {
+ void assertIsConst(String snippet, bool isConst) {
int index = testSource.indexOf(snippet);
expect(index >= 0, isTrue);
NodeLocator visitor = new NodeLocator(index);
@@ -462,6 +462,41 @@
testUnit = await resolveSource2('/test.dart', source);
}
+ void test_isConst_notInContext_constructor_const_constParam_named() async {
+ enablePreviewDart2();
+ await resolve('''
+var v = C(c: C());
+class C {
+ const C({c});
+}
+''');
+ assertIsConst("C(c", true);
+ }
+
+ void
+ test_isConst_notInContext_constructor_const_constParam_named_parens() async {
+ enablePreviewDart2();
+ await resolve('''
+var v = C(c: (C()));
+class C {
+ const C({c});
+}
+''');
+ assertIsConst("C(c", true);
+ }
+
+ void test_isConst_notInContext_constructor_const_constParam_parens() async {
+ enablePreviewDart2();
+ await resolve('''
+var v = C( (C.c()) );
+class C {
+ const C(c);
+ const C.c();
+}
+''');
+ assertIsConst("C( (", true);
+ }
+
void test_isConst_notInContext_constructor_const_generic_named() async {
enablePreviewDart2();
await resolve('''
@@ -470,7 +505,7 @@
const C.n();
}
''');
- assertInContext("C<int>.n", true);
+ assertIsConst("C<int>.n", true);
}
void
@@ -485,7 +520,7 @@
import 'c.dart' as p;
f() => <Object>[p.C<int>.n()];
''');
- assertInContext("C<int>", true);
+ assertIsConst("C<int>", true);
}
void test_isConst_notInContext_constructor_const_generic_unnamed() async {
@@ -496,7 +531,7 @@
const C();
}
''');
- assertInContext("C<int>", true);
+ assertIsConst("C<int>", true);
}
void
@@ -511,7 +546,7 @@
import 'c.dart' as p;
f() => <Object>[p.C<int>()];
''');
- assertInContext("C<int>", true);
+ assertIsConst("C<int>", true);
}
void
@@ -530,7 +565,7 @@
B();
}
''');
- assertInContext("B())", false);
+ assertIsConst("B())", false);
}
void
@@ -543,7 +578,7 @@
const C(this.f);
}
''');
- assertInContext("C(i)", false);
+ assertIsConst("C(i)", false);
}
void test_isConst_notInContext_constructor_const_nonGeneric_named() async {
@@ -554,7 +589,7 @@
const C.n();
}
''');
- assertInContext("C.n()", true);
+ assertIsConst("C.n()", true);
}
void
@@ -569,7 +604,7 @@
import 'c.dart' as p;
f() => <Object>[p.C.n()];
''');
- assertInContext("C.n()", true);
+ assertIsConst("C.n()", true);
}
void test_isConst_notInContext_constructor_const_nonGeneric_unnamed() async {
@@ -580,7 +615,7 @@
const C();
}
''');
- assertInContext("C()", true);
+ assertIsConst("C()", true);
}
void
@@ -595,7 +630,7 @@
import 'c.dart' as p;
f() => <Object>[p.C()];
''');
- assertInContext("C()", true);
+ assertIsConst("C()", true);
}
void test_isConst_notInContext_constructor_nonConst() async {
@@ -606,7 +641,7 @@
C();
}
''');
- assertInContext("C()", false);
+ assertIsConst("C()", false);
}
}
diff --git a/pkg/analyzer/test/src/dart/sdk/sdk_test.dart b/pkg/analyzer/test/src/dart/sdk/sdk_test.dart
index 49cdd97..74633e6 100644
--- a/pkg/analyzer/test/src/dart/sdk/sdk_test.dart
+++ b/pkg/analyzer/test/src/dart/sdk/sdk_test.dart
@@ -76,7 +76,11 @@
EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = false;
sdk.useSummary = true;
- expect(sdk.getLinkedBundle(), isNotNull);
+ if (sdk.analysisOptions.previewDart2) {
+ expect(sdk.getLinkedBundle(), isNull);
+ } else {
+ expect(sdk.getLinkedBundle(), isNotNull);
+ }
}
void test_getLinkedBundle_strong() {
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
index 08cd463..d6686bc 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
@@ -58,10 +58,6 @@
@override
bool get isStrongMode => true;
- @override
- AnalysisOptionsImpl createOptions() =>
- super.createOptions()..strongMode = true;
-
@failingTest // See dartbug.com/32290
test_const_constructor_inferred_args() =>
test_const_constructor_inferred_args();
@@ -239,8 +235,6 @@
abstract class _ResynthesizeAstTest extends ResynthesizeTest
with _AstResynthesizeTestMixin {
- bool get isStrongMode;
-
bool get shouldCompareLibraryElements;
@override
@@ -265,8 +259,17 @@
DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
@override
- AnalysisOptionsImpl createOptions() =>
- super.createOptions()..strongMode = isStrongMode;
+ AnalysisOptionsImpl createOptions() {
+ if (isStrongMode) {
+ return super.createOptions()
+ ..previewDart2 = true
+ ..strongMode = true;
+ } else {
+ return super.createOptions()
+ ..previewDart2 = false
+ ..strongMode = false;
+ }
+ }
test_getElement_constructor_named() async {
String text = 'class C { C.named(); }';
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index ea66e05..6dfd98c 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -71,7 +71,7 @@
bool get isSharedFrontEnd => false;
/**
- * Return `true` if resynthesizing should be done is strong mode.
+ * Return `true` if resynthesizing should be done in strong mode.
*/
bool get isStrongMode;
@@ -1183,7 +1183,7 @@
DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
/**
- * Determine the analysis options that should be used for this test.
+ * Create the analysis options that should be used for this test.
*/
AnalysisOptionsImpl createOptions() => new AnalysisOptionsImpl();
diff --git a/pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart b/pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart
index fcc0791..0774634 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart
@@ -88,10 +88,6 @@
return resynthesizer.getLibrary(testUriStr);
}
- @override
- AnalysisOptionsImpl createOptions() =>
- super.createOptions()..strongMode = true;
-
@failingTest
@FastaProblem('https://github.com/dart-lang/sdk/issues/30857')
test_class_constructor_field_formal_multiple_matching_fields() async {
@@ -205,6 +201,27 @@
await super.test_exportImport_configurations_useFirst();
}
+ @failingTest
+ @override
+ test_futureOr() async {
+ // TODO(brianwilkerson) Triage this failure.
+ fail('Inconsistent results');
+ }
+
+ @failingTest
+ @override
+ test_futureOr_const() async {
+ // TODO(brianwilkerson) Triage this failure.
+ fail('Inconsistent results');
+ }
+
+ @failingTest
+ @override
+ test_futureOr_inferred() async {
+ // TODO(brianwilkerson) Triage this failure.
+ fail('Inconsistent results');
+ }
+
test_getElement_unit() async {
String text = 'class C {}';
Source source = addLibrarySource('/test.dart', text);
diff --git a/pkg/analyzer/test/src/task/options_test.dart b/pkg/analyzer/test/src/task/options_test.dart
index bca19f8..4d5bb5e 100644
--- a/pkg/analyzer/test/src/task/options_test.dart
+++ b/pkg/analyzer/test/src/task/options_test.dart
@@ -23,8 +23,8 @@
import 'package:yaml/yaml.dart';
import '../../generated/test_support.dart';
-import '../context/abstract_context.dart';
import '../../resource_utils.dart';
+import '../context/abstract_context.dart';
main() {
defineReflectiveSuite(() {
@@ -53,6 +53,7 @@
optionsProvider.getOptionsFromString(source);
test_configure_bad_options_contents() {
+ (analysisOptions as AnalysisOptionsImpl).previewDart2 = false;
configureContext('''
analyzer:
strong-mode:true # misformatted
@@ -156,6 +157,7 @@
}
test_configure_strong_mode_bad_value() {
+ (analysisOptions as AnalysisOptionsImpl).previewDart2 = false;
configureContext('''
analyzer:
strong-mode: foo
@@ -280,36 +282,20 @@
}
}
-@reflectiveTest
-class GenerateOldOptionsErrorsTaskTest extends AbstractContextTest {
- final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
+class ErrorProcessorMatcher extends Matcher {
+ final ErrorProcessor required;
- String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
+ ErrorProcessorMatcher(this.required);
- test_does_analyze_old_options_files() {
- validate('''
-analyzer:
- strong-mode: true
- ''', [AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME]);
- }
+ @override
+ Description describe(Description desc) => desc
+ ..add("an ErrorProcessor setting ${required.code} to ${required.severity}");
- test_finds_issues_in_old_options_files() {
- validate('''
-analyzer:
- strong_mode: true
- ''', [
- AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME,
- AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES
- ]);
- }
-
- void validate(String content, List<ErrorCode> expected) {
- final Source source = newSource(optionsFilePath, content);
- var options = optionsProvider.getOptionsFromSource(source);
- final OptionsFileValidator validator = new OptionsFileValidator(source);
- var errors = validator.validate(options);
- expect(errors.map((AnalysisError e) => e.errorCode),
- unorderedEquals(expected));
+ @override
+ bool matches(dynamic o, Map<dynamic, dynamic> options) {
+ return o is ErrorProcessor &&
+ o.code.toUpperCase() == required.code.toUpperCase() &&
+ o.severity == required.severity;
}
}
@@ -491,6 +477,39 @@
}
@reflectiveTest
+class GenerateOldOptionsErrorsTaskTest extends AbstractContextTest {
+ final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
+
+ String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
+
+ test_does_analyze_old_options_files() {
+ validate('''
+analyzer:
+ strong-mode: true
+ ''', [AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME]);
+ }
+
+ test_finds_issues_in_old_options_files() {
+ validate('''
+analyzer:
+ strong_mode: true
+ ''', [
+ AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME,
+ AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES
+ ]);
+ }
+
+ void validate(String content, List<ErrorCode> expected) {
+ final Source source = newSource(optionsFilePath, content);
+ var options = optionsProvider.getOptionsFromSource(source);
+ final OptionsFileValidator validator = new OptionsFileValidator(source);
+ var errors = validator.validate(options);
+ expect(errors.map((AnalysisError e) => e.errorCode),
+ unorderedEquals(expected));
+ }
+}
+
+@reflectiveTest
class OptionsFileValidatorTest {
final OptionsFileValidator validator =
new OptionsFileValidator(new TestSource());
@@ -555,6 +574,13 @@
''', []);
}
+ test_analyzer_strong_mode_false_deprecated() {
+ validate('''
+analyzer:
+ strong-mode: false
+ ''', [AnalysisOptionsHintCode.SPEC_MODE_DEPRECATED]);
+ }
+
test_analyzer_supported_exclude() {
validate('''
analyzer:
@@ -577,13 +603,6 @@
''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]);
}
- test_analyzer_strong_mode_false_deprecated() {
- validate('''
-analyzer:
- strong-mode: false
- ''', [AnalysisOptionsHintCode.SPEC_MODE_DEPRECATED]);
- }
-
test_analyzer_unsupported_option() {
validate('''
analyzer:
@@ -697,23 +716,6 @@
}
}
-class ErrorProcessorMatcher extends Matcher {
- final ErrorProcessor required;
-
- ErrorProcessorMatcher(this.required);
-
- @override
- Description describe(Description desc) => desc
- ..add("an ErrorProcessor setting ${required.code} to ${required.severity}");
-
- @override
- bool matches(dynamic o, Map<dynamic, dynamic> options) {
- return o is ErrorProcessor &&
- o.code.toUpperCase() == required.code.toUpperCase() &&
- o.severity == required.severity;
- }
-}
-
class TestRule extends LintRule {
TestRule() : super(name: 'fantastic_test_rule');
TestRule.withName(String name) : super(name: name);
diff --git a/pkg/analyzer/test/src/task/strong_mode_test.dart b/pkg/analyzer/test/src/task/strong_mode_test.dart
index 4c964f4..6753adc 100644
--- a/pkg/analyzer/test/src/task/strong_mode_test.dart
+++ b/pkg/analyzer/test/src/task/strong_mode_test.dart
@@ -124,7 +124,11 @@
ClassElement classC = unit.getType('C');
MethodElement methodC = classC.getMethod(methodName);
ParameterElement parameterC = methodC.parameters[0];
- expect(parameterC.type.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(parameterC.type.isDynamic, isFalse);
+ } else {
+ expect(parameterC.type.isDynamic, isTrue);
+ }
_runInferrer(unit);
@@ -174,7 +178,11 @@
ClassElement classC = unit.getType('C');
MethodElement methodC = classC.getMethod(methodName);
ParameterElement parameterC = methodC.parameters[0];
- expect(parameterC.type.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(parameterC.type.isDynamic, isFalse);
+ } else {
+ expect(parameterC.type.isDynamic, isTrue);
+ }
_runInferrer(unit);
@@ -195,7 +203,11 @@
DartType typeCE = classC.typeParameters[0].type;
MethodElement methodC = classC.getMethod(methodName);
ParameterElement parameterC = methodC.parameters[0];
- expect(parameterC.type.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(parameterC.type.isDynamic, isFalse);
+ } else {
+ expect(parameterC.type.isDynamic, isTrue);
+ }
expect(methodC.type.typeArguments, [typeCE]);
_runInferrer(unit);
@@ -286,7 +298,11 @@
''');
ClassElement classC = unit.getType('C');
MethodElement methodC = classC.getMethod(methodName);
- expect(methodC.returnType.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(methodC.returnType.isDynamic, isFalse);
+ } else {
+ expect(methodC.returnType.isDynamic, isTrue);
+ }
_runInferrer(unit);
@@ -311,7 +327,11 @@
DartType expectedType = methodA.returnType;
ClassElement classC = unit.getType('C');
MethodElement methodC = classC.getMethod(methodName);
- expect(methodC.returnType.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(methodC.returnType.isDynamic, isFalse);
+ } else {
+ expect(methodC.returnType.isDynamic, isTrue);
+ }
_runInferrer(unit);
@@ -336,7 +356,11 @@
DartType expectedType = methodA.returnType;
ClassElement classC = unit.getType('C');
MethodElement methodC = classC.getMethod(methodName);
- expect(methodC.returnType.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(methodC.returnType.isDynamic, isFalse);
+ } else {
+ expect(methodC.returnType.isDynamic, isTrue);
+ }
_runInferrer(unit);
@@ -379,7 +403,11 @@
MethodElement methodA = classA.getMethod(methodName);
ClassElement classB = unit.getType('B');
MethodElement methodB = classB.getMethod(methodName);
- expect(methodB.returnType.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(methodB.returnType.isDynamic, isFalse);
+ } else {
+ expect(methodB.returnType.isDynamic, isTrue);
+ }
_runInferrer(unit);
@@ -399,7 +427,11 @@
ClassElement classB = unit.getType('B');
DartType typeBE = classB.typeParameters[0].type;
MethodElement methodB = classB.getMethod(methodName);
- expect(methodB.returnType.isDynamic, isTrue);
+ if (previewDart2) {
+ expect(methodB.returnType.isDynamic, isFalse);
+ } else {
+ expect(methodB.returnType.isDynamic, isTrue);
+ }
expect(methodB.type.typeArguments, [typeBE]);
_runInferrer(unit);
diff --git a/pkg/analyzer_cli/test/driver_test.dart b/pkg/analyzer_cli/test/driver_test.dart
index f32dee3..f638da8 100644
--- a/pkg/analyzer_cli/test/driver_test.dart
+++ b/pkg/analyzer_cli/test/driver_test.dart
@@ -854,7 +854,7 @@
test_analysisOptions_excludes() async {
await drive('data/exclude_test_project',
options: 'data/exclude_test_project/$optionsFileName');
- _expectUndefinedClassErrorsWithoutExclusions(usePreviewDart2);
+ _expectUndefinedClassErrorsWithoutExclusions();
}
test_analysisOptions_excludesRelativeToAnalysisOptions_explicit() async {
@@ -862,7 +862,7 @@
// has to then understand that.
await drive('data/exclude_test_project',
options: 'data/exclude_test_project/$optionsFileName');
- _expectUndefinedClassErrorsWithoutExclusions(usePreviewDart2);
+ _expectUndefinedClassErrorsWithoutExclusions();
}
test_analysisOptions_excludesRelativeToAnalysisOptions_inferred() async {
@@ -870,7 +870,7 @@
// analysis_options above lib. The exclude is relative to the project, not
// the analyzed path, and it has to then understand that.
await drive('data/exclude_test_project/lib', options: null);
- _expectUndefinedClassErrorsWithoutExclusions(usePreviewDart2);
+ _expectUndefinedClassErrorsWithoutExclusions();
}
test_analyzeFilesInDifferentContexts() async {
@@ -989,7 +989,8 @@
options: 'data/options_tests_project/$optionsFileName');
}
- void _expectUndefinedClassErrorsWithoutExclusions(bool isStrong) {
+ void _expectUndefinedClassErrorsWithoutExclusions() {
+ bool isStrong = usePreviewDart2 || new AnalysisOptionsImpl().previewDart2;
final String issueType = isStrong ? 'error' : 'warning';
expect(bulletToDash(outSink),
contains("$issueType - Undefined class 'IncludedUndefinedClass'"));
diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
index 1256caf..1f1320c 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
@@ -388,7 +388,19 @@
write(prefix2);
writeln('// TODO: implement $memberName');
- if (returnType.isVoid) {
+ if (isSetter) {
+ if (!isAbstract) {
+ write(prefix2);
+ selectAll(() {
+ write('super.');
+ write(memberName);
+ write(' = ');
+ write(parameters[0].name);
+ write(';');
+ });
+ writeln();
+ }
+ } else if (returnType.isVoid) {
if (!isAbstract) {
write(prefix2);
selectAll(() {
@@ -405,18 +417,6 @@
});
writeln();
}
- } else if (isSetter) {
- if (!isAbstract) {
- write(prefix2);
- selectAll(() {
- write('super.');
- write(memberName);
- write(' = ');
- write(parameters[0].name);
- write(';');
- });
- writeln();
- }
} else {
write(prefix2);
if (isAbstract) {
diff --git a/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart b/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart
index f4c063b..e7ab4ef 100644
--- a/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart
+++ b/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart
@@ -1243,7 +1243,21 @@
}
test_writeOverrideOfInheritedMember_setter_abstract() async {
- await _assertWriteOverrideOfInheritedAccessor('''
+ if (previewDart2) {
+ await _assertWriteOverrideOfInheritedAccessor('''
+abstract class A {
+ set value(int value);
+}
+class B extends A {
+}
+''', '''
+ @override
+ void set value(int value) {
+ // TODO: implement value
+ }
+''', displayText: 'value(int value) { … }', selection: null);
+ } else {
+ await _assertWriteOverrideOfInheritedAccessor('''
abstract class A {
set value(int value);
}
@@ -1255,10 +1269,28 @@
// TODO: implement value
}
''', displayText: 'value(int value) { … }', selection: null);
+ }
}
test_writeOverrideOfInheritedMember_setter_concrete() async {
- await _assertWriteOverrideOfInheritedAccessor('''
+ if (previewDart2) {
+ await _assertWriteOverrideOfInheritedAccessor('''
+class A {
+ set value(int value) {}
+}
+class B extends A {
+}
+''', '''
+ @override
+ void set value(int value) {
+ // TODO: implement value
+ super.value = value;
+ }
+''',
+ displayText: 'value(int value) { … }',
+ selection: new SourceRange(133, 20));
+ } else {
+ await _assertWriteOverrideOfInheritedAccessor('''
class A {
set value(int value) {}
}
@@ -1271,8 +1303,9 @@
super.value = value;
}
''',
- displayText: 'value(int value) { … }',
- selection: new SourceRange(128, 20));
+ displayText: 'value(int value) { … }',
+ selection: new SourceRange(128, 20));
+ }
}
test_writeParameterMatchingArgument() async {
diff --git a/pkg/analyzer_plugin/test/src/utilities/completion/optype_test.dart b/pkg/analyzer_plugin/test/src/utilities/completion/optype_test.dart
index fff6171..e48e3ea 100644
--- a/pkg/analyzer_plugin/test/src/utilities/completion/optype_test.dart
+++ b/pkg/analyzer_plugin/test/src/utilities/completion/optype_test.dart
@@ -82,7 +82,8 @@
test_Annotation() async {
// SimpleIdentifier Annotation MethodDeclaration ClassDeclaration
addTestSource('class C { @A^ }');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ArgumentList() async {
@@ -90,7 +91,11 @@
addTestSource('void main() {expect(^)}');
// If "expect()" were resolved, then either namedArgs would be true
// or returnValue and typeNames would be true.
- await assertOpType(namedArgs: true, returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2,
+ namedArgs: true,
+ returnValue: true,
+ typeNames: true);
}
test_ArgumentList_constructor_named_resolved_1_0() async {
@@ -181,19 +186,25 @@
// SimpleIdentifier NamedExpression ArgumentList MethodInvocation
// ExpressionStatement
addTestSource('void main() {expect(foo: ^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ArgumentList_prefixedIdentifier() async {
// SimpleIdentifier PrefixedIdentifier ArgumentList
addTestSource('void main() {expect(aa.^)}');
- await assertOpType(returnValue: true, typeNames: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ prefixed: true);
}
test_ArgumentList_resolved() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addTestSource('void main() {int.parse(^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ArgumentList_resolved_2_0() async {
@@ -210,7 +221,11 @@
test_AsIdentifier() async {
addTestSource('class A {var asdf; foo() {as^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_AsIdentifier2() async {
@@ -220,12 +235,14 @@
test_Assert() async {
addTestSource('main() {assert(^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AssertInitializer() async {
addTestSource('class C { C() : assert(^); }');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AssignmentExpression_name() async {
@@ -239,7 +256,8 @@
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('class A {} main() {int a; int b = ^}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AssignmentExpression_type() async {
@@ -254,7 +272,11 @@
// or (2) starting a new statement.
// Consider suggesting only types
// if only spaces separates the 1st and 2nd identifiers.
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_AssignmentExpression_type_newline() async {
@@ -268,7 +290,11 @@
// Allow non-types preceding an identifier on LHS of assignment
// if newline follows first identifier
// because user is probably starting a new statement
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_AssignmentExpression_type_partial() async {
@@ -283,7 +309,11 @@
// or (2) starting a new statement.
// Consider suggesting only types
// if only spaces separates the 1st and 2nd identifiers.
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_AssignmentExpression_type_partial_newline() async {
@@ -297,63 +327,77 @@
// Allow non-types preceding an identifier on LHS of assignment
// if newline follows first identifier
// because user is probably starting a new statement
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_AwaitExpression() async {
// SimpleIdentifier AwaitExpression ExpressionStatement
addTestSource('main() async {A a; await ^}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AwaitExpression2() async {
addTestSource('main() async {A a; await c^ await}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AwaitExpression3() async {
addTestSource('main() async {A a; await ^ await foo;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AwaitExpression4() async {
addTestSource('main() async {A a; await ^ await bar();}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AwaitExpression_assignment() async {
addTestSource('main() async {A a; int x = await ^}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AwaitExpression_assignment2() async {
addTestSource('main() async {A a; int x = await ^ await foo;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_AwaitExpression_assignment3() async {
addTestSource('main() async {A a; int x = await v^ int y = await foo;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_BinaryExpression_LHS() async {
// SimpleIdentifier BinaryExpression VariableDeclaration
// VariableDeclarationList VariableDeclarationStatement
addTestSource('main() {int a = 1, b = ^ + 2;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_BinaryExpression_RHS() async {
// SimpleIdentifier BinaryExpression VariableDeclaration
// VariableDeclarationList VariableDeclarationStatement
addTestSource('main() {int a = 1, b = 2 + ^;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_BinaryExpression_RHS2() async {
// SimpleIdentifier BinaryExpression
addTestSource('main() {if (c < ^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_Block() async {
@@ -367,7 +411,11 @@
^ var r;
}
}''');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_1a() async {
@@ -401,55 +449,91 @@
test_Block_catch_2a() async {
// '}' Block BlockFunctionBody FunctionExpression
addTestSource('main() {try {} catch () {} ^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_2b() async {
// [ExpressionStatement 'c'] Block BlockFunctionBody
addTestSource('main() {try {} catch () {} c^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_2c() async {
// [EmptyStatement] Block BlockFunctionBody FunctionExpression
addTestSource('main() {try {} catch () {} ^;}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_2d() async {
// [VariableDeclarationStatement 'Foo foo'] Block BlockFunctionBody
addTestSource('main() {try {} catch () {} ^ Foo foo;}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_3a() async {
// '}' Block BlockFunctionBody FunctionExpression
addTestSource('main() {try {} finally {} ^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_3b() async {
// [ExpressionStatement 'c'] Block BlockFunctionBody
addTestSource('main() {try {} finally {} c^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_3c() async {
// [EmptyStatement] Block BlockFunctionBody FunctionExpression
addTestSource('main() {try {} finally {} ^;}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_catch_3d() async {
// [VariableDeclarationStatement 'Foo foo'] Block BlockFunctionBody
addTestSource('main() {try {} finally {} ^ Foo foo;}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_empty() async {
// Block BlockFunctionBody MethodDeclaration ClassDeclaration
addTestSource('class A extends E implements I with M {a() {^}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_final() async {
@@ -479,18 +563,27 @@
test_Block_identifier_partial() async {
addTestSource('class X {a() {var f; {var x;} D^ var r;} void b() { }}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_keyword() async {
addTestSource('class C { static C get instance => null; } main() {C.in^}');
await assertOpType(
- prefixed: true, returnValue: true, typeNames: true, voidReturn: true);
+ constructors: previewDart2,
+ prefixed: true,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_Block_static() async {
addTestSource('class A {static foo() {^}}');
await assertOpType(
+ constructors: previewDart2,
returnValue: true,
typeNames: true,
staticMethodBody: true,
@@ -519,25 +612,41 @@
// but the user is trying to get completions for a non-cascade
main() {A a; a.^.z}''');
await assertOpType(
- returnValue: true, typeNames: true, voidReturn: true, prefixed: true);
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true,
+ prefixed: true);
}
test_CascadeExpression_selector2() async {
// SimpleIdentifier PropertyAccess CascadeExpression ExpressionStatement
addTestSource('main() {A a; a..^z}');
- await assertOpType(returnValue: true, voidReturn: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ voidReturn: true,
+ prefixed: true);
}
test_CascadeExpression_selector2_withTrailingReturn() async {
// PropertyAccess CascadeExpression ExpressionStatement Block
addTestSource('main() {A a; a..^ return}');
- await assertOpType(returnValue: true, voidReturn: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ voidReturn: true,
+ prefixed: true);
}
test_CascadeExpression_target() async {
// SimpleIdentifier CascadeExpression ExpressionStatement
addTestSource('main() {A a; a^..b}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_catch_4a1() async {
@@ -595,13 +704,21 @@
test_CatchClause_typed() async {
// Block CatchClause TryStatement
addTestSource('class A {a() {try{var x;} on E catch (e) {^}}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_CatchClause_untyped() async {
// Block CatchClause TryStatement
addTestSource('class A {a() {try{var x;} catch (e, s) {^}}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_ClassDeclaration_body() async {
@@ -637,6 +754,7 @@
// SimpleIdentifier CommentReference Comment MethodDeclaration
addTestSource('class A {/** [^] */ mth() {}');
await assertOpType(
+ constructors: previewDart2,
returnValue: true,
typeNames: true,
voidReturn: true,
@@ -646,31 +764,36 @@
test_ConditionalExpression_elseExpression() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addTestSource('class C {foo(){var f; {var x;} return a ? T1 : T^}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ConditionalExpression_elseExpression_empty() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addTestSource('class C {foo(){var f; {var x;} return a ? T1 : ^}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ConditionalExpression_partial_thenExpression() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addTestSource('class C {foo(){var f; {var x;} return a ? T^}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ConditionalExpression_partial_thenExpression_empty() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addTestSource('class C {foo(){var f; {var x;} return a ? ^}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ConditionalExpression_thenExpression() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addTestSource('class C {foo(){var f; {var x;} return a ? T^ : c}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ConstructorName() async {
@@ -719,25 +842,37 @@
test_DefaultFormalParameter_named_expression() async {
// DefaultFormalParameter FormalParameterList MethodDeclaration
addTestSource('class A {a(blat: ^) { }}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_DoStatement() async {
// SimpleIdentifier DoStatement Block
addTestSource('main() {do{} while(^x);}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
+ }
+
+ test_DoubleLiteral() async {
+ addTestSource('main() { print(1.2^); }');
+ await assertOpType();
}
test_ExpressionFunctionBody() async {
// SimpleIdentifier ExpressionFunctionBody FunctionExpression
addTestSource('m(){[1].forEach((x)=>^x);}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ExpressionStatement() async {
// ExpressionStatement Block BlockFunctionBody
addTestSource('n(){f(3);^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_ExpressionStatement_name() async {
@@ -787,25 +922,35 @@
test_ForEachStatement() async {
// SimpleIdentifier ForEachStatement Block
addTestSource('main() {for(z in ^zs) {}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ForEachStatement_body_typed() async {
// Block ForEachStatement
addTestSource('main(args) {for (int foo in bar) {^}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_ForEachStatement_body_untyped() async {
// Block ForEachStatement
addTestSource('main(args) {for (foo in bar) {^}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_ForEachStatement_iterable() async {
// SimpleIdentifier ForEachStatement Block
addTestSource('main(args) {for (int foo in ^) {}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ForEachStatement_loopVariable() async {
@@ -841,19 +986,31 @@
test_FormalParameter_partialType() async {
// FormalParameterList MethodDeclaration
addTestSource('class A {a(b.^ f) { }}');
- await assertOpType(returnValue: true, typeNames: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ prefixed: true);
}
test_FormalParameter_partialType2() async {
// FormalParameterList MethodDeclaration
addTestSource('class A {a(b.z^ f) { }}');
- await assertOpType(returnValue: true, typeNames: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ prefixed: true);
}
test_FormalParameter_partialType3() async {
// FormalParameterList MethodDeclaration
addTestSource('class A {a(b.^) { }}');
- await assertOpType(returnValue: true, typeNames: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ prefixed: true);
}
test_FormalParameterList() async {
@@ -865,7 +1022,8 @@
test_ForStatement_condition() async {
// SimpleIdentifier ForStatement
addTestSource('main() {for (int index = 0; i^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ForStatement_initializer() async {
@@ -894,13 +1052,18 @@
// SimpleIdentifier ForStatement
addTestSource('main() {for (int index = 0; index < 10; i^)}');
// TODO (danrubel) may want to exclude methods/functions with void return
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_ForStatement_updaters_prefix_expression() async {
// SimpleIdentifier PrefixExpression ForStatement
addTestSource('main() {for (int index = 0; index < 10; ++i^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_FunctionDeclaration1() async {
@@ -1073,25 +1236,35 @@
test_IfStatement() async {
// EmptyStatement IfStatement Block BlockFunctionBody
addTestSource('main(){var a; if (true) ^}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_IfStatement_condition() async {
// SimpleIdentifier IfStatement Block BlockFunctionBody
addTestSource('main(){var a; if (^)}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_IfStatement_empty() async {
// SimpleIdentifier PrefixIdentifier IfStatement
addTestSource('class A {foo() {A a; if (^) something}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_IfStatement_invocation() async {
// SimpleIdentifier PrefixIdentifier IfStatement
addTestSource('main() {var a; if (a.^) something}');
- await assertOpType(returnValue: true, typeNames: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ prefixed: true);
}
test_ImplementsClause() async {
@@ -1110,12 +1283,14 @@
test_IndexExpression() async {
addTestSource('class C {foo(){var f; {var x;} f[^]}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_IndexExpression2() async {
addTestSource('class C {foo(){var f; {var x;} f[T^]}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_InstanceCreationExpression() async {
@@ -1127,13 +1302,21 @@
test_InstanceCreationExpression_keyword() async {
// InstanceCreationExpression ExpressionStatement Block
addTestSource('class C {foo(){var f; {var x;} new^ }}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_InstanceCreationExpression_keyword2() async {
// InstanceCreationExpression ExpressionStatement Block
addTestSource('class C {foo(){var f; {var x;} new^ C();}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_InstanceCreationExpression_trailingStmt() async {
@@ -1142,42 +1325,6 @@
await assertOpType(constructors: true);
}
- test_InterpolationExpression() async {
- // SimpleIdentifier InterpolationExpression StringInterpolation
- addTestSource('main() {String name; print("hello \$^");}');
- await assertOpType(returnValue: true);
- }
-
- test_InterpolationExpression_block() async {
- // SimpleIdentifier InterpolationExpression StringInterpolation
- addTestSource('main() {String name; print("hello \${n^}");}');
- await assertOpType(returnValue: true, typeNames: true);
- }
-
- test_InterpolationExpression_prefix_selector() async {
- // SimpleIdentifier PrefixedIdentifier InterpolationExpression
- addTestSource('main() {String name; print("hello \${name.^}");}');
- await assertOpType(returnValue: true, typeNames: true, prefixed: true);
- }
-
- test_InterpolationExpression_prefix_target() async {
- // SimpleIdentifier PrefixedIdentifier InterpolationExpression
- addTestSource('main() {String name; print("hello \${nam^e.length}");}');
- await assertOpType(returnValue: true, typeNames: true);
- }
-
- test_IsExpression() async {
- // SimpleIdentifier TypeName IsExpression IfStatement
- addTestSource('main() {var x; if (x is ^) { }}');
- await assertOpType(typeNames: true);
- }
-
- test_IsExpression_target() async {
- // IfStatement Block BlockFunctionBody
- addTestSource('main(){var a; if (^ is A)}');
- await assertOpType(returnValue: true, typeNames: true);
- }
-
test_IntegerLiteral_inArgumentList() async {
addTestSource('main() { print(1^); }');
await assertOpType();
@@ -1188,9 +1335,47 @@
await assertOpType();
}
- test_DoubleLiteral() async {
- addTestSource('main() { print(1.2^); }');
- await assertOpType();
+ test_InterpolationExpression() async {
+ // SimpleIdentifier InterpolationExpression StringInterpolation
+ addTestSource('main() {String name; print("hello \$^");}');
+ await assertOpType(constructors: previewDart2, returnValue: true);
+ }
+
+ test_InterpolationExpression_block() async {
+ // SimpleIdentifier InterpolationExpression StringInterpolation
+ addTestSource('main() {String name; print("hello \${n^}");}');
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
+ }
+
+ test_InterpolationExpression_prefix_selector() async {
+ // SimpleIdentifier PrefixedIdentifier InterpolationExpression
+ addTestSource('main() {String name; print("hello \${name.^}");}');
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ prefixed: true);
+ }
+
+ test_InterpolationExpression_prefix_target() async {
+ // SimpleIdentifier PrefixedIdentifier InterpolationExpression
+ addTestSource('main() {String name; print("hello \${nam^e.length}");}');
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
+ }
+
+ test_IsExpression() async {
+ // SimpleIdentifier TypeName IsExpression IfStatement
+ addTestSource('main() {var x; if (x is ^) { }}');
+ await assertOpType(typeNames: true);
+ }
+
+ test_IsExpression_target() async {
+ // IfStatement Block BlockFunctionBody
+ addTestSource('main(){var a; if (^ is A)}');
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_IsExpression_type_partial() async {
@@ -1202,13 +1387,15 @@
test_Literal_list() async {
// ']' ListLiteral ArgumentList MethodInvocation
addTestSource('main() {var Some; print([^]);}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_Literal_list2() async {
// SimpleIdentifier ListLiteral ArgumentList MethodInvocation
addTestSource('main() {var Some; print([S^]);}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_Literal_string() async {
@@ -1220,19 +1407,22 @@
test_MapLiteralEntry() async {
// MapLiteralEntry MapLiteral VariableDeclaration
addTestSource('foo = {^');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_MapLiteralEntry1() async {
// MapLiteralEntry MapLiteral VariableDeclaration
addTestSource('foo = {T^');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_MapLiteralEntry2() async {
// SimpleIdentifier MapLiteralEntry MapLiteral VariableDeclaration
addTestSource('foo = {7:T^};');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_MethodDeclaration1() async {
@@ -1402,40 +1592,61 @@
set _s2(I x) {x.^ m(null);}
}''');
await assertOpType(
- returnValue: true, typeNames: true, voidReturn: true, prefixed: true);
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true,
+ prefixed: true);
}
test_PostfixExpression() async {
// SimpleIdentifier PostfixExpression ForStatement
addTestSource('int x = 0; main() {ax+^+;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_PrefixedIdentifier_class_const() async {
// SimpleIdentifier PrefixedIdentifier ExpressionStatement Block
addTestSource('main() {A.^}');
await assertOpType(
- returnValue: true, typeNames: true, voidReturn: true, prefixed: true);
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true,
+ prefixed: true);
}
test_PrefixedIdentifier_class_imported() async {
// SimpleIdentifier PrefixedIdentifier ExpressionStatement
addTestSource('main() {A a; a.^}');
await assertOpType(
- returnValue: true, typeNames: true, voidReturn: true, prefixed: true);
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true,
+ prefixed: true);
}
test_PrefixedIdentifier_prefix() async {
// SimpleIdentifier PrefixedIdentifier ExpressionStatement
addTestSource('class X {foo(){A^.bar}}');
- await assertOpType(typeNames: true, returnValue: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ typeNames: true,
+ returnValue: true,
+ voidReturn: true);
}
test_PropertyAccess_expression() async {
// SimpleIdentifier MethodInvocation PropertyAccess ExpressionStatement
addTestSource('class A {a() {"hello".to^String().length}}');
await assertOpType(
- returnValue: true, typeNames: true, voidReturn: true, prefixed: true);
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true,
+ prefixed: true);
}
test_PropertyAccess_noTarget() async {
@@ -1460,13 +1671,18 @@
// SimpleIdentifier PropertyAccess ExpressionStatement Block
addTestSource('class A {a() {"hello".length.^}}');
await assertOpType(
- returnValue: true, typeNames: true, voidReturn: true, prefixed: true);
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true,
+ prefixed: true);
}
test_ReturnStatement() async {
// ReturnStatement Block
addTestSource('f() { var vvv = 42; return ^ }');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_SimpleFormalParameter_closure() async {
@@ -1532,19 +1748,25 @@
test_SwitchCase_between() async {
// SwitchCase SwitchStatement Block
addTestSource('main() {switch(k) {case 1: ^ case 2: return}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_SwitchCase_expression1() async {
// SimpleIdentifier SwitchCase SwitchStatement
addTestSource('''m() {switch (x) {case ^D: return;}}''');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_SwitchCase_expression2() async {
// SimpleIdentifier SwitchCase SwitchStatement
addTestSource('''m() {switch (x) {case ^}}''');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_SwitchDefault_before() async {
@@ -1556,7 +1778,11 @@
test_SwitchDefault_between() async {
// SwitchDefault SwitchStatement Block
addTestSource('main() {switch(k) {case 1: ^ default: return;}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_SwitchStatement_body_empty() async {
@@ -1568,30 +1794,41 @@
test_SwitchStatement_body_end() async {
// Token('}') SwitchStatement Block
addTestSource('main() {switch(k) {case 1:^}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_SwitchStatement_body_end2() async {
addTestSource('main() {switch(k) {case 1:as^}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_SwitchStatement_expression1() async {
// SimpleIdentifier SwitchStatement Block
addTestSource('main() {switch(^k) {case 1:{}}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_SwitchStatement_expression2() async {
// SimpleIdentifier SwitchStatement Block
addTestSource('main() {switch(k^) {case 1:{}}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_SwitchStatement_expression_empty() async {
// SimpleIdentifier SwitchStatement Block
addTestSource('main() {switch(^) {case 1:{}}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_ThisExpression_block() async {
@@ -1601,7 +1838,12 @@
// no semicolon between completion point and next statement
set s1(I x) {} set _s2(I x) {this.^ m(null);}
}''');
- await assertOpType(returnValue: true, voidReturn: true, prefixed: true);
+ // TODO(brianwilkerson) We should not be adding constructors here.
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ voidReturn: true,
+ prefixed: true);
}
test_ThisExpression_constructor() async {
@@ -1610,7 +1852,11 @@
class A implements I {
A() {this.^}
}''');
- await assertOpType(returnValue: true, voidReturn: true, prefixed: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ voidReturn: true,
+ prefixed: true);
}
test_ThisExpression_constructor_param() async {
@@ -1652,7 +1898,8 @@
test_ThrowExpression() async {
// SimpleIdentifier ThrowExpression ExpressionStatement
addTestSource('main() {throw ^;}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_TopLevelVariableDeclaration_typed_name() async {
@@ -1734,27 +1981,34 @@
test_VariableDeclarationStatement_afterSemicolon() async {
// VariableDeclarationStatement Block BlockFunctionBody
addTestSource('class A {var a; x() {var b;^}}');
- await assertOpType(returnValue: true, typeNames: true, voidReturn: true);
+ await assertOpType(
+ constructors: previewDart2,
+ returnValue: true,
+ typeNames: true,
+ voidReturn: true);
}
test_VariableDeclarationStatement_RHS() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement
addTestSource('class C {bar(){var f; {var x;} var e = ^}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_VariableDeclarationStatement_RHS_missing_semicolon() async {
// VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement
addTestSource('class C {bar(){var f; {var x;} var e = ^ var g}}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_WhileStatement() async {
// SimpleIdentifier WhileStatement Block
addTestSource('mth() { while (b^) {} }}');
- await assertOpType(returnValue: true, typeNames: true);
+ await assertOpType(
+ constructors: previewDart2, returnValue: true, typeNames: true);
}
test_WithClause() async {
diff --git a/pkg/analyzer_plugin/test/support/abstract_context.dart b/pkg/analyzer_plugin/test/support/abstract_context.dart
index c461237..e5b4622 100644
--- a/pkg/analyzer_plugin/test/support/abstract_context.dart
+++ b/pkg/analyzer_plugin/test/support/abstract_context.dart
@@ -12,15 +12,15 @@
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/source/package_map_resolver.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/file_state.dart';
+import 'package:analyzer/src/dart/analysis/performance_logger.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/engine.dart' as engine;
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/testing/element_search.dart';
-import 'package:analyzer/src/dart/analysis/performance_logger.dart';
-import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'mock_sdk.dart';
@@ -63,6 +63,8 @@
*/
bool get enableStrongMode => false;
+ bool get previewDart2 => driver.analysisOptions.previewDart2;
+
/**
* Return the analysis session associated with the driver.
*/
diff --git a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart
index df0e08f..da77786 100644
--- a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart
+++ b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart
@@ -407,7 +407,11 @@
expect(location.startColumn, 16);
}
expect(element.parameters, isNull);
- expect(element.returnType, 'dynamic');
+ if (previewDart2) {
+ expect(element.returnType, 'int');
+ } else {
+ expect(element.returnType, 'dynamic');
+ }
expect(
element.flags, plugin.Element.FLAG_CONST | plugin.Element.FLAG_STATIC);
}
diff --git a/pkg/front_end/lib/src/fasta/parser/modifier_context.dart b/pkg/front_end/lib/src/fasta/parser/modifier_context.dart
index fd95bba..546501b 100644
--- a/pkg/front_end/lib/src/fasta/parser/modifier_context.dart
+++ b/pkg/front_end/lib/src/fasta/parser/modifier_context.dart
@@ -278,11 +278,9 @@
}
/// Parse modifiers for variable declarations.
- Token parseVariableDeclarationModifiers(
- Token token, TypeContinuation typeContinuation,
+ Token parseVariableDeclarationModifiers(Token token,
{Token varFinalOrConst}) {
- token = parseModifiers(token, typeContinuation,
- varFinalOrConst: varFinalOrConst);
+ token = parseModifiers(token, null, varFinalOrConst: varFinalOrConst);
reportExtraneousModifier(abstractToken);
reportExtraneousModifier(covariantToken);
diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart
index 5203691..0778f66 100644
--- a/pkg/front_end/lib/src/fasta/parser/parser.dart
+++ b/pkg/front_end/lib/src/fasta/parser/parser.dart
@@ -5525,15 +5525,12 @@
next = token.next;
}
- TypeContinuation typeContinuation;
Token varFinalOrConst;
if (isModifier(next)) {
if (optional('var', next)) {
- typeContinuation = TypeContinuation.OptionalAfterVar;
varFinalOrConst = token = token.next;
next = token.next;
} else if (optional('final', next) || optional('const', next)) {
- typeContinuation = TypeContinuation.Optional;
varFinalOrConst = token = token.next;
next = token.next;
}
@@ -5542,13 +5539,11 @@
// Recovery
ModifierRecoveryContext2 modifierContext =
new ModifierRecoveryContext2(this);
- token = modifierContext.parseVariableDeclarationModifiers(
- token, typeContinuation,
+ token = modifierContext.parseVariableDeclarationModifiers(token,
varFinalOrConst: varFinalOrConst);
next = token.next;
varFinalOrConst = modifierContext.varFinalOrConst;
- typeContinuation = modifierContext.typeContinuation;
modifierContext = null;
}
}
@@ -5602,15 +5597,12 @@
token = parseMetadataStar(token);
Token next = token.next;
- TypeContinuation typeContinuation;
Token varFinalOrConst;
if (isModifier(next)) {
if (optional('var', next)) {
- typeContinuation = TypeContinuation.OptionalAfterVar;
varFinalOrConst = token = token.next;
next = token.next;
} else if (optional('final', next) || optional('const', next)) {
- typeContinuation = TypeContinuation.Optional;
varFinalOrConst = token = token.next;
next = token.next;
}
@@ -5619,12 +5611,10 @@
// Recovery
ModifierRecoveryContext2 modifierContext =
new ModifierRecoveryContext2(this);
- token = modifierContext.parseVariableDeclarationModifiers(
- token, typeContinuation,
+ token = modifierContext.parseVariableDeclarationModifiers(token,
varFinalOrConst: varFinalOrConst);
varFinalOrConst = modifierContext.varFinalOrConst;
- typeContinuation = modifierContext.typeContinuation;
modifierContext = null;
}
}
diff --git a/tools/VERSION b/tools/VERSION
index 986a52a..08a79fe 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 0
PATCH 0
-PRERELEASE 38
+PRERELEASE 39
PRERELEASE_PATCH 0
diff --git a/tools/bots/test_matrix.json b/tools/bots/test_matrix.json
index 14c06a3..21094fc 100644
--- a/tools/bots/test_matrix.json
+++ b/tools/bots/test_matrix.json
@@ -249,16 +249,6 @@
]
},
{
- "name": "vm tests",
- "arguments": [
- "--compiler=dartkp",
- "--runtime=dart_precompiled",
- "--use-blobs"
- ],
- "fileset": "vm-kernel",
- "shards": 10
- },
- {
"name": "strong vm tests",
"arguments": [
"--compiler=dartkp",
@@ -288,13 +278,6 @@
]
},
{
- "name": "vm tests",
- "arguments": [
- "--compiler=dartkp","--runtime=dart_precompiled"],
- "fileset": "vm-kernel",
- "shards": 10
- },
- {
"name": "strong vm tests",
"arguments": [
"--compiler=dartkp",
@@ -323,16 +306,6 @@
]
},
{
- "name": "vm tests",
- "arguments": [
- "--compiler=dartkp",
- "--runtime=dart_precompiled",
- "--vm-options=--no-enable-malloc-hooks"
- ],
- "fileset": "vm-kernel",
- "shards": 10
- },
- {
"name": "strong vm tests",
"arguments": [
"--compiler=dartkp",
@@ -403,12 +376,6 @@
"arguments": ["runtime_kernel"]
},
{
- "name": "vm tests",
- "arguments": ["--compiler=dartk"],
- "fileset": "vm-kernel",
- "shards": 10
- },
- {
"name": "strong vm tests",
"arguments": ["--compiler=dartk", "--strong"],
"fileset": "vm-kernel",
@@ -675,16 +642,6 @@
]
},
{
- "name": "vm tests",
- "arguments": [
- "--builder-tag=optimization_counter_threshold",
- "--compiler=dartk",
- "--vm-options=--optimization-counter-threshold=5"
- ],
- "fileset": "vm-kernel",
- "shards": 10
- },
- {
"name": "strong vm tests",
"arguments": [
"--builder-tag=optimization_counter_threshold",
diff --git a/tools/infra/config/cq.cfg b/tools/infra/config/cq.cfg
index f68e8ca..74ce8ab 100644
--- a/tools/infra/config/cq.cfg
+++ b/tools/infra/config/cq.cfg
@@ -31,6 +31,7 @@
builders { name: "ddc-linux-release-chrome-try"}
builders { name: "vm-linux-product-x64-try"}
builders { name: "dart-sdk-windows-try"}
+ builders { name: "vm-kernel-legacy-linux-release-x64-try"}
builders { name: "vm-kernel-mac-release-x64-try"}
builders { name: "benchmark-linux-try"}
builders { name: "front-end-linux-release-x64-try"}