Version 2.10.0-13.0.dev
Merge commit 'aba88b6ed42b963a2a74fed935da8b317051d898' into 'dev'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c3e87cc..e0b4d8d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -151,10 +151,10 @@
### Pub
* `pub run` and `pub global run` accepts a `--enable-experiment` flag enabling
experiments in the Dart VM (and language).
+* `pub run` and `pub global run` accepts a `--(no-)-sound-null-safety flag, that
+ is passed to the VM.
* Warn when publishing the first null-safe version of a package.
* `pub outdated`:
- * Introduce `--mode=null-safety` flag that will report which of your
- dependencies you can upgrade to fully support null safety.
* If the current version of a dependency is a prerelease
version, use prereleases for latest if there is no newer stable.
* Don't require a `pubspec.lock` file. When the lockfile is missing, the
@@ -172,6 +172,7 @@
* Fix git folder names in cache, allowing for ssh-style git
dependencies.
* Fix: Avoid precompilation of dependencies of global packages.
+* Fix: avoid multiple recompilation of binaries in global packages.
## 2.8.4 - 2020-06-04
diff --git a/DEPS b/DEPS
index 4268f99..0a1e7ec 100644
--- a/DEPS
+++ b/DEPS
@@ -128,7 +128,7 @@
"ply_rev": "604b32590ffad5cbb82e4afef1d305512d06ae93",
"pool_rev": "eedbd5fde84f9a1a8da643b475305a81841da599",
"protobuf_rev": "3746c8fd3f2b0147623a8e3db89c3ff4330de760",
- "pub_rev": "04b054b62cc437cf23451785fdc50e49cd9de139",
+ "pub_rev": "0d185a398a1684c15ea16a0facc17f5d170e5d51",
"pub_semver_tag": "v1.4.4",
"quiver-dart_tag": "246e754fe45cecb6aa5f3f13b4ed61037ff0d784",
"resource_rev": "f8e37558a1c4f54550aa463b88a6a831e3e33cd6",
@@ -483,16 +483,6 @@
"dep_type": "cipd",
},
- Var("dart_root") + "/pkg/analysis_server/language_model": {
- "packages": [
- {
- "package": "dart/language_model",
- "version": "lIRt14qoA1Cocb8j3yw_Fx5cfYou2ddam6ArBm4AI6QC",
- }
- ],
- "dep_type": "cipd",
- },
-
Var("dart_root") + "/buildtools": {
"packages": [
{
diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
index c0b1a66..059880a 100644
--- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
@@ -8,6 +8,7 @@
import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
import 'package:analysis_server/src/services/correction/change_workspace.dart';
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
+import 'package:analysis_server/src/services/correction/dart/add_await.dart';
import 'package:analysis_server/src/services/correction/dart/add_override.dart';
import 'package:analysis_server/src/services/correction/dart/convert_add_all_to_spread.dart';
import 'package:analysis_server/src/services/correction/dart/convert_conditional_expression_to_if_element.dart';
@@ -88,6 +89,7 @@
LintNames.prefer_spread_collections: ConvertAddAllToSpread.newInstance,
LintNames.slash_for_doc_comments: ConvertDocumentationIntoLine.newInstance,
LintNames.type_init_formals: RemoveTypeAnnotation.newInstance,
+ LintNames.unawaited_futures: AddAwait.newInstance,
LintNames.unnecessary_const: RemoveUnnecessaryConst.newInstance,
LintNames.unnecessary_lambdas: ReplaceWithTearOff.newInstance,
LintNames.unnecessary_new: RemoveUnnecessaryNew.newInstance,
diff --git a/pkg/analysis_server/lib/src/services/correction/organize_imports.dart b/pkg/analysis_server/lib/src/services/correction/organize_imports.dart
index 6b0184e..ae1b4c6 100644
--- a/pkg/analysis_server/lib/src/services/correction/organize_imports.dart
+++ b/pkg/analysis_server/lib/src/services/correction/organize_imports.dart
@@ -64,6 +64,34 @@
var priority = getDirectivePriority(directive);
if (priority != null) {
var offset = directive.offset;
+ if (directive.beginToken.precedingComments != null) {
+ var firstComment = directive.beginToken.precedingComments;
+ var comment = firstComment;
+ // Don't connect comments that have a blank line between them
+ while (comment.next != null) {
+ var currentLine = lineInfo.getLocation(comment.offset).lineNumber;
+ var nextLine =
+ lineInfo.getLocation(comment.next.offset).lineNumber;
+ if (nextLine - currentLine > 1) {
+ firstComment = comment.next;
+ }
+
+ comment = comment.next;
+ }
+ // Check if the comment is the first comment in the document
+ if (firstComment != unit.beginToken.precedingComments) {
+ var previousLine = lineInfo
+ .getLocation(directive.beginToken.previous.end)
+ .lineNumber;
+
+ // Check if the comment is after the last token of the previous line
+ // Only connect, if it's not on the same line as the last token of the previous line
+ if (lineInfo.getLocation(firstComment.offset).lineNumber !=
+ previousLine) {
+ offset = firstComment.offset;
+ }
+ }
+ }
var end = directive.end;
var line = lineInfo.getLocation(end).lineNumber;
diff --git a/pkg/analysis_server/test/services/completion/dart/completion_ranking_test.dart b/pkg/analysis_server/test/services/completion/dart/completion_ranking_test.dart
index e1aa937..841ad47 100644
--- a/pkg/analysis_server/test/services/completion/dart/completion_ranking_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/completion_ranking_test.dart
@@ -21,7 +21,7 @@
tokenize('if (list == null) { return; } for (final i = 0; i < list.');
final response = await ranking.makePredictRequest(tokens);
expect(response['data']['length'], greaterThan(0.9));
- });
+ }, skip: 'https://github.com/dart-lang/sdk/issues/42988');
}
final directory = path.join(File.fromUri(Platform.script).parent.path, '..',
diff --git a/pkg/analysis_server/test/services/completion/dart/language_model_test.dart b/pkg/analysis_server/test/services/completion/dart/language_model_test.dart
index d98d3a3..7a2434e 100644
--- a/pkg/analysis_server/test/services/completion/dart/language_model_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/language_model_test.dart
@@ -15,60 +15,62 @@
return;
}
- LanguageModel model;
+ group('LanguageModel', () {
+ LanguageModel model;
- setUp(() {
- model = LanguageModel.load(directory);
- });
+ setUp(() {
+ model = LanguageModel.load(directory);
+ });
- tearDown(() {
- model.close();
- });
+ tearDown(() {
+ model.close();
+ });
- test('calculates lookback', () {
- expect(model.lookback, expectedLookback);
- });
+ test('calculates lookback', () {
+ expect(model.lookback, expectedLookback);
+ });
- test('predict with defaults', () {
- final tokens =
- tokenize('if (list == null) { return; } for (final i = 0; i < list.');
- final suggestions = model.predict(tokens);
- expect(suggestions.first, 'length');
- });
+ test('predict with defaults', () {
+ final tokens =
+ tokenize('if (list == null) { return; } for (final i = 0; i < list.');
+ final suggestions = model.predict(tokens);
+ expect(suggestions.first, 'length');
+ });
- test('predict with confidence scores', () {
- final tokens =
- tokenize('if (list == null) { return; } for (final i = 0; i < list.');
- final suggestions = model.predictWithScores(tokens);
- final best = suggestions.entries.first;
- expect(best.key, 'length');
- expect(best.value, greaterThan(0.9));
- });
+ test('predict with confidence scores', () {
+ final tokens =
+ tokenize('if (list == null) { return; } for (final i = 0; i < list.');
+ final suggestions = model.predictWithScores(tokens);
+ final best = suggestions.entries.first;
+ expect(best.key, 'length');
+ expect(best.value, greaterThan(0.9));
+ });
- test('predict when no previous tokens', () {
- final tokens = <String>[];
- final suggestions = model.predict(tokens);
- expect(suggestions.first, isNotEmpty);
- });
+ test('predict when no previous tokens', () {
+ final tokens = <String>[];
+ final suggestions = model.predict(tokens);
+ expect(suggestions.first, isNotEmpty);
+ });
- test('load fail', () {
- try {
- LanguageModel.load('doesnotexist');
- fail('Failure to load language model should throw an exception');
- } catch (e) {
- expect(
- e.toString(), equals('Invalid argument(s): Unable to create model.'));
- }
- });
+ test('load fail', () {
+ try {
+ LanguageModel.load('doesnotexist');
+ fail('Failure to load language model should throw an exception');
+ } catch (e) {
+ expect(e.toString(),
+ equals('Invalid argument(s): Unable to create model.'));
+ }
+ });
- test('isNumber', () {
- expect(model.isNumber('0xCAb005E'), true);
- expect(model.isNumber('foo'), false);
- expect(model.isNumber('3.1415'), true);
- expect(model.isNumber('1337'), true);
- expect(model.isNumber('"four score and seven years ago"'), false);
- expect(model.isNumber('0.0'), true);
- });
+ test('isNumber', () {
+ expect(model.isNumber('0xCAb005E'), true);
+ expect(model.isNumber('foo'), false);
+ expect(model.isNumber('3.1415'), true);
+ expect(model.isNumber('1337'), true);
+ expect(model.isNumber('"four score and seven years ago"'), false);
+ expect(model.isNumber('0.0'), true);
+ });
+ }, skip: 'https://github.com/dart-lang/sdk/issues/42988');
}
const expectedLookback = 100;
diff --git a/pkg/analysis_server/test/services/correction/organize_directives_test.dart b/pkg/analysis_server/test/services/correction/organize_directives_test.dart
index 2cfde40..77ab9c2 100644
--- a/pkg/analysis_server/test/services/correction/organize_directives_test.dart
+++ b/pkg/analysis_server/test/services/correction/organize_directives_test.dart
@@ -290,6 +290,53 @@
''');
}
+ Future<void>
+ test_sort_imports_dontConnectFirstCommentsWithBlankLinesBetween() async {
+ await _computeUnitAndErrors(r'''
+// Copyright...
+
+// Some comment related to the line below
+import 'package:b/a.dart';
+import 'package:a/b.dart';''');
+ _assertOrganize(r'''
+// Copyright...
+
+import 'package:a/b.dart';
+// Some comment related to the line below
+import 'package:b/a.dart';''');
+ }
+
+ Future<void> test_sort_imports_keepFirstCommentUntouched() async {
+ await _computeUnitAndErrors(r'''
+// Copyright
+// Copyright2
+// Copyright3
+import 'package:b/a.dart';
+import 'package:a/b.dart';''');
+
+ _assertOrganize(r'''
+// Copyright
+// Copyright2
+// Copyright3
+import 'package:a/b.dart';
+import 'package:b/a.dart';''');
+ }
+
+ Future<void> test_sort_imports_keepSubsequentComments() async {
+ await _computeUnitAndErrors(r'''
+/// Copyright...
+library lib;
+
+import 'package:b/a.dart'; // We are keeping this because ...
+import 'package:a/b.dart';''');
+ _assertOrganize(r'''
+/// Copyright...
+library lib;
+
+import 'package:a/b.dart';
+import 'package:b/a.dart'; // We are keeping this because ...''');
+ }
+
Future<void> test_sort_imports_packageAndPath() async {
await _computeUnitAndErrors(r'''
library lib;
@@ -314,6 +361,36 @@
''');
}
+ Future<void> test_sort_imports_with_library_keepPrecedingComments() async {
+ await _computeUnitAndErrors(r'''
+/// Copyright...
+library lib;
+
+// Test comment
+
+// We are keeping this because ... l1
+// We are keeping this because ... l2
+// We are keeping this because ... l3
+import 'package:b/a.dart';
+// Comment for a
+
+import 'package:a/b.dart';''');
+
+ _assertOrganize(r'''
+/// Copyright...
+library lib;
+
+// Test comment
+
+// Comment for a
+
+import 'package:a/b.dart';
+// We are keeping this because ... l1
+// We are keeping this because ... l2
+// We are keeping this because ... l3
+import 'package:b/a.dart';''');
+ }
+
void _assertOrganize(String expectedCode, {bool removeUnused = false}) {
var organizer = ImportOrganizer(testCode, testUnit, testErrors,
removeUnused: removeUnused);
diff --git a/pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart b/pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart
new file mode 100644
index 0000000..5ee8044
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/bulk/add_await_test.dart
@@ -0,0 +1,41 @@
+// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analysis_server/src/services/linter/lint_names.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import 'bulk_fix_processor.dart';
+
+void main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(AddAwaitTest);
+ });
+}
+
+@reflectiveTest
+class AddAwaitTest extends BulkFixProcessorTest {
+ @override
+ String get lintCode => LintNames.unawaited_futures;
+
+ Future<void> test_singleFile() async {
+ await resolveTestUnit('''
+Future doSomething() => new Future.value('');
+Future doSomethingElse() => new Future.value('');
+
+void main() async {
+ doSomething();
+ doSomethingElse();
+}
+''');
+ await assertHasFix('''
+Future doSomething() => new Future.value('');
+Future doSomethingElse() => new Future.value('');
+
+void main() async {
+ await doSomething();
+ await doSomethingElse();
+}
+''');
+ }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart
index 8267b5d..456f64d 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart
@@ -4,6 +4,7 @@
import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'add_await_test.dart' as add_await;
import 'add_override_test.dart' as add_override;
import 'convert_documentation_into_line_test.dart'
as convert_documentation_into_line;
@@ -41,6 +42,7 @@
void main() {
defineReflectiveSuite(() {
+ add_await.main();
add_override.main();
convert_documentation_into_line.main();
convert_to_contains.main();
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index ac374e1..cf378e9 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -8,9 +8,6 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/listener.dart';
-import 'package:analyzer/src/dart/ast/ast.dart'
- show PrefixedIdentifierImpl, SimpleIdentifierImpl;
-import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
import 'package:analyzer/src/dart/element/type.dart';
@@ -22,7 +19,6 @@
import 'package:analyzer/src/dart/resolver/scope.dart';
import 'package:analyzer/src/dart/resolver/type_property_resolver.dart';
import 'package:analyzer/src/error/codes.dart';
-import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/migratable_ast_info_provider.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/super_context.dart';
@@ -190,49 +186,48 @@
}
} else if (identifier is PrefixedIdentifier) {
SimpleIdentifier prefix = identifier.prefix;
+ Element prefixElement = _resolveSimpleIdentifier(prefix);
+ prefix.staticElement = prefixElement;
+
SimpleIdentifier name = identifier.identifier;
- Element element = _resolveSimpleIdentifier(prefix);
- if (element == null) {
+
+ if (prefixElement == null) {
// resolver.reportError(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, prefix, prefix.getName());
- } else {
- prefix.staticElement = element;
- if (element is PrefixElement) {
- // TODO(brianwilkerson) Report this error?
- element = _resolver.nameScope.lookupIdentifier(identifier);
- name.staticElement = element;
- return;
- }
- LibraryElement library = element.library;
- if (library == null) {
- // TODO(brianwilkerson) We need to understand how the library could
- // ever be null.
- AnalysisEngine.instance.instrumentationService
- .logError("Found element with null library: ${element.name}");
- } else if (library != _definingLibrary) {
+ return;
+ }
+
+ if (prefixElement is PrefixElement) {
+ var prefixScope = prefixElement.scope;
+ var lookupResult = prefixScope.lookup2(name.name);
+ var element = lookupResult.getter ?? lookupResult.setter;
+ element = _resolver.toLegacyElement(element);
+ name.staticElement = element;
+ return;
+ }
+
+ LibraryElement library = prefixElement.library;
+ if (library != _definingLibrary) {
+ // TODO(brianwilkerson) Report this error.
+ }
+
+ if (node.newKeyword == null) {
+ if (prefixElement is ClassElement) {
+ name.staticElement = prefixElement.getMethod(name.name) ??
+ prefixElement.getGetter(name.name) ??
+ prefixElement.getSetter(name.name) ??
+ prefixElement.getNamedConstructor(name.name);
+ } else {
// TODO(brianwilkerson) Report this error.
}
- if (node.newKeyword == null) {
- if (element is ClassElement) {
- name.staticElement = element.getMethod(name.name) ??
- element.getGetter(name.name) ??
- element.getSetter(name.name) ??
- element.getNamedConstructor(name.name);
- } else {
- // TODO(brianwilkerson) Report this error.
- }
+ } else if (prefixElement is ClassElement) {
+ var constructor = prefixElement.getNamedConstructor(name.name);
+ if (constructor == null) {
+ // TODO(brianwilkerson) Report this error.
} else {
- if (element is ClassElement) {
- ConstructorElement constructor =
- element.getNamedConstructor(name.name);
- if (constructor == null) {
- // TODO(brianwilkerson) Report this error.
- } else {
- name.staticElement = constructor;
- }
- } else {
- // TODO(brianwilkerson) Report this error.
- }
+ name.staticElement = constructor;
}
+ } else {
+ // TODO(brianwilkerson) Report this error.
}
}
}
@@ -500,13 +495,10 @@
//
Element prefixElement = prefix.staticElement;
if (prefixElement is PrefixElement) {
- Element element = _resolver.nameScope.lookupIdentifier(node);
+ var lookupResult = prefixElement.scope.lookup2(identifier.name);
+ var element = lookupResult.getter;
if (element == null && identifier.inSetterContext()) {
- Identifier setterName = PrefixedIdentifierImpl.temp(
- node.prefix,
- SimpleIdentifierImpl(StringToken(TokenType.STRING,
- "${node.identifier.name}=", node.identifier.offset - 1)));
- element = _resolver.nameScope.lookupIdentifier(setterName);
+ element = lookupResult.setter;
}
element = _resolver.toLegacyElement(element);
if (element == null && _resolver.nameScope.shouldIgnoreUndefined(node)) {
diff --git a/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart b/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart
index 2dc2b41..b64b7ee 100644
--- a/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart
+++ b/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart
@@ -31,6 +31,7 @@
class AnalysisOptionsFileConfig {
final List<String> experiments;
final bool implicitCasts;
+ final bool implicitDynamic;
final List<String> lints;
final bool strictInference;
final bool strictRawTypes;
@@ -38,6 +39,7 @@
AnalysisOptionsFileConfig({
this.experiments,
this.implicitCasts,
+ this.implicitDynamic,
this.lints,
this.strictInference,
this.strictRawTypes,
@@ -47,9 +49,10 @@
var buffer = StringBuffer();
if (experiments != null ||
+ implicitCasts != null ||
+ implicitDynamic != null ||
strictRawTypes != null ||
- strictInference != null ||
- implicitCasts != null) {
+ strictInference != null) {
buffer.writeln('analyzer:');
if (experiments != null) {
@@ -67,9 +70,14 @@
buffer.writeln(' strict-inference: $strictInference');
}
- if (implicitCasts != null) {
+ if (implicitCasts != null || implicitDynamic != null) {
buffer.writeln(' strong-mode:');
- buffer.writeln(' implicit-casts: $implicitCasts');
+ if (implicitCasts != null) {
+ buffer.writeln(' implicit-casts: $implicitCasts');
+ }
+ if (implicitDynamic != null) {
+ buffer.writeln(' implicit-dynamic: $implicitDynamic');
+ }
}
}
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index fe99a26..81b6014 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -2,10 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'package:analyzer/src/test_utilities/package_mixin.dart';
+import 'package:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import 'strong_test_helper.dart';
+import '../../../generated/test_support.dart';
+import '../../dart/resolution/context_collection_resolution.dart';
void main() {
defineReflectiveSuite(() {
@@ -14,9 +15,9 @@
}
@reflectiveTest
-class CheckerTest extends AbstractStrongTest with PackageMixin {
+class CheckerTest extends PubPackageResolutionTest {
test_awaitForInCastsStreamElementToVariable() async {
- await checkFile('''
+ await assertErrorsInCode('''
import 'dart:async';
abstract class MyStream<T> extends Stream<T> {
@@ -25,7 +26,7 @@
main() async {
// Don't choke if sequence is not stream.
- await for (var i in /*error:FOR_IN_OF_INVALID_TYPE*/1234) {}
+ await for (var i in 1234) {}
// Dynamic cast.
await for (String s in new MyStream<dynamic>()) {}
@@ -39,11 +40,18 @@
// Downcast.
await for (int i in new MyStream<num>()) {}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 181, 1),
+ error(CompileTimeErrorCode.FOR_IN_OF_INVALID_TYPE, 186, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 235, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 309, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 373, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 438, 1),
+ ]);
}
test_awaitForInCastsSupertypeSequenceToStream() async {
- await checkFile('''
+ await assertErrorsInCode('''
main() async {
dynamic d;
await for (var i in d) {}
@@ -51,11 +59,14 @@
Object o;
await for (var i in o) {}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 45, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 86, 1),
+ ]);
}
test_binaryAndIndexOperators() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {
A operator *(B b) => null;
A operator /(B b) => null;
@@ -87,9 +98,9 @@
a = a ~/ b;
a = a % b;
a = a + b;
- a = a + /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a;
+ a = a + a;
a = a - b;
- b = /*error:INVALID_ASSIGNMENT*/b - b;
+ b = b - b;
a = a << b;
a = a >> b;
a = a & b;
@@ -101,35 +112,43 @@
int y = 42;
x = x + x;
x = x + c;
- x = x + /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y;
+ x = x + y;
bool p = true;
p = p && p;
p = p && c;
p = (c) && p;
p = (c) && c;
- p = /*error:NON_BOOL_OPERAND*/y && p;
+ p = y && p;
p = c == y;
a = a[b];
a = a[c];
c = (c[b]);
- a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y];
+ a[y];
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 574, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 596, 5),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 758, 1),
+ error(CompileTimeErrorCode.NON_BOOL_OPERAND, 845, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 910, 1),
+ ]);
}
test_callMethodOnFunctions() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
void f(int x) => print(x);
main() {
- f.call(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi');
+ f.call('hi');
}
- ''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 45, 4),
+ ]);
}
test_castsInConditions() async {
- await checkFile('''
+ await assertErrorsInCode('''
main() {
bool b = true;
num x = b ? 1 : 2.3;
@@ -137,16 +156,20 @@
String z = !b ? "hello" : null;
z = b ? null : "hello";
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 32, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 55, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 81, 1),
+ ]);
}
test_castsInConstantContexts() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {
static const num n = 3.0;
// The severe error is from constant evaluation where we know the
// concrete type.
- static const int i = /*error:VARIABLE_TYPE_MISMATCH*/n;
+ static const int i = n;
final int fi;
const A(num a) : this.fi = a;
}
@@ -154,95 +177,112 @@
const B(Object a) : super(a);
}
void foo(Object o) {
- var a = const A(/*error:CONST_WITH_NON_CONSTANT_ARGUMENT*/o);
+ var a = const A(o);
}
-''');
+''', [
+ error(CompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, 149, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 283, 1),
+ error(CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT, 295, 1),
+ ]);
}
test_classOverrideOfGrandInterface_interfaceOfAbstractSuperclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
abstract class Base implements I1 {}
class T1 extends Base {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 119, 1),
+ ]);
}
test_classOverrideOfGrandInterface_interfaceOfConcreteSuperclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
-class /*error:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER*/Base
- implements I1 {}
+class Base implements I1 {}
class T1 extends Base {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 62,
+ 4),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 111, 1),
+ ]);
}
test_classOverrideOfGrandInterface_interfaceOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
abstract class I2 implements I1 {}
class T1 implements I2 {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 118, 1),
+ ]);
}
test_classOverrideOfGrandInterface_mixinOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class M1 {
- m(A a);
+ m(A a);
}
abstract class I2 extends Object with M1 {}
class T1 implements I2 {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 127, 1),
+ ]);
}
test_classOverrideOfGrandInterface_superclassOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
abstract class I2 extends I1 {}
class T1 implements I2 {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 115, 1),
+ ]);
}
test_compoundAssignment_returnsDynamic() async {
- await checkFile(r'''
+ await assertNoErrorsInCode(r'''
class Foo {
operator +(other) => null;
}
@@ -252,11 +292,11 @@
foo = foo + 1;
foo += 1;
}
- ''');
+''');
}
test_compoundAssignments() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {
A operator *(B b) => null;
A operator /(B b) => null;
@@ -289,7 +329,7 @@
test() {
int x = 0;
x += 5;
- x += /*error:INVALID_ASSIGNMENT*/3.14;
+ x += 3.14;
double y = 0.0;
y += 5;
@@ -319,9 +359,9 @@
a ~/= b;
a %= b;
a += b;
- a += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a;
+ a += a;
a -= b;
- b -= /*error:INVALID_ASSIGNMENT*/b;
+ b -= b;
a <<= b;
a >>= b;
a &= b;
@@ -336,18 +376,25 @@
var d = new D();
a[b] += d;
a[c] += d;
- a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d;
+ a[z] += d;
a[b] += c;
- a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z;
+ a[b] += z;
c[b] += d;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 613, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 927, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 947, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1045, 3),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1110, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1142, 1),
+ ]);
}
- @failingTest // See dartbug.com/33440
+ @FailingTest(issue: 'dartbug.com/33440')
test_constantGenericTypeArg_explicit() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26141
- await checkFile('''
+ await assertNoErrorsInCode('''
abstract class Equality<R> {}
abstract class EqualityBase<R> implements Equality<R> {
final C<R> c = const C<R>();
@@ -368,12 +415,12 @@
main() {
const SetEquality<String>();
}
- ''');
+''');
}
test_constantGenericTypeArg_infer() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26141
- await checkFile('''
+ await assertErrorsInCode('''
abstract class Equality<Q> {}
abstract class EqualityBase<R> implements Equality<R> {
final C<R> c = const C();
@@ -394,21 +441,23 @@
main() {
const SetEquality<String>();
}
- ''');
+''', []);
}
test_constructorInvalid() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26695
- await checkFile('''
+ await assertErrorsInCode('''
class A {
- B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {}
+ B({this.test: 1.0 }) {}
final double test = 0.0;
}
-''');
+''', [
+ error(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 15, 9),
+ ]);
}
test_constructors() async {
- await checkFile('''
+ await assertErrorsInCode('''
const num z = 25;
Object obj = "world";
@@ -416,37 +465,48 @@
int x;
String y;
- A(this.x) : this.y = /*error:FIELD_INITIALIZER_NOT_ASSIGNABLE*/42;
+ A(this.x) : this.y = 42;
A.c1(p): this.x = z, this.y = p;
A.c2(this.x, this.y);
- A.c3(/*error:FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE*/num this.x, String this.y);
+ A.c3(num this.x, String this.y);
}
class B extends A {
- B() : super(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
+ B() : super("hello");
- B.c2(int x, String y) : super.c2(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/x);
+ B.c2(int x, String y) : super.c2(y, x);
B.c3(num x, Object y) : super.c3(x, y);
}
void main() {
- A a = new A.c2(z, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z);
- var b = new B.c2(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello", obj);
+ A a = new A.c2(z, z);
+ var b = new B.c2("hello", obj);
}
-''');
+''', [
+ error(CompileTimeErrorCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, 96, 2),
+ error(CompileTimeErrorCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, 169,
+ 10),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 234, 7),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 280, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 283, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 352, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 368, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 379, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 392, 7),
+ ]);
}
test_conversionAndDynamicInvoke() async {
- addFile('''
+ newFile('$testPackageLibPath/helper.dart', content: r'''
dynamic toString = (int x) => x + 42;
dynamic hashCode = "hello";
-''', name: '/helper.dart');
- await checkFile('''
+''');
+
+ await assertErrorsInCode('''
import 'helper.dart' as helper;
class A {
@@ -485,7 +545,7 @@
f1("hello");
dynamic f2 = foo;
(f2("hello"));
- DynFun f3 = /*error:INVALID_CAST_FUNCTION*/foo;
+ DynFun f3 = foo;
(f3("hello"));
(f3(42));
StrFun f4 = foo;
@@ -518,11 +578,15 @@
baz().toString();
baz().hashCode;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 503, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 760, 15),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1039, 8),
+ ]);
}
test_covariantOverride() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
class C {
num f(num x) => x;
}
@@ -538,23 +602,28 @@
class G extends E implements D {}
class D_error extends C {
- int /*error:INVALID_OVERRIDE*/f(int x) => x;
+ int f(int x) => x;
}
class E_error extends D {
- int /*error:INVALID_OVERRIDE*/f(covariant double x) => 0;
+ int f(covariant double x) => 0;
}
class F_error extends E {
- int /*error:INVALID_OVERRIDE*/f(covariant double x) => 0;
+ int f(covariant double x) => 0;
}
class G_error extends E implements D {
- int /*error:INVALID_OVERRIDE*/f(covariant double x) => 0;
+ int f(covariant double x) => 0;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 252, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 301, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 363, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 438, 1),
+ ]);
}
@failingTest
test_covariantOverride_fields() async {
- await checkFile(r'''
+ await assertNoErrorsInCode(r'''
class A {
get foo => '';
set foo(_) {}
@@ -572,11 +641,11 @@
class E extends D {
num foo;
}
- ''');
+''');
}
test_covariantOverride_leastUpperBound() async {
- await checkFile(r'''
+ await assertNoErrorsInCode(r'''
abstract class Top {}
abstract class Left implements Top {}
abstract class Right implements Top {}
@@ -595,11 +664,11 @@
// LUB(Left, Right) == Top, so this is an implicit cast from Top to Bottom.
void m(covariant Bottom x);
}
- ''');
+''');
}
test_covariantOverride_markerIsInherited() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
class C {
num f(covariant num x) => x;
}
@@ -615,22 +684,27 @@
class G extends E implements D {}
class D_error extends C {
- int /*error:INVALID_OVERRIDE*/f(String x) => 0;
+ int f(String x) => 0;
}
class E_error extends D {
- int /*error:INVALID_OVERRIDE*/f(double x) => 0;
+ int f(double x) => 0;
}
class F_error extends E {
- int /*error:INVALID_OVERRIDE*/f(double x) => 0;
+ int f(double x) => 0;
}
class G_error extends E implements D {
- int /*error:INVALID_OVERRIDE*/f(double x) => 0;
+ int f(double x) => 0;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 242, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 294, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 346, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 411, 1),
+ ]);
}
test_dynamicInvocation() {
- return checkFile(r'''
+ return assertErrorsInCode(r'''
typedef dynamic A(dynamic x);
class B {
int call(int x) => x;
@@ -642,29 +716,29 @@
int x;
bool y;
x = f(3);
- x = /*error:INVALID_ASSIGNMENT*/f.col(true);
- y = /*error:INVALID_ASSIGNMENT*/f(3);
+ x = f.col(true);
+ y = f(3);
y = f.col(true);
- f(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/true);
- f.col(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
+ f(true);
+ f.col(3);
}
{
Function f = new B();
int x;
bool y;
x = f(3);
- x = f./*error:UNDEFINED_METHOD*/col(true);
+ x = f.col(true);
y = f(3);
- y = f./*error:UNDEFINED_METHOD*/col(true);
+ y = f.col(true);
f(true);
// Through type propagation, we know f is actually a B, hence the
// hint.
- f./*error:UNDEFINED_METHOD*/col(3);
+ f.col(3);
}
{
- A f = /*error:INVALID_ASSIGNMENT*/new B();
+ A f = new B();
B b = new B();
- f = /* error:INVALID_ASSIGNMENT*/b;
+ f = b;
int x;
bool y;
x = f(3);
@@ -677,19 +751,40 @@
g.col(true);
g.foo(true);
g.x;
- A f = /* error:INVALID_ASSIGNMENT*/new B();
+ A f = new B();
B b = new B();
- f = /*error:INVALID_ASSIGNMENT*/b;
- f./*error:UNDEFINED_METHOD*/col(true);
- f./*error:UNDEFINED_METHOD*/foo(true);
- f./*error:UNDEFINED_GETTER*/x;
+ f = b;
+ f.col(true);
+ f.foo(true);
+ f.x;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 136, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 148, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 173, 11),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 194, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 227, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 244, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 290, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 302, 1),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 329, 3),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 364, 3),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 477, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 503, 7),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 539, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 550, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 562, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 710, 7),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 746, 1),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 755, 3),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 772, 3),
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 789, 1),
+ ]);
}
test_factoryConstructorDowncast() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
class Animal {
Animal();
factory Animal.cat() => new Cat();
@@ -699,12 +794,15 @@
void main() {
Cat c = new Animal.cat();
- c = /*error:INVALID_CAST_NEW_EXPR*/new Animal();
-}''');
+ c = new Animal();
+}''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 116, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_NEW_EXPR, 144, 12),
+ ]);
}
test_fieldFieldOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends B {}
@@ -717,23 +815,30 @@
}
class Child extends Base {
- A /*error:INVALID_OVERRIDE*/f1; // invalid for getter
- C /*error:INVALID_OVERRIDE*/f2; // invalid for setter
+ A f1; // invalid for getter
+ C f2; // invalid for setter
var f3;
- dynamic /*error:INVALID_OVERRIDE*/f4;
+ dynamic f4;
}
class Child2 implements Base {
- A /*error:INVALID_OVERRIDE*/f1; // invalid for getter
- C /*error:INVALID_OVERRIDE*/f2; // invalid for setter
+ A f1; // invalid for getter
+ C f2; // invalid for setter
var f3;
- dynamic /*error:INVALID_OVERRIDE*/f4;
+ dynamic f4;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 133, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 163, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 209, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 251, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 281, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 327, 2),
+ ]);
}
test_fieldGetterOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends B {}
@@ -746,23 +851,32 @@
}
class Child extends Base {
- A get /*error:INVALID_OVERRIDE*/f1 => null;
+ A get f1 => null;
C get f2 => null;
get f3 => null;
- dynamic get /*error:INVALID_OVERRIDE*/f4 => null;
+ dynamic get f4 => null;
}
-class /*error:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER*/Child2 implements Base {
- A get /*error:INVALID_OVERRIDE*/f1 => null;
+class Child2 implements Base {
+ A get f1 => null;
C get f2 => null;
get f3 => null;
- dynamic get /*error:INVALID_OVERRIDE*/f4 => null;
+ dynamic get f4 => null;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 146, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 210, 2),
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR,
+ 231,
+ 6),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 264, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 328, 2),
+ ]);
}
test_fieldOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef void ToVoid<T>(T x);
class F {
final ToVoid<dynamic> f = null;
@@ -770,19 +884,22 @@
}
class G extends F {
- final ToVoid<int> /*error:INVALID_OVERRIDE*/f = null;
+ final ToVoid<int> f = null;
final ToVoid<dynamic> g = null;
}
class H implements F {
- final ToVoid<int> /*error:INVALID_OVERRIDE*/f = null;
+ final ToVoid<int> f = null;
final ToVoid<dynamic> g = null;
}
- ''');
+ ''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 146, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 236, 1),
+ ]);
}
test_fieldSetterOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends B {}
@@ -803,7 +920,7 @@
B get f5 => null;
void set f1(A value) {}
- void set /*error:INVALID_OVERRIDE*/f2(C value) {}
+ void set f2(C value) {}
void set f3(value) {}
void set f4(dynamic value) {}
set f5(B value) {}
@@ -817,19 +934,22 @@
B get f5 => null;
void set f1(A value) {}
- void set /*error:INVALID_OVERRIDE*/f2(C value) {}
+ void set f2(C value) {}
void set f3(value) {}
void set f4(dynamic value) {}
set f5(B value) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 275, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 539, 2),
+ ]);
}
test_forInCastsIterateElementToVariable() async {
- await checkFile('''
+ await assertErrorsInCode('''
main() {
// Don't choke if sequence is not iterable.
- for (var i in /*error:FOR_IN_OF_INVALID_TYPE*/1234) {}
+ for (var i in 1234) {}
// Dynamic cast.
for (String s in <dynamic>[]) {}
@@ -843,11 +963,18 @@
// Downcast.
for (int i in <num>[]) {}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 66, 1),
+ error(CompileTimeErrorCode.FOR_IN_OF_INVALID_TYPE, 71, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 114, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 170, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 216, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 263, 1),
+ ]);
}
test_forInCastsSupertypeSequenceToIterate() async {
- await checkFile('''
+ await assertErrorsInCode('''
main() {
dynamic d;
for (var i in d) {}
@@ -855,14 +982,17 @@
Object o;
for (var i in o) {}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 33, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 68, 1),
+ ]);
}
test_forLoopVariable() async {
- await checkFile('''
+ await assertErrorsInCode('''
foo() {
for (int i = 0; i < 10; i++) {
- i = /*error:INVALID_ASSIGNMENT*/"hi";
+ i = "hi";
}
}
bar() {
@@ -870,11 +1000,14 @@
int j = i + 1;
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 49, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 1),
+ ]);
}
test_functionModifiers_async() async {
- await checkFile('''
+ await assertErrorsInCode('''
import 'dart:async';
import 'dart:math' show Random;
@@ -884,9 +1017,7 @@
Future foo2() async => x;
Future<int> foo3() async => x;
Future<int> foo4() async => new Future<int>.value(x);
-Future<int> foo5() async =>
- /*error:RETURN_OF_INVALID_TYPE*/new Future<String>.value(
- x);
+Future<int> foo5() async => new Future<String>.value(x);
bar1() async { return x; }
Future bar2() async { return x; }
@@ -895,8 +1026,7 @@
return new Future<int>.value(x);
}
Future<int> bar5() async {
- return /*error:RETURN_OF_INVALID_TYPE*/new Future<String>.value(
- x);
+ return new Future<String>.value(x);
}
int y;
@@ -906,7 +1036,7 @@
int a = await x;
int b = await y;
int c = await z;
- String d = /*error:INVALID_ASSIGNMENT*/await z;
+ String d = await z;
}
Future<bool> get issue_ddc_264 async {
@@ -922,11 +1052,19 @@
Future<String> issue_sdk_26404() async {
return ((1 > 0) ? new Future<String>.value('hello') : "world");
}
-''');
+''', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 224, 27),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 454, 27),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 529, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 548, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 567, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 589, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 593, 7),
+ ]);
}
test_functionTypingAndSubtyping_classes() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -956,31 +1094,44 @@
}
{
Left f;
- f = /*error:INVALID_CAST_FUNCTION*/top;
+ f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Right f;
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = top;
+ f = left;
f = right;
f = bot;
}
{
Bot f;
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_CAST_FUNCTION*/left;
- f = /*error:INVALID_CAST_FUNCTION*/right;
+ f = top;
+ f = left;
+ f = right;
f = bot;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 405, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 428, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 503, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 514, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 541, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 579, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 590, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 603, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 653, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 664, 3),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 677, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 691, 5),
+ ]);
}
test_functionTypingAndSubtyping_dynamic() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
typedef dynamic Top(Null x); // Top of the lattice
@@ -1004,13 +1155,13 @@
Left f;
f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Right f;
f = top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = left;
f = right;
f = bot;
}
@@ -1022,7 +1173,14 @@
f = bot;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 308, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 383, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 421, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 459, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 483, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 536, 1),
+ ]);
}
test_functionTypingAndSubtyping_dynamic_knownFunctions() async {
@@ -1041,7 +1199,7 @@
// static type errors, since they cannot succeed.
// This makes some of what look like downcasts turn into
// type errors below.
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
typedef dynamic BotTop(Null x);
@@ -1091,63 +1249,63 @@
f = topTop;
f = aa;
f = aTop;
- f = /*error:INVALID_ASSIGNMENT*/botA;
+ f = botA;
f = botTop;
apply<ATop>(
topA,
topTop,
aa,
aTop,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
+ botA,
botTop
- );
+ );
apply<ATop>(
(dynamic x) => new A(),
(dynamic x) => (x as Object),
(A x) => x,
(A x) => null,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
+ botA,
botTop
- );
+ );
}
{
BotA f;
f = topA;
- f = /*error:INVALID_ASSIGNMENT*/topTop;
+ f = topTop;
f = aa;
- f = /*error:INVALID_ASSIGNMENT*/aTop;
+ f = aTop;
f = botA;
f = botTop;
apply<BotA>(
topA,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop,
+ topTop,
aa,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aTop,
+ aTop,
botA,
botTop
- );
+ );
apply<BotA>(
(dynamic x) => new A(),
(dynamic x) => (x as Object),
(A x) => x,
- (A x) => (/*info:UNNECESSARY_CAST*/x as Object),
+ (A x) => (x as Object),
botA,
botTop
- );
+ );
}
{
AA f;
f = topA;
- f = /*error:INVALID_ASSIGNMENT*/topTop;
+ f = topTop;
f = aa;
- f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function
+ f = aTop; // known function
f = botA;
f = botTop;
apply<AA>(
topA,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/topTop,
+ topTop,
aa,
- /*error:INVALID_CAST_FUNCTION*/aTop, // known function
+ aTop, // known function
botA,
botTop
);
@@ -1155,67 +1313,106 @@
(dynamic x) => new A(),
(dynamic x) => (x as Object),
(A x) => x,
- (A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function
+ (A x) => (x as Object), // known function
botA,
botTop
- );
+ );
}
{
TopTop f;
f = topA;
f = topTop;
- f = /*error:INVALID_ASSIGNMENT*/aa;
- f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function
- f = /*error:INVALID_ASSIGNMENT*/botA;
+ f = aa;
+ f = aTop; // known function
+ f = botA;
f = botTop;
apply<TopTop>(
topA,
topTop,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/aa,
- /*error:INVALID_CAST_FUNCTION*/aTop, // known function
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
+ aa,
+ aTop, // known function
+ botA,
botTop
- );
+ );
apply<TopTop>(
(dynamic x) => new A(),
(dynamic x) => (x as Object),
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(A x) => x,
- /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/botA,
+ (A x) => x,
+ (A x) => (x as Object), // known function
+ botA,
botTop
- );
+ );
}
{
TopA f;
f = topA;
- f = /*error:INVALID_CAST_FUNCTION*/topTop; // known function
- f = /*error:INVALID_CAST_FUNCTION*/aa; // known function
- f = /*error:INVALID_CAST_FUNCTION*/aTop; // known function
+ f = topTop; // known function
+ f = aa; // known function
+ f = aTop; // known function
f = botA;
f = botTop;
apply<TopA>(
topA,
- /*error:INVALID_CAST_FUNCTION*/topTop, // known function
- /*error:INVALID_CAST_FUNCTION*/aa, // known function
- /*error:INVALID_CAST_FUNCTION*/aTop, // known function
+ topTop, // known function
+ aa, // known function
+ aTop, // known function
botA,
botTop
- );
+ );
apply<TopA>(
(dynamic x) => new A(),
(dynamic x) => (x as Object), // known function
- /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => x, // known function
- /*error:INVALID_CAST_FUNCTION_EXPR*/(A x) => (/*info:UNNECESSARY_CAST*/x as Object), // known function
+ (A x) => x, // known function
+ (A x) => (x as Object), // known function
botA,
botTop
- );
+ );
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 401, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 822, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 889, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 992, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1158, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1203, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1228, 6),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1256, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1331, 6),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1359, 4),
+ error(HintCode.UNNECESSARY_CAST, 1526, 11),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1591, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1616, 6),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 1644, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1735, 6),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 1763, 4),
+ error(HintCode.UNNECESSARY_CAST, 1960, 11),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2047, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 2088, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2100, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 2132, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2211, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2223, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2255, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2380, 10),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION_EXPR, 2400, 22),
+ error(HintCode.UNNECESSARY_CAST, 2410, 11),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2450, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2495, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2520, 6),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2554, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2584, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2677, 6),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2711, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 2741, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION_EXPR, 2914, 10),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION_EXPR, 2952, 22),
+ error(HintCode.UNNECESSARY_CAST, 2962, 11),
+ ]);
}
test_functionTypingAndSubtyping_functionLiteralVariance() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1236,31 +1433,43 @@
}
{
Function2<B, B> f; // left
- f = /*error:INVALID_CAST_FUNCTION*/top;
+ f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Function2<A, A> f; // right
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = top;
+ f = left;
f = right;
f = bot;
}
{
Function2<A, B> f;
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_CAST_FUNCTION*/left;
- f = /*error:INVALID_CAST_FUNCTION*/right;
+ f = top;
+ f = left;
+ f = right;
f = bot;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 181, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 267, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 286, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 313, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 361, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 381, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 394, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 456, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 467, 3),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 480, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 494, 5),
+ ]);
}
test_functionTypingAndSubtyping_functionVariableVariance() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1280,11 +1489,11 @@
left = top;
left = left;
- left = /*error:INVALID_ASSIGNMENT*/right;
+ left = right;
left = bot;
right = top;
- right = /*error:INVALID_ASSIGNMENT*/left;
+ right = left;
right = right;
right = bot;
@@ -1294,11 +1503,14 @@
bot = bot;
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 296, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 349, 4),
+ ]);
}
test_functionTypingAndSubtyping_higherOrderFunctionLiteral1() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1323,31 +1535,43 @@
}
{
Function2<AToB, AToB> f; // Left
- f = /*error:INVALID_CAST_FUNCTION*/top;
+ f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Function2<BToA, BToA> f; // Right
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = top;
+ f = left;
f = right;
f = bot;
}
{
Function2<BToA, AToB> f; // Bot
f = bot;
- f = /*error:INVALID_CAST_FUNCTION*/left;
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_CAST_FUNCTION*/right;
+ f = left;
+ f = top;
+ f = right;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 337, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 436, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 455, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 482, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 536, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 556, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 569, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 637, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 668, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 682, 3),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 695, 5),
+ ]);
}
test_functionTypingAndSubtyping_higherOrderFunctionLiteral2() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1372,31 +1596,43 @@
}
{
Function2<AToB, AToB> f; // Left
- f = /*error:INVALID_CAST_FUNCTION*/top;
+ f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Function2<BToA, BToA> f; // Right
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = top;
+ f = left;
f = right;
f = bot;
}
{
Function2<BToA, AToB> f; // Bot
f = bot;
- f = /*error:INVALID_CAST_FUNCTION*/left;
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_CAST_FUNCTION*/right;
+ f = left;
+ f = top;
+ f = right;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 403, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 502, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 521, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 548, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 602, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 622, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 635, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 703, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 734, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 748, 3),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 761, 5),
+ ]);
}
test_functionTypingAndSubtyping_higherOrderFunctionLiteral3() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1421,31 +1657,43 @@
}
{
Function2<AToB, AToB> f; // Left
- f = /*error:INVALID_CAST_FUNCTION*/top;
+ f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Function2<BToA, BToA> f; // Right
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = top;
+ f = left;
f = right;
f = bot;
}
{
Function2<BToA, AToB> f; // Bot
f = bot;
- f = /*error:INVALID_CAST_FUNCTION*/left;
- f = /*error:INVALID_CAST_FUNCTION*/top;
- f = /*error:INVALID_CAST_FUNCTION*/right;
+ f = left;
+ f = top;
+ f = right;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 392, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 491, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 510, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 537, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 591, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 611, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 624, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 692, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 723, 4),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 737, 3),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 750, 5),
+ ]);
}
test_functionTypingAndSubtyping_higherOrderFunctionVariables() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1465,13 +1713,11 @@
left = top;
left = left;
- left =
- /*error:INVALID_ASSIGNMENT*/right;
+ left = right;
left = bot;
right = top;
- right =
- /*error:INVALID_ASSIGNMENT*/left;
+ right = left;
right = right;
right = bot;
@@ -1481,11 +1727,14 @@
bot = bot;
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 408, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 461, 4),
+ ]);
}
test_functionTypingAndSubtyping_instanceMethodVariance() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1511,13 +1760,13 @@
Function2<B, B> f;
f = c.top;
f = c.left;
- f = /*error:INVALID_ASSIGNMENT*/c.right;
+ f = c.right;
f = c.bot;
}
{
Function2<A, A> f;
f = c.top;
- f = /*error:INVALID_ASSIGNMENT*/c.left;
+ f = c.left;
f = c.right;
f = c.bot;
}
@@ -1529,11 +1778,18 @@
f = c.bot;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 218, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 312, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 354, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 406, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 432, 6),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 500, 1),
+ ]);
}
test_functionTypingAndSubtyping_intAndObject() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef Object Top(int x); // Top of the lattice
typedef int Left(int x); // Left branch
typedef int Left2(int x); // Left branch
@@ -1569,13 +1825,13 @@
Left f;
f = top;
f = left;
- f = /*error:INVALID_ASSIGNMENT*/right;
+ f = right;
f = bot;
}
{
Right f;
f = top;
- f = /*error:INVALID_ASSIGNMENT*/left;
+ f = left;
f = right;
f = bot;
}
@@ -1587,11 +1843,19 @@
f = bot;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 725, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 748, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 823, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 861, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 899, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 923, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 973, 1),
+ ]);
}
test_functionTypingAndSubtyping_namedAndOptionalParameters() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
typedef A FR(A x);
@@ -1617,99 +1881,150 @@
r = r;
r = o;
- r = /*error:INVALID_ASSIGNMENT*/n;
- r = /*error:INVALID_ASSIGNMENT*/rr;
+ r = n;
+ r = rr;
r = ro;
r = rn;
r = oo;
- r = /*error:INVALID_ASSIGNMENT*/nn;
- r = /*error:INVALID_ASSIGNMENT*/nnn;
+ r = nn;
+ r = nnn;
o = r;
o = o;
- o = /*error:INVALID_ASSIGNMENT*/n;
- o = /*error:INVALID_ASSIGNMENT*/rr;
- o = /*error:INVALID_ASSIGNMENT*/ro;
- o = /*error:INVALID_ASSIGNMENT*/rn;
+ o = n;
+ o = rr;
+ o = ro;
+ o = rn;
o = oo;
- o = /*error:INVALID_ASSIGNMENT*/nn;
- o = /*error:INVALID_ASSIGNMENT*/nnn;
+ o = nn;
+ o = nnn;
- n = /*error:INVALID_ASSIGNMENT*/r;
- n = /*error:INVALID_ASSIGNMENT*/o;
+ n = r;
+ n = o;
n = n;
- n = /*error:INVALID_ASSIGNMENT*/rr;
- n = /*error:INVALID_ASSIGNMENT*/ro;
- n = /*error:INVALID_ASSIGNMENT*/rn;
- n = /*error:INVALID_ASSIGNMENT*/oo;
+ n = rr;
+ n = ro;
+ n = rn;
+ n = oo;
n = nn;
n = nnn;
- rr = /*error:INVALID_ASSIGNMENT*/r;
- rr = /*error:INVALID_ASSIGNMENT*/o;
- rr = /*error:INVALID_ASSIGNMENT*/n;
+ rr = r;
+ rr = o;
+ rr = n;
rr = rr;
rr = ro;
- rr = /*error:INVALID_ASSIGNMENT*/rn;
+ rr = rn;
rr = oo;
- rr = /*error:INVALID_ASSIGNMENT*/nn;
- rr = /*error:INVALID_ASSIGNMENT*/nnn;
+ rr = nn;
+ rr = nnn;
ro = r;
- ro = /*error:INVALID_ASSIGNMENT*/o;
- ro = /*error:INVALID_ASSIGNMENT*/n;
+ ro = o;
+ ro = n;
ro = rr;
ro = ro;
- ro = /*error:INVALID_ASSIGNMENT*/rn;
+ ro = rn;
ro = oo;
- ro = /*error:INVALID_ASSIGNMENT*/nn;
- ro = /*error:INVALID_ASSIGNMENT*/nnn;
+ ro = nn;
+ ro = nnn;
rn = r;
- rn = /*error:INVALID_ASSIGNMENT*/o;
- rn = /*error:INVALID_ASSIGNMENT*/n;
- rn = /*error:INVALID_ASSIGNMENT*/rr;
- rn = /*error:INVALID_ASSIGNMENT*/ro;
+ rn = o;
+ rn = n;
+ rn = rr;
+ rn = ro;
rn = rn;
- rn = /*error:INVALID_ASSIGNMENT*/oo;
- rn = /*error:INVALID_ASSIGNMENT*/nn;
- rn = /*error:INVALID_ASSIGNMENT*/nnn;
+ rn = oo;
+ rn = nn;
+ rn = nnn;
oo = r;
oo = o;
- oo = /*error:INVALID_ASSIGNMENT*/n;
+ oo = n;
oo = rr;
oo = ro;
- oo = /*error:INVALID_ASSIGNMENT*/rn;
+ oo = rn;
oo = oo;
- oo = /*error:INVALID_ASSIGNMENT*/nn;
- oo = /*error:INVALID_ASSIGNMENT*/nnn;
+ oo = nn;
+ oo = nnn;
- nn = /*error:INVALID_ASSIGNMENT*/r;
- nn = /*error:INVALID_ASSIGNMENT*/o;
+ nn = r;
+ nn = o;
nn = n;
- nn = /*error:INVALID_ASSIGNMENT*/rr;
- nn = /*error:INVALID_ASSIGNMENT*/ro;
- nn = /*error:INVALID_ASSIGNMENT*/rn;
- nn = /*error:INVALID_ASSIGNMENT*/oo;
+ nn = rr;
+ nn = ro;
+ nn = rn;
+ nn = oo;
nn = nn;
nn = nnn;
- nnn = /*error:INVALID_ASSIGNMENT*/r;
- nnn = /*error:INVALID_ASSIGNMENT*/o;
+ nnn = r;
+ nnn = o;
nnn = n;
- nnn = /*error:INVALID_ASSIGNMENT*/rr;
- nnn = /*error:INVALID_ASSIGNMENT*/ro;
- nnn = /*error:INVALID_ASSIGNMENT*/rn;
- nnn = /*error:INVALID_ASSIGNMENT*/oo;
+ nnn = rr;
+ nnn = ro;
+ nnn = rn;
+ nnn = oo;
nnn = nn;
nnn = nnn;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 377, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 387, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 431, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 442, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 475, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 485, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 496, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 507, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 529, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 540, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 553, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 563, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 583, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 594, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 605, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 616, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 652, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 663, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 674, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 709, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 733, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 745, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 770, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 781, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 816, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 840, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 852, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 877, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 888, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 899, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 911, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 935, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 947, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 959, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 995, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1030, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1054, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1066, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1080, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1091, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1113, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1125, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1137, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1149, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1188, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1200, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1224, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1237, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1250, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1263, 2),
+ ]);
}
test_functionTypingAndSubtyping_objectsWithCallMethods() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef int I2I(int x);
typedef num N2N(num x);
class A {
@@ -1724,38 +2039,38 @@
{
I2I f;
f = new A();
- f = /*error:INVALID_ASSIGNMENT*/new B();
+ f = new B();
f = i2i;
- f = /*error:INVALID_ASSIGNMENT*/n2n;
- f = /*info:UNNECESSARY_CAST*/i2i as Object;
- f = /*info:UNNECESSARY_CAST*/n2n as Function;
+ f = n2n;
+ f = i2i as Object;
+ f = n2n as Function;
}
{
N2N f;
- f = /*error:INVALID_ASSIGNMENT*/new A();
+ f = new A();
f = new B();
- f = /*error:INVALID_ASSIGNMENT*/i2i;
+ f = i2i;
f = n2n;
- f = /*info:UNNECESSARY_CAST*/i2i as Object;
- f = /*info:UNNECESSARY_CAST*/n2n as Function;
+ f = i2i as Object;
+ f = n2n as Function;
}
{
A f;
f = new A();
- f = /*error:INVALID_ASSIGNMENT*/new B();
- f = /*error:INVALID_ASSIGNMENT*/i2i;
- f = /*error:INVALID_ASSIGNMENT*/n2n;
- f = /*info:UNNECESSARY_CAST*/i2i as Object;
- f = /*info:UNNECESSARY_CAST,error:INVALID_ASSIGNMENT*/n2n as Function;
+ f = new B();
+ f = i2i;
+ f = n2n;
+ f = i2i as Object;
+ f = n2n as Function;
}
{
B f;
- f = /*error:INVALID_ASSIGNMENT*/new A();
+ f = new A();
f = new B();
- f = /*error:INVALID_ASSIGNMENT*/i2i;
- f = /*error:INVALID_ASSIGNMENT*/n2n;
- f = /*info:UNNECESSARY_CAST*/i2i as Object;
- f = /*info:UNNECESSARY_CAST,error:INVALID_ASSIGNMENT*/n2n as Function;
+ f = i2i;
+ f = n2n;
+ f = i2i as Object;
+ f = n2n as Function;
}
{
Function f;
@@ -1763,15 +2078,43 @@
f = new B();
f = i2i;
f = n2n;
- f = /*info:UNNECESSARY_CAST*/i2i as Object;
- f = /*info:UNNECESSARY_CAST*/n2n as Function;
+ f = i2i as Object;
+ f = n2n as Function;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 192, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 222, 7),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 254, 3),
+ error(HintCode.UNNECESSARY_CAST, 268, 13),
+ error(HintCode.UNNECESSARY_CAST, 292, 15),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 328, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 340, 7),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 376, 3),
+ error(HintCode.UNNECESSARY_CAST, 404, 13),
+ error(HintCode.UNNECESSARY_CAST, 428, 15),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 462, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 492, 7),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 510, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 524, 3),
+ error(HintCode.UNNECESSARY_CAST, 538, 13),
+ error(HintCode.UNNECESSARY_CAST, 562, 15),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 562, 15),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 596, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 608, 7),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 644, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 658, 3),
+ error(HintCode.UNNECESSARY_CAST, 672, 13),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 696, 15),
+ error(HintCode.UNNECESSARY_CAST, 696, 15),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 737, 1),
+ error(HintCode.UNNECESSARY_CAST, 813, 13),
+ error(HintCode.UNNECESSARY_CAST, 837, 15),
+ ]);
}
test_functionTypingAndSubtyping_staticMethodVariance() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1794,31 +2137,43 @@
}
{
Function2<B, B> f;
- f = /*error:INVALID_CAST_METHOD*/C.top;
+ f = C.top;
f = C.left;
- f = /*error:INVALID_ASSIGNMENT*/C.right;
+ f = C.right;
f = C.bot;
}
{
Function2<A, A> f;
- f = /*error:INVALID_CAST_METHOD*/C.top;
- f = /*error:INVALID_ASSIGNMENT*/C.left;
+ f = C.top;
+ f = C.left;
f = C.right;
f = C.bot;
}
{
Function2<A, B> f;
- f = /*error:INVALID_CAST_METHOD*/C.top;
- f = /*error:INVALID_CAST_METHOD*/C.left;
- f = /*error:INVALID_CAST_METHOD*/C.right;
+ f = C.top;
+ f = C.left;
+ f = C.right;
f = C.bot;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 229, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 323, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_METHOD, 334, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 365, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 417, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_METHOD, 428, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 443, 6),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 511, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_METHOD, 522, 5),
+ error(CompileTimeErrorCode.INVALID_CAST_METHOD, 537, 6),
+ error(CompileTimeErrorCode.INVALID_CAST_METHOD, 553, 7),
+ ]);
}
test_functionTypingAndSubtyping_subtypeOfUniversalType() async {
- await checkFile('''
+ await assertErrorsInCode('''
void main() {
nonGenericFn(x) => null;
{
@@ -1829,8 +2184,8 @@
local = g; // valid
// Non-generic function cannot subtype a generic one.
- local = /*error:INVALID_ASSIGNMENT*/(x) => null;
- local = /*error:INVALID_ASSIGNMENT*/nonGenericFn;
+ local = (x) => null;
+ local = nonGenericFn;
}
{
Iterable<R> f<P, R>(List<P> p) => null;
@@ -1841,29 +2196,38 @@
var local2 = g;
local = local2;
- local2 = /*error:INVALID_CAST_FUNCTION*/f;
+ local2 = f;
local2 = local;
// Non-generic function cannot subtype a generic one.
- local = /*error:INVALID_ASSIGNMENT*/(x) => null;
- local = /*error:INVALID_ASSIGNMENT*/nonGenericFn;
+ local = (x) => null;
+ local = nonGenericFn;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 216, 11),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 241, 12),
+ error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 449, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 543, 11),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 568, 12),
+ ]);
}
test_functionTypingAndSubtyping_uninferredClosure() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef num Num2Num(num x);
void main() {
- Num2Num g = /*error:INVALID_ASSIGNMENT*/(int x) { return x; };
+ Num2Num g = (int x) { return x; };
print(g(42));
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 56, 21),
+ ]);
}
test_functionTypingAndSubtyping_void() async {
- await checkFile('''
+ await assertNoErrorsInCode('''
class A {
void bar() => null;
void foo() => bar(); // allowed
@@ -1872,7 +2236,7 @@
}
test_genericClassMethodOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -1881,43 +2245,63 @@
}
class Derived<S extends A> extends Base<B> {
- S /*error:INVALID_OVERRIDE*/foo() => null;
+ S foo() => null;
}
class Derived2<S extends B> extends Base<B> {
S foo() => null;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 130, 3),
+ ]);
}
test_genericFunctionWrongNumberOfArguments() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
T foo<T>(T x, T y) => x;
T bar<T>({T x, T y}) => x;
main() {
String x;
// resolving these shouldn't crash.
- foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/(1, 2, 3);
- x = foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/('1', '2', '3');
- foo/*error:NOT_ENOUGH_POSITIONAL_ARGUMENTS*/(1);
- x = foo/*error:NOT_ENOUGH_POSITIONAL_ARGUMENTS*/('1');
- x = foo/*error:EXTRA_POSITIONAL_ARGUMENTS*/(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/2, 3);
- x = foo/*error:NOT_ENOUGH_POSITIONAL_ARGUMENTS*/(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/1);
+ foo(1, 2, 3);
+ x = foo('1', '2', '3');
+ foo(1);
+ x = foo('1');
+ x = foo(1, 2, 3);
+ x = foo(1);
// named arguments
- bar(y: 1, x: 2, /*error:UNDEFINED_NAMED_PARAMETER*/z: 3);
- x = bar(/*error:UNDEFINED_NAMED_PARAMETER*/z: '1', x: '2', y: '3');
+ bar(y: 1, x: 2, z: 3);
+ x = bar(z: '1', x: '2', y: '3');
bar(y: 1);
- x = bar(x: '1', /*error:UNDEFINED_NAMED_PARAMETER*/z: 42);
- x = bar(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y: 1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/x: 2, /*error:UNDEFINED_NAMED_PARAMETER*/z: 3);
- x = bar(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/x: 1);
+ x = bar(x: '1', z: 42);
+ x = bar(y: 1, x: 2, z: 3);
+ x = bar(x: 1);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 71, 1),
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 117, 9),
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 137, 15),
+ error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 159, 3),
+ error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 173, 5),
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 189, 9),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 190, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 193, 1),
+ error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 209, 3),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 210, 1),
+ error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 254, 1),
+ error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 271, 1),
+ error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 327, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 345, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 351, 4),
+ error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 357, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 374, 4),
+ ]);
}
test_genericMethodOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class Future<T> {
S then<S>(S onValue(T t)) => null;
}
@@ -1937,11 +2321,11 @@
class DerivedFuture4<A> extends Future<A> {
B then<B>(Object onValue(A a)) => null;
}
-''');
+''', []);
}
test_genericMethodSuper() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
class A<T> {
A<S> create<S extends T>() => new A<S>();
}
@@ -1955,16 +2339,19 @@
A<S> create<S extends num>() => super.create<S>();
}
class E extends A<num> {
- A<S> create<S extends num>() => /*error:RETURN_OF_INVALID_TYPE*/super.create<int>();
+ A<S> create<S extends num>() => super.create<int>();
}
class F extends A<num> {
create2<S>() => super.create</*error:TYPE_ARGUMENT_NOT_MATCHING_BOUNDS*/S>();
}
- ''');
+''', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 321, 19),
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 443, 1),
+ ]);
}
test_genericMethodSuperSubstitute() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
class Cloneable<T> {}
class G<T> {
create<A extends Cloneable<T>, B extends Iterable<A>>() => null;
@@ -1972,11 +2359,11 @@
class H extends G<num> {
create2() => super.create<Cloneable<int>, List<Cloneable<int>>>();
}
- ''');
+''', []);
}
test_getterGetterOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends B {}
@@ -1989,16 +2376,19 @@
}
class Child extends Base {
- A get /*error:INVALID_OVERRIDE*/f1 => null;
+ A get f1 => null;
C get f2 => null;
get f3 => null;
- dynamic get /*error:INVALID_OVERRIDE*/f4 => null;
+ dynamic get f4 => null;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 162, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 226, 2),
+ ]);
}
test_getterOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef void ToVoid<T>(T x);
class F {
@@ -2007,19 +2397,22 @@
}
class G extends F {
- ToVoid<int> get /*error:INVALID_OVERRIDE*/f => null;
+ ToVoid<int> get f => null;
ToVoid<dynamic> get g => null;
}
class H implements F {
- ToVoid<int> get /*error:INVALID_OVERRIDE*/f => null;
+ ToVoid<int> get f => null;
ToVoid<dynamic> get g => null;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 143, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 231, 1),
+ ]);
}
test_ifForDoWhileStatementsUseBooleanConversion() async {
- await checkFile('''
+ await assertErrorsInCode('''
main() {
dynamic dyn = 42;
Object obj = 42;
@@ -2029,267 +2422,565 @@
if (b) {}
if (dyn) {}
if (obj) {}
- if (/*error:NON_BOOL_CONDITION*/i) {}
+ if (i) {}
while (b) {}
while (dyn) {}
while (obj) {}
- while (/*error:NON_BOOL_CONDITION*/i) {}
+ while (i) {}
do {} while (b);
do {} while (dyn);
do {} while (obj);
- do {} while (/*error:NON_BOOL_CONDITION*/i);
+ do {} while (i);
for (;b;) {}
for (;dyn;) {}
for (;obj;) {}
- for (;/*error:NON_BOOL_CONDITION*/i;) {}
+ for (;i;) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 127, 1),
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 192, 1),
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 275, 1),
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 337, 1),
+ ]);
}
test_implicitCasts_assignment() async {
- addFile('num n; int i; void main() { i = n;}//yy');
- await check();
-
- addFile(
- 'num n; int i; void main() { i = /*error:INVALID_ASSIGNMENT*/n;}//ny');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(
+ 'void f(num n, int i) { i = n;}',
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 27, 1),
+ ],
+ );
}
test_implicitCasts_compoundAssignment() async {
- addFile('''f(num n, int i) {
- i += n;}//yy''');
- await check();
-
- addFile('''f(num n, int i) {
- i += /*error:INVALID_ASSIGNMENT*/n;}//ny''');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(
+ 'void f(num n, int i) { i += n; }',
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 28, 1),
+ ],
+ );
}
test_implicitCasts_constructorInitializer() async {
- addFile('class A { int i; A(num n) : i = n;}//yy');
- await check();
-
- addFile(
- 'class A { int i; A(num n) : i = /*error:FIELD_INITIALIZER_NOT_ASSIGNABLE*/n;}//ny');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(
+ 'class A { int i; A(num n) : i = n; }',
+ [
+ error(CompileTimeErrorCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, 32, 1),
+ ],
+ );
}
test_implicitCasts_defaultValue() async {
- addFile('''const num n = 0;
- f({int i = n}) => i;//yy''');
- await check();
-
- addFile('''const num n = 0;
- f({int i = /*error:INVALID_ASSIGNMENT*/n}) => i;//ny''');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(
+ 'const num n = 0; int f({int i = n}) => i;',
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 32, 1),
+ ],
+ );
}
test_implicitCasts_fieldInitializer() async {
- addFile('class A { static num n; int i = n;}//yy');
- await check();
-
- addFile(
- 'class A { static num n; int i = /*error:INVALID_ASSIGNMENT*/n;}//nn');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(
+ 'class A { static num n; int i = n; }',
+ [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 32, 1),
+ ],
+ );
}
test_implicitCasts_forEach() async {
- addFile(r'''
-main(dynamic a) {
+ await _assertImplicitCasts(r'''
+void f(dynamic a) {
for (int v in a) {
v;
}
}
-''');
- await check();
-
- addFile(r'''
-main(dynamic a) {
- for (int v in /*error:FOR_IN_OF_INVALID_ELEMENT_TYPE*/a) {
- v;
- }
-}
-''');
- await check(implicitCasts: false);
+''', [
+ error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 36, 1),
+ ]);
}
test_implicitCasts_forEach_async() async {
- addFile(r'''
-main(dynamic a) async {
+ await _assertImplicitCasts(r'''
+void f(dynamic a) async {
await for (int v in a) {
v;
}
}
-''');
- await check();
-
- addFile(r'''
-main(dynamic a) async {
- await for (int v in /*error:FOR_IN_OF_INVALID_ELEMENT_TYPE*/a) {
- v;
- }
-}
-''');
- await check(implicitCasts: false);
+''', [
+ error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 48, 1),
+ ]);
}
test_implicitCasts_functionCall() async {
- addFile('''num n;
- f(int i) => i;
- var i = f(n);//yy''');
- await check();
-
- addFile('''num n;
- f(int i) => i;
- var i = f(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/n);//nn''');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(r'''
+int f(int i) => i;
+num n = 0;
+var v = f(n);
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 40, 1),
+ ]);
}
test_implicitCasts_genericMethods() async {
- addFile('''
-var x = <String>[].map<String>((x) => "");
-''');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(r'''
+var x = <String>[].map<String>((x) => '');
+''', []);
}
test_implicitCasts_initializer() async {
- addFile('num n; int i = n;//yy');
- await check();
+ await _assertImplicitCasts(r'''
+num n = 0;
+int i = n;
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 19, 1),
+ ]);
+ }
- addFile('num n; int i = /*error:INVALID_ASSIGNMENT*/n;//nn');
- await check(implicitCasts: false);
+ test_implicitCasts_list_ifElement_condition_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(dynamic c) {
+ <int>[if (c) 0];
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 32, 1),
+ ]);
+ }
+
+ test_implicitCasts_list_ifElement_condition_object() async {
+ await _assertImplicitCasts(r'''
+void f(Object c) {
+ <int>[if (c) 0];
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 31, 1),
+ ]);
+ }
+
+ test_implicitCasts_list_ifElement_falseBranch_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int>[if (c) 0 else a];
+}
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 50, 1),
+ ]);
+ }
+
+ test_implicitCasts_list_ifElement_falseBranch_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int>[if (c) 0 else a];
+}
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 46, 1),
+ ]);
+ }
+
+ test_implicitCasts_list_ifElement_trueBranch_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int>[if (c) a];
+}
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 43, 1),
+ ]);
+ }
+
+ test_implicitCasts_list_ifElement_trueBranch_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int>[if (c) a];
+}
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 39, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_condition_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(dynamic c) {
+ <int, int>{if (c) 0: 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 37, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_condition_object() async {
+ await _assertImplicitCasts(r'''
+void f(Object c) {
+ <int, int>{if (c) 0: 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 36, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_falseBranch_key_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int, int>{if (c) 0: 0 else a: 0};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 58, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_falseBranch_key_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int, int>{if (c) 0: 0 else a: 0};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 54, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_falseBranch_value_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int, int>{if (c) 0: 0 else 0: a};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 61, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_falseBranch_value_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int, int>{if (c) 0: 0 else 0: a};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 57, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_trueBranch_key_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int, int>{if (c) a: 0 };
+}
+''', [
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 48, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_trueBranch_key_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int, int>{if (c) a: 0};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 44, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_trueBranch_value_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int, int>{if (c) 0: a};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 51, 1),
+ ]);
+ }
+
+ test_implicitCasts_map_ifElement_trueBranch_value_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int, int>{if (c) 0: a};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 47, 1),
+ ]);
}
test_implicitCasts_numericOps() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26912
- addFile(r'''
-void f() {
- int x = 0;
- int y = 0;
+ await _assertImplicitCasts(r'''
+void f(int x, int y) {
x += y;
}
- ''');
- await check(implicitCasts: false);
+''', []);
}
test_implicitCasts_operator() async {
- addFile('''num n;
- int i;
- var r = i & n;//yy''');
- await check();
-
- addFile('''num n;
- int i;
- var r = i & /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/n;//nn''');
- await check(implicitCasts: false);
+ await _assertImplicitCasts(r'''
+num n = 0;
+int i = 0;
+var v = i & n;
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 34, 1),
+ ]);
}
test_implicitCasts_return() async {
- addFile('int f(num n) => n;//yy');
- await check();
-
- addFile('int f(num n) => /*error:RETURN_OF_INVALID_TYPE*/n;//nn');
- await check(implicitCasts: false);
+ await _assertImplicitCasts('int f(num n) => n;', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 16, 1),
+ ]);
}
test_implicitCasts_return_async() async {
- addFile(r'''
-import 'dart:async';
-
-Future<List<String>> foo() async {
- List<Object> x = <Object>["hello", "world"];
+ await _assertImplicitCasts(r'''
+Future<List<String>> f() async {
+ List<Object> x = <Object>['hello', 'world'];
return x;
}
- ''');
- await check();
+''', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 89, 1),
+ ]);
+ }
+
+ test_implicitCasts_set_ifElement_condition_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(dynamic c) {
+ <int>{if (c) 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 32, 1),
+ ]);
+ }
+
+ test_implicitCasts_set_ifElement_condition_object() async {
+ await _assertImplicitCasts(r'''
+void f(Object c) {
+ <int>{if (c) 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 31, 1),
+ ]);
+ }
+
+ test_implicitCasts_set_ifElement_falseBranch_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int>{if (c) 0 else a};
+}
+''', [
+ error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 50, 1),
+ ]);
+ }
+
+ test_implicitCasts_set_ifElement_falseBranch_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int>{if (c) 0 else a};
+}
+''', [
+ error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 46, 1),
+ ]);
+ }
+
+ test_implicitCasts_set_ifElement_trueBranch_dynamic() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, dynamic a) {
+ <int>{if (c) a};
+}
+''', [
+ error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 43, 1),
+ ]);
+ }
+
+ test_implicitCasts_set_ifElement_trueBranch_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(bool c, num a) {
+ <int>{if (c) a};
+}
+''', [
+ error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 39, 1),
+ ]);
+ }
+
+ @failingTest
+ test_implicitCasts_test_list_spread_dynamic() async {
+ // TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
+ await _assertImplicitCasts(r'''
+void f(dynamic a) {
+ [...a];
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 26, 1),
+ ]);
+ }
+
+ test_implicitCasts_test_list_spread_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(Iterable<num> a) {
+ <int>[...a];
+}
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 37, 1),
+ ]);
+ }
+
+ @failingTest
+ test_implicitCasts_test_map_spread_dynamic() async {
+ // TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
+ await _assertImplicitCasts(r'''
+void f(dynamic a) {
+ <dynamic, dynamic>{...a};
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 44, 1),
+ ]);
+ }
+
+ test_implicitCasts_test_map_spread_key_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(Map<num, dynamic> a) {
+ <int, dynamic>{...a};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 50, 1),
+ ]);
+ }
+
+ test_implicitCasts_test_map_spread_value_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(Map<dynamic, num> a) {
+ <dynamic, int>{...a};
+}
+''', [
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 50, 1),
+ ]);
+ }
+
+ @failingTest
+ test_implicitCasts_test_set_spread_dynamic() async {
+ // TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
+ await _assertImplicitCasts(r'''
+void f(dynamic a) {
+ <dynamic>{...a};
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 35, 1),
+ ]);
+ }
+
+ test_implicitCasts_test_set_spread_supertype() async {
+ await _assertImplicitCasts(r'''
+void f(Iterable<num> a) {
+ <int>{...a};
+}
+''', [
+ error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 37, 1),
+ ]);
}
test_implicitDynamic_field() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
class C {
- var /*error:IMPLICIT_DYNAMIC_FIELD*/x0;
- var /*error:IMPLICIT_DYNAMIC_FIELD*/x1 = (<dynamic>[])[0];
- var /*error:IMPLICIT_DYNAMIC_FIELD*/x2,
- x3 = 42,
- /*error:IMPLICIT_DYNAMIC_FIELD*/x4;
+ var x0;
+ var x1 = (<dynamic>[])[0];
+ var x2, x3 = 42, x4;
dynamic y0;
dynamic y1 = (<dynamic>[])[0];
}
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FIELD, 16, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FIELD, 26, 21),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FIELD, 55, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FIELD, 68, 2),
+ ]);
}
test_implicitDynamic_function() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
T a<T>(T t) => t;
T b<T>() => null;
void main<S>() {
dynamic d;
int i;
- /*error:IMPLICIT_DYNAMIC_FUNCTION*/a(d);
+ a(d);
a(42);
- /*error:IMPLICIT_DYNAMIC_FUNCTION*/b();
- d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/b();
+ b();
+ d = b();
i = b();
void f<T>(T t) {};
T g<T>() => null;
- /*error:IMPLICIT_DYNAMIC_FUNCTION*/f(d);
+ f(d);
f(42);
- /*error:IMPLICIT_DYNAMIC_FUNCTION*/g();
- d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/g();
+ g();
+ d = g();
i = g();
- /*error:IMPLICIT_DYNAMIC_INVOKE*/(<T>(T t) => t)(d);
+ (<T>(T t) => t)(d);
(<T>(T t) => t)(42);
- (<T>() => /*info:UNNECESSARY_CAST*/null as T)<int>();
+ (<T>() => null as T)<int>();
}
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 73, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION, 78, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION, 95, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION, 106, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION, 167, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION, 184, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION, 195, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_INVOKE, 214, 15),
+ error(HintCode.UNNECESSARY_CAST, 269, 9),
+ ]);
}
test_implicitDynamic_listLiteral() async {
- addFile(r'''
-
-var l0 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[];
-List l1 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[];
-List<dynamic> l2 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[];
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
+var l0 = [];
+List l1 = [];
+List<dynamic> l2 = [];
dynamic d = 42;
-var l3 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[d, d];
+var l3 = [d, d];
var l4 = <dynamic>[];
var l5 = <int>[];
List<int> l6 = [];
var l7 = [42];
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 9, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 23, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 46, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 75, 6),
+ ]);
}
test_implicitDynamic_mapLiteral() async {
- addFile(r'''
-var m0 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
-Map m1 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
-Map<dynamic, dynamic> m2 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
+var m0 = {};
+Map m1 = {};
+Map<dynamic, dynamic> m2 = {};
dynamic d = 42;
-var m3 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{d: d};
-var m4 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{'x': d, 'y': d};
-var m5 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{d: 'x'};
+var m3 = {d: d};
+var m4 = {'x': d, 'y': d};
+var m5 = {d: 'x'};
var m6 = <dynamic, dynamic>{};
var m7 = <String, String>{};
Map<String, String> m8 = {};
var m9 = {'hi': 'there'};
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 9, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 22, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 53, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 82, 6),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 99, 16),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 126, 8),
+ ]);
}
test_implicitDynamic_method() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
class C {
T m<T>(T s) => s;
T n<T>() => null;
@@ -2301,66 +2992,82 @@
void f() {
dynamic d;
int i;
- new C()./*error:IMPLICIT_DYNAMIC_METHOD*/m(d);
+ new C().m(d);
new C().m(42);
- new C()./*error:IMPLICIT_DYNAMIC_METHOD*/n();
- d = new C()./*error:IMPLICIT_DYNAMIC_METHOD*/n();
+ new C().n();
+ d = new C().n();
i = new C().n();
- new D<int>()./*error:IMPLICIT_DYNAMIC_METHOD*/m(d);
+ new D<int>().m(d);
new D<int>().m(42);
- new D<int>()./*error:IMPLICIT_DYNAMIC_METHOD*/n();
- d = new D<int>()./*error:IMPLICIT_DYNAMIC_METHOD*/n();
+ new D<int>().n();
+ d = new D<int>().n();
i = new D<int>().n();
}
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 137, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_METHOD, 150, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_METHOD, 183, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_METHOD, 202, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_METHOD, 242, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_METHOD, 285, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_METHOD, 309, 1),
+ ]);
}
test_implicitDynamic_parameter() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
const dynamic DYNAMIC_VALUE = 42;
// simple formal
-void f0(/*error:IMPLICIT_DYNAMIC_PARAMETER*/x) {}
+void f0(x) {}
void f1(dynamic x) {}
// default formal
-void df0([/*error:IMPLICIT_DYNAMIC_PARAMETER*/x = DYNAMIC_VALUE]) {}
+void df0([x = DYNAMIC_VALUE]) {}
void df1([dynamic x = DYNAMIC_VALUE]) {}
// https://github.com/dart-lang/sdk/issues/25794
-void df2([/*error:IMPLICIT_DYNAMIC_PARAMETER*/x = 42]) {}
+void df2([x = 42]) {}
// default formal (named)
-void nf0({/*error:IMPLICIT_DYNAMIC_PARAMETER*/x: DYNAMIC_VALUE}) {}
+void nf0({x: DYNAMIC_VALUE}) {}
void nf1({dynamic x: DYNAMIC_VALUE}) {}
// https://github.com/dart-lang/sdk/issues/25794
-void nf2({/*error:IMPLICIT_DYNAMIC_PARAMETER*/x: 42}) {}
+void nf2({x: 42}) {}
// field formal
class C {
- var /*error:IMPLICIT_DYNAMIC_FIELD*/x;
+ var x;
C(this.x);
}
// function typed formal
-void ftf0(void x(/*error:IMPLICIT_DYNAMIC_PARAMETER*/y)) {}
+void ftf0(void x(y)) {}
void ftf1(void x(int y)) {}
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER, 60, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER, 117, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER, 241, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER, 290, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER, 412, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_FIELD, 456, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER, 517, 1),
+ ]);
}
test_implicitDynamic_return() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
// function
-/*error:IMPLICIT_DYNAMIC_RETURN*/f0() {return f0();}
+f0() {return f0();}
dynamic f1() { return 42; }
// nested function
void main() {
- /*error:IMPLICIT_DYNAMIC_RETURN*/g0() {return g0();}
+ g0() {return g0();}
dynamic g1() { return 42; }
}
@@ -2369,29 +3076,37 @@
int m1() => 42;
}
class C extends B {
- /*error:IMPLICIT_DYNAMIC_RETURN*/m0() => 123;
+ m0() => 123;
m1() => 123;
dynamic m2() => 'hi';
}
// accessors
set x(int value) {}
-get /*error:IMPLICIT_DYNAMIC_RETURN*/y0 => 42;
+get y0 => 42;
dynamic get y1 => 42;
// function typed formals
-void ftf0(/*error:IMPLICIT_DYNAMIC_RETURN*/f(int x)) {}
+void ftf0(f(int x)) {}
void ftf1(dynamic f(int x)) {}
// function expressions
var fe0 = (int x) => x as dynamic;
var fe1 = (int x) => x;
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, 12, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, 96, 2),
+ error(HintCode.UNUSED_ELEMENT, 96, 2),
+ error(HintCode.UNUSED_ELEMENT, 126, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, 212, 12),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, 304, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, 373, 1),
+ ]);
}
test_implicitDynamic_static() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
class C {
static void test(int body()) {}
}
@@ -2401,28 +3116,28 @@
return 42;
});
}
-''');
- await check(implicitDynamic: false);
+''', []);
}
test_implicitDynamic_type() async {
- addFile(r'''
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
class C<T> {}
-class M1<T extends /*error:IMPLICIT_DYNAMIC_TYPE*/List> {}
+class M1<T extends List> {}
class M2<T> {}
class I<T> {}
-class D<T, S> extends /*error:IMPLICIT_DYNAMIC_TYPE*/C
- with M1, /*error:IMPLICIT_DYNAMIC_TYPE*/M2
- implements /*error:IMPLICIT_DYNAMIC_TYPE*/I {}
-class D2<T, S> = /*error:IMPLICIT_DYNAMIC_TYPE*/C
- with M1, /*error:IMPLICIT_DYNAMIC_TYPE*/M2
- implements /*error:IMPLICIT_DYNAMIC_TYPE*/I;
+class D<T, S> extends C
+ with M1, M2
+ implements I {}
+class D2<T, S> = C
+ with M1, M2
+ implements I;
C f(D d) {
- D x = new /*error:IMPLICIT_DYNAMIC_TYPE*/D();
- D<int, dynamic> y = new /*error:IMPLICIT_DYNAMIC_TYPE*/D();
- D<dynamic, int> z = new /*error:IMPLICIT_DYNAMIC_TYPE*/D();
- return new /*error:IMPLICIT_DYNAMIC_TYPE*/C();
+ D x = new D();
+ D<int, dynamic> y = new D();
+ D<dynamic, int> z = new D();
+ return new C();
}
class A<T extends num> {}
@@ -2434,26 +3149,44 @@
B y = new B();
return new A();
}
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 33, 4),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 93, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 108, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 126, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 148, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 163, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 181, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 200, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 208, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 231, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 239, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 262, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 270, 1),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_TYPE, 288, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 493, 1),
+ ]);
}
test_implicitDynamic_variable() async {
- addFile(r'''
-var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x0;
-var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x1 = (<dynamic>[])[0];
-var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x2,
- x3 = 42,
- /*error:IMPLICIT_DYNAMIC_VARIABLE*/x4;
+ _disableTestPackageImplicitDynamic();
+ await assertErrorsInCode(r'''
+var x0;
+var x1 = (<dynamic>[])[0];
+var x2, x3 = 42, x4;
dynamic y0;
dynamic y1 = (<dynamic>[])[0];
- ''');
- await check(implicitDynamic: false);
+''', [
+ error(StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE, 4, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE, 12, 21),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE, 39, 2),
+ error(StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE, 52, 2),
+ ]);
}
test_interfaceOverridesAreAllChecked() {
// Regression test for https://github.com/dart-lang/sdk/issues/29766
- return checkFile(r'''
+ return assertErrorsInCode(r'''
class B {
set x(int y) {}
}
@@ -2461,34 +3194,39 @@
set x(Object y) {}
}
class D implements B, C {
- int /*error:INVALID_OVERRIDE*/x;
+ int x;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 95, 1),
+ ]);
}
test_interfacesFromMixinsAreChecked() {
// Regression test for https://github.com/dart-lang/sdk/issues/29782
- return checkFile(r'''
+ return assertErrorsInCode(r'''
abstract class I {
set x(int v);
}
abstract class M implements I {}
class C extends Object with M {
- String /*error:INVALID_OVERRIDE*/x;
+ String x;
}
abstract class M2 = Object with M;
class C2 extends Object with M2 {
- String /*error:INVALID_OVERRIDE*/x;
+ String x;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 112, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 197, 1),
+ ]);
}
test_interfacesFromMixinsOnlyConsiderMostDerivedMember() {
// Regression test for dart2js interface pattern in strong mode.
- return checkFile(r'''
+ return assertErrorsInCode(r'''
abstract class I1 { num get x; }
abstract class I2 extends I1 { int get x; }
@@ -2499,53 +3237,61 @@
class Child extends Base with M2 implements I2 {}
class C extends Object with M1, M2 implements I1, I2 {}
- ''');
+''', []);
}
test_interfacesFromMixinsUsedTwiceAreChecked() {
// Regression test for https://github.com/dart-lang/sdk/issues/29782
- return checkFile(r'''
+ return assertErrorsInCode(r'''
abstract class I<E> {
set x(E v);
}
abstract class M<E> implements I<E> {}
class C extends Object with M<int> {
- String /*error:INVALID_OVERRIDE*/x;
+ String x;
}
abstract class D extends Object with M<num> {}
-/*error:CONFLICTING_GENERIC_INTERFACES*/
-/*error:CONFLICTING_GENERIC_INTERFACES*/class E extends D with M<int> {
- int /*error:INVALID_OVERRIDE*/x;
+
+class E extends D with M<int> {
+ int x;
}
-/*error:CONFLICTING_GENERIC_INTERFACES*/
-/*error:CONFLICTING_GENERIC_INTERFACES*/class F extends D with M<int> {
+
+class F extends D with M<int> {
num x;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 124, 1),
+ error(CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES, 180, 42),
+ error(CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES, 180, 42),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 218, 1),
+ error(CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES, 226, 42),
+ error(CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES, 226, 42),
+ ]);
}
test_invalidOverrides_baseClassOverrideToChildInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I {
- m(A a);
+ m(A a);
}
class Base {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Base implements I {}
-''');
+class T1 extends Base implements I {}
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 89, 2),
+ ]);
}
test_invalidOverrides_childOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -2554,151 +3300,192 @@
}
class T1 extends Base {
- B get /*error:INVALID_OVERRIDE, error:GETTER_NOT_ASSIGNABLE_SETTER_TYPES*/f => null;
+ B get f => null;
}
class T2 extends Base {
- set /*error:INVALID_OVERRIDE, error:GETTER_NOT_ASSIGNABLE_SETTER_TYPES*/f(
- B b) => null;
+ set f(B b) => null;
}
class T3 extends Base {
- final B
- /*error:FINAL_NOT_INITIALIZED, error:INVALID_OVERRIDE, error:GETTER_NOT_ASSIGNABLE_SETTER_TYPES*/f;
+ final B f;
}
class T4 extends Base {
// two: one for the getter one for the setter.
- B /*error:INVALID_OVERRIDE, error:INVALID_OVERRIDE*/f;
+ B f;
}
-class /*error:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER*/T5 implements Base {
- /**/B get /*error:INVALID_OVERRIDE, error:GETTER_NOT_ASSIGNABLE_SETTER_TYPES*/f => null;
+class T5 implements Base {
+ B get f => null;
}
-class /*error:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER*/T6 implements Base {
- set /*error:INVALID_OVERRIDE, error:GETTER_NOT_ASSIGNABLE_SETTER_TYPES*/f(B b) => null;
+class T6 implements Base {
+ set f(B b) => null;
}
-class /*error:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER*/T7 implements Base {
- final B /*error:INVALID_OVERRIDE, error:GETTER_NOT_ASSIGNABLE_SETTER_TYPES*/f = null;
+class T7 implements Base {
+ final B f = null;
}
class T8 implements Base {
// two: one for the getter one for the setter.
- B /*error:INVALID_OVERRIDE, error:INVALID_OVERRIDE*/f;
+ B f;
}
-''');
+''', [
+ error(CompileTimeErrorCode.GETTER_NOT_ASSIGNABLE_SETTER_TYPES, 80, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 80, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 124, 1),
+ error(CompileTimeErrorCode.GETTER_NOT_ASSIGNABLE_SETTER_TYPES, 124, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 177, 1),
+ error(CompileTimeErrorCode.GETTER_NOT_ASSIGNABLE_SETTER_TYPES, 177, 1),
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 177, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 259, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 259, 1),
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 271,
+ 2),
+ error(CompileTimeErrorCode.GETTER_NOT_ASSIGNABLE_SETTER_TYPES, 300, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 300, 1),
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 320,
+ 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 347, 1),
+ error(CompileTimeErrorCode.GETTER_NOT_ASSIGNABLE_SETTER_TYPES, 347, 1),
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 372,
+ 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 403, 1),
+ error(CompileTimeErrorCode.GETTER_NOT_ASSIGNABLE_SETTER_TYPES, 403, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 495, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 495, 1),
+ ]);
}
test_invalidOverrides_childOverride2() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
class Base {
- m(A a) {}
+ m(A a) {}
}
class Test extends Base {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 79, 1),
+ ]);
}
test_invalidOverrides_classOverrideOfInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I {
- m(A a);
+ m(A a);
}
class T1 implements I {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 81, 1),
+ ]);
}
test_invalidOverrides_doubleOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
class Grandparent {
- m(A a) {}
+ m(A a) {}
}
+
class Parent extends Grandparent {
- m(A a) {}
+ m(A a) {}
}
class Test extends Parent {
- // Reported only once
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ // Reported only once
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 162, 1),
+ ]);
}
test_invalidOverrides_doubleOverride2() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
class Grandparent {
- m(A a) {}
+ m(A a) {}
}
+
class Parent extends Grandparent {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
class Test extends Parent {
- m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 95, 1),
+ ]);
}
test_invalidOverrides_grandChildOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
class Grandparent {
- m(A a) {}
- int x;
+ m(A a) {}
+ int x;
}
+
class Parent extends Grandparent {
}
class Test extends Parent {
- /*error:INVALID_OVERRIDE*/m(B a) {}
- int x;
+ m(B a) {}
+ int x;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 135, 1),
+ ]);
}
test_invalidOverrides_mixinOverrideOfInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I {
- m(A a);
+ m(A a);
}
class M {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Object with M
- implements I {}
+class T1 extends Object with M implements I {}
-class /*error:INCONSISTENT_INHERITANCE*/U1 = Object
- with M implements I;
-''');
+class U1 = Object with M implements I;
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 86, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 134, 2),
+ ]);
}
test_invalidOverrides_mixinOverrideToBase() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -2715,18 +3502,25 @@
int x;
}
-class T1 extends Base with /*error:INVALID_OVERRIDE*/M1 {}
-class T2 extends Base with /*error:INVALID_OVERRIDE*/M1, M2 {}
-class T3 extends Base with M2, /*error:INVALID_OVERRIDE*/M1 {}
+class T1 extends Base with M1 {}
+class T2 extends Base with M1, M2 {}
+class T3 extends Base with M2, M1 {}
-class U1 = Base with /*error:INVALID_OVERRIDE*/M1;
-class U2 = Base with /*error:INVALID_OVERRIDE*/M1, M2;
-class U3 = Base with M2, /*error:INVALID_OVERRIDE*/M1;
-''');
+class U1 = Base with M1;
+class U2 = Base with M1, M2;
+class U3 = Base with M2, M1;
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 144, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 177, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 218, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 246, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 271, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 304, 2),
+ ]);
}
test_invalidOverrides_mixinOverrideToMixin() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -2743,10 +3537,13 @@
int x;
}
-class T1 extends Base with M1, /*error:INVALID_OVERRIDE*/M2 {}
+class T1 extends Base with M1, M2 {}
-class U1 = Base with M1, /*error:INVALID_OVERRIDE*/M2;
-''');
+class U1 = Base with M1, M2;
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 148, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 180, 2),
+ ]);
}
@failingTest
@@ -2754,38 +3551,36 @@
// This is a regression test for a bug in an earlier implementation were
// names were hiding errors if the first mixin override looked correct,
// but subsequent ones did not.
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
class Base {
- m(A a) {}
+ m(A a) {}
}
class M1 {
- m(A a) {}
+ m(A a) {}
}
class M2 {
- m(B a) {}
+ m(B a) {}
}
class M3 {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1 extends Base
- with M1, /*error:INVALID_OVERRIDE_FROM_MIXIN*/M2, M3 {}
+class T1 extends Base with M1, M2, M3 {}
-class /*error:INCONSISTENT_INHERITANCE*/U1 = Base
- with M1, /*error:INVALID_OVERRIDE_FROM_MIXIN*/M2, M3;
-''');
+class U1 = Base with M1, M2, M3;
+''', []);
}
test_invalidOverrides_noErrorsIfSubclassCorrectlyOverrideBaseAndInterface() async {
// This is a case were it is incorrect to say that the base class
// incorrectly overrides the interface.
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -2797,30 +3592,28 @@
void m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Base
- implements I1 {}
+class T1 extends Base implements I1 {}
class T2 extends Base implements I1 {
void m(dynamic a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T3
- extends Object with Base
- implements I1 {}
+class T3 extends Object with Base implements I1 {}
-class /*error:INCONSISTENT_INHERITANCE*/U3
- = Object with Base
- implements I1;
+class U3 = Object with Base implements I1;
class T4 extends Object with Base implements I1 {
void m(dynamic a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 93, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 197, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 249, 2),
+ ]);
}
test_invalidRuntimeChecks() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef int I2I(int x);
typedef int D2I(x);
typedef int II2I(int x, int y);
@@ -2856,25 +3649,32 @@
// For as, the validity of checks is deferred to runtime.
Function f;
- f = /*info:UNNECESSARY_CAST*/foo as I2I;
+ f = foo as I2I;
f = foo as D2I;
- f = /*info:UNNECESSARY_CAST*/foo as I2D;
+ f = foo as I2D;
f = foo as D2D;
- f = /*info:UNNECESSARY_CAST*/bar as II2I;
+ f = bar as II2I;
f = bar as DI2I;
f = bar as ID2I;
- f = /*info:UNNECESSARY_CAST*/bar as II2D;
+ f = bar as II2D;
f = bar as DD2I;
f = bar as DI2D;
f = bar as ID2D;
f = bar as DD2D;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 365, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 665, 1),
+ error(HintCode.UNNECESSARY_CAST, 674, 10),
+ error(HintCode.UNNECESSARY_CAST, 710, 10),
+ error(HintCode.UNNECESSARY_CAST, 747, 11),
+ error(HintCode.UNNECESSARY_CAST, 804, 11),
+ ]);
}
test_leastUpperBounds() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef T Returns<T>();
// regression test for https://github.com/dart-lang/sdk/issues/26094
@@ -2883,9 +3683,9 @@
S s;
T t;
if (b) {
- return /*error:RETURN_OF_INVALID_TYPE*/b ? s : t;
+ return b ? s : t;
} else {
- return /*error:RETURN_OF_INVALID_TYPE*/s ?? t;
+ return s ?? t;
}
}
}
@@ -2894,7 +3694,7 @@
T t;
S s;
int test(bool b) {
- return /*error:RETURN_OF_INVALID_TYPE*/b ? t : s;
+ return b ? t : s;
}
}
@@ -2905,7 +3705,7 @@
int test1(bool b) {
List<int> li;
List<double> ld;
- return /*error:RETURN_OF_INVALID_TYPE*/b ? li : ld;
+ return b ? li : ld;
}
// TODO(leafp): This case isn't handled yet. This test checks
// the case where two related classes are instantiated with related
@@ -2917,365 +3717,18 @@
return b ? li : id;
}
}
-''');
- }
-
- test_list_ifElement_dynamicCondition_disableImplicitCasts() async {
- addFile(r'''
-dynamic c;
-void main() {
- <int>[if (/*error:NON_BOOL_CONDITION*/c) 0];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_list_ifElement_dynamicCondition_implicitCasts() async {
- addFile(r'''
-dynamic c;
-void main() {
- <int>[if (c) 0];
-}
-''');
- await check();
- }
-
- test_list_ifElement_falseBranch_dynamic_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>[if (c) 0 else /*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/dyn];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_list_ifElement_falseBranch_dynamic_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>[if (c) 0 else dyn];
-}
-''');
- await check();
- }
-
- test_list_ifElement_falseBranch_supertype_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>[if (c) 0 else /*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/someNum];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_list_ifElement_falseBranch_supertype_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>[if (c) 0 else someNum];
-}
-''');
- await check();
- }
-
- test_list_ifElement_objectCondition_disableImplicitCasts() async {
- addFile(r'''
-Object c;
-void main() {
- <int>[if (/*error:NON_BOOL_CONDITION*/c) 0];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_list_ifElement_objectCondition_implicitCasts() async {
- addFile(r'''
-Object c;
-void main() {
- <int>[if (c) 0];
-}
-''');
- await check();
- }
-
- test_list_ifElement_trueBranch_dynamic_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>[if (c) /*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/dyn];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_list_ifElement_trueBranch_dynamic_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>[if (c) dyn];
-}
-''');
- await check();
- }
-
- test_list_ifElement_trueBranch_supertype_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>[if (c) /*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/someNum];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_list_ifElement_trueBranch_supertype_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>[if (c) someNum];
-}
-''');
- await check();
- }
-
- test_loadLibrary() async {
- addFile('''library lib1;''', name: '/lib1.dart');
- await checkFile(r'''
-import 'lib1.dart' deferred as lib1;
-import 'dart:async' show Future;
-main() {
- Future f = lib1.loadLibrary();
-}''');
- }
-
- test_map_ifElement_dynamicCondition_disableImplicitCasts() async {
- addFile(r'''
-dynamic c;
-void main() {
- <int, int>{if (/*error:NON_BOOL_CONDITION*/c) 0: 0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_dynamicCondition_implicitCasts() async {
- addFile(r'''
-dynamic c;
-void main() {
- <int, int>{if (c) 0: 0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_falseBranch_dynamicKey_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) 0:0 else /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/dyn:0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_falseBranch_dynamicKey_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) 0:0 else dyn:0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_falseBranch_dynamicValue_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) 0:0 else 0:/*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/dyn};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_falseBranch_dynamicValue_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) 0:0 else 0:dyn};
-}
-''');
- await check();
- }
-
- test_map_ifElement_falseBranch_supertypeKey_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) 0:0 else /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/someNum:0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_falseBranch_supertypeKey_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) 0:0 else someNum:0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_falseBranch_supertypeValue_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) 0:0 else 0:/*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/someNum};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_falseBranch_supertypeValue_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) 0:0 else 0:someNum};
-}
-''');
- await check();
- }
-
- test_map_ifElement_objectCondition_disableImplicitCasts() async {
- addFile(r'''
-Object c;
-void main() {
- <int, int>{if (/*error:NON_BOOL_CONDITION*/c) 0: 0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_objectCondition_implicitCasts() async {
- addFile(r'''
-Object c;
-void main() {
- <int, int>{if (c) 0: 0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_trueBranch_dynamicKey_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/dyn:0 else 0:0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_trueBranch_dynamicKey_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) dyn:0 else 0:0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_trueBranch_dynamicValue_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) 0:/*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/dyn else 0:0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_trueBranch_dynamicValue_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int, int>{if (c) 0:dyn else 0:0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_trueBranch_supertypeKey_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/someNum:0 else 0:0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_trueBranch_supertypeKey_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) someNum:0 else 0:0};
-}
-''');
- await check();
- }
-
- test_map_ifElement_trueBranch_supertypeValue_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) 0:/*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/someNum else 0:0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_map_ifElement_trueBranch_supertypeValue_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int, int>{if (c) 0:someNum else 0:0};
-}
-''');
- await check();
+''', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 214, 9),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 251, 6),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 344, 9),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 617, 11),
+ error(TodoCode.TODO, 639, 59),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 878, 1),
+ ]);
}
test_methodOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends B {}
@@ -3290,18 +3743,23 @@
}
class Child extends Base {
- A /*error:INVALID_OVERRIDE*/m1(A value) => null;
- C /*error:INVALID_OVERRIDE*/m2(C value) => null;
- A /*error:INVALID_OVERRIDE*/m3(C value) => null;
+ A m1(A value) => null;
+ C m2(C value) => null;
+ A m3(C value) => null;
C m4(A value) => null;
m5(value) => null;
- dynamic /*error:INVALID_OVERRIDE*/m6(dynamic value) => null;
+ dynamic m6(dynamic value) => null;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 227, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 252, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 277, 2),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 354, 2),
+ ]);
}
test_methodOverride_contravariant() async {
- await checkFile('''
+ await assertErrorsInCode('''
abstract class A {
bool operator ==(Object object);
}
@@ -3314,31 +3772,34 @@
}
class G extends F {
- void /*error:INVALID_OVERRIDE*/f(int x) {}
+ void f(int x) {}
void g(dynamic x) {}
}
class H implements F {
- void /*error:INVALID_OVERRIDE*/f(int x) {}
+ void f(int x) {}
void g(dynamic x) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 156, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 224, 1),
+ ]);
}
test_methodTearoffStrictArrow() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26393
- await checkFile(r'''
+ await assertErrorsInCode(r'''
class A {
void foo(dynamic x) {}
void test(void f(int x)) {
test(foo);
}
}
- ''');
+''', []);
}
test_mixinApplicationIsConcrete() {
- return checkFile(r'''
+ return assertErrorsInCode(r'''
class A {
int get foo => 3;
}
@@ -3349,209 +3810,218 @@
class C = Object with B;
-class /*error:INVALID_OVERRIDE*/D extends Object with C implements A {}
- ''');
+class D extends Object with C implements A {}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 100, 1),
+ ]);
}
test_mixinOverrideOfGrandInterface_interfaceOfAbstractSuperclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
+
abstract class Base implements I1 {}
class M {
- m(B a) {}
+ m(B a) {}
}
-class T1 extends Base with /*error:INVALID_OVERRIDE*/M {}
+class T1 extends Base with M {}
-class U1 = Base with /*error:INVALID_OVERRIDE*/M;
-''');
+class U1 = Base with M;
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 146, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 173, 1),
+ ]);
}
test_mixinOverrideOfGrandInterface_interfaceOfConcreteSuperclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
-class /*error:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER*/Base
- implements I1 {}
+class Base implements I1 {}
class M {
- m(B a) {}
+ m(B a) {}
}
-class T1 extends Base with /*error:INVALID_OVERRIDE*/M {}
+class T1 extends Base with M {}
-class U1 = Base with /*error:INVALID_OVERRIDE*/M;
-''');
+class U1 = Base with M;
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 62,
+ 4),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 137, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 164, 1),
+ ]);
}
test_mixinOverrideOfGrandInterface_interfaceOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
+
abstract class I2 implements I1 {}
class M {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Object with M
- implements I2 {}
+class T1 extends Object with M implements I2 {}
-class /*error:INCONSISTENT_INHERITANCE*/U1
- = Object with M
- implements I2;
-''');
+class U1 = Object with M implements I2;
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 123, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 172, 2),
+ ]);
}
test_mixinOverrideOfGrandInterface_mixinOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class M1 {
m(A a);
}
+
abstract class I2 extends Object with M1 {}
class M {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Object with M
- implements I2 {}
+class T1 extends Object with M implements I2 {}
-class /*error:INCONSISTENT_INHERITANCE*/U1
- = Object with M
- implements I2;
-''');
+class U1 = Object with M implements I2;
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 134, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 183, 2),
+ ]);
}
test_mixinOverrideOfGrandInterface_superclassOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
+
abstract class I2 extends I1 {}
class M {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Object with M
- implements I2 {}
+class T1 extends Object with M implements I2 {}
-class /*error:INCONSISTENT_INHERITANCE*/U1
- = Object with M
- implements I2;
-''');
+class U1 = Object with M implements I2;
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 120, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 169, 2),
+ ]);
}
test_noDuplicateReports_baseTypeAndMixinOverrideSameMethodInInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
class Base {
- m(B a) {}
+ m(B a) {}
}
class M {
- m(B a) {}
+ m(B a) {}
}
// TODO(jmesserly): the `INCONSISTENT_METHOD_INHERITANCE` message is from the
// Dart 1 checking logic (using strong mode type system), it is not produced
// by the strong mode OverrideChecker.
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Base
- with M
- implements I1 {}
+class T1 extends Base with M implements I1 {}
-class /*error:INCONSISTENT_INHERITANCE*/U1 =
- Base
- with M
- implements I1;
-''');
+class U1 = Base with M implements I1;
+''', [
+ error(TodoCode.TODO, 112, 74),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 309, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 356, 2),
+ ]);
}
test_noDuplicateReports_twoGrandTypesOverrideSameMethodInInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
class Grandparent {
- m(B a) {}
+ m(B a) {}
}
class Parent1 extends Grandparent {
- m(B a) {}
+ m(B a) {}
}
class Parent2 extends Grandparent {}
// Note: otherwise both errors would be reported on this line
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Parent1
- implements I1 {}
-class /*error:INCONSISTENT_INHERITANCE*/T2
- extends Parent2
- implements I1 {}
-''');
+class T1 extends Parent1 implements I1 {}
+class T2 extends Parent2 implements I1 {}
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 247, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 289, 2),
+ ]);
}
test_noDuplicateReports_twoMixinsOverrideSameMethodInInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
class M1 {
- m(B a) {}
+ m(B a) {}
}
class M2 {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1 extends Object
- with M1, M2
- implements I1 {}
-''');
+class T1 extends Object with M1, M2 implements I1 {}
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 114, 2),
+ ]);
}
test_noDuplicateReports_typeAndBaseTypeOverrideSameMethodInInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -3564,17 +4034,18 @@
}
class T1 extends Base implements I1 {
- void /*error:INVALID_OVERRIDE*/m(B a) {}
+ void m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T2
- extends Base
- implements I1 {}
-''');
+class T2 extends Base implements I1 {}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 139, 1),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 158, 2),
+ ]);
}
test_noDuplicateReports_typeAndMixinOverrideSameMethodInInterface() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -3587,41 +4058,44 @@
}
class T1 extends Object with M implements I1 {
- void /*error:INVALID_OVERRIDE*/m(B a) {}
+ void m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T2
- extends Object with M
- implements I1 {}
+class T2 extends Object with M implements I1 {}
-class /*error:INCONSISTENT_INHERITANCE*/U2
- = Object with M
- implements I1;
-''');
+class U2 = Object with M implements I1;
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 145, 1),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 164, 2),
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 213, 2),
+ ]);
}
test_noDuplicateReports_typeOverridesSomeMethodInMultipleInterfaces() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
+
abstract class I2 implements I1 {
- m(A a);
+ m(A a);
}
class Base {}
class T1 implements I2 {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 145, 1),
+ ]);
}
test_nullCoalescingOperator() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class C<T> {}
main() {
@@ -3634,11 +4108,11 @@
c ??= new C();
d = d ?? new C();
}
-''');
+''', []);
}
test_nullCoalescingStrictArrow() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
bool _alwaysTrue(x) => true;
typedef bool TakesA<T>(T t);
class C<T> {
@@ -3647,67 +4121,76 @@
: g = f ?? _alwaysTrue;
C.a() : g = _alwaysTrue;
}
- ''');
+''', []);
}
test_optionalParams() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26155
- await checkFile(r'''
+ await assertErrorsInCode(r'''
void takesF(void f(int x)) {
takesF(([x]) { bool z = x.isEven; });
takesF((y) { bool z = y.isEven; });
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 51, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 1),
+ ]);
}
test_overrideNarrowsType() async {
- addFile(r'''
+ await assertErrorsInCode(r'''
class A {}
class B extends A {}
abstract class C {
- m(A a);
- n(B b);
+ void m(A a);
+ void n(B b);
}
+
abstract class D extends C {
- /*error:INVALID_OVERRIDE*/m(B b);
- n(A a);
+ void m(B b);
+ void n(A a);
}
- ''');
- await check(implicitCasts: false);
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 121, 1),
+ ]);
}
test_overrideNarrowsType_legalWithChecked() async {
// Regression test for https://github.com/dart-lang/sdk/issues/25232
- await checkFile(r'''
+ await assertErrorsInCode(r'''
abstract class A { void test(A arg) { } }
abstract class B extends A { void test(covariant B arg) { } }
abstract class X implements A { }
class C extends B with X { }
class D extends B implements A { }
- ''');
+''', []);
}
test_overrideNarrowsType_noDuplicateError() {
// Regression test for https://github.com/dart-lang/sdk/issues/25232
- return checkFile(r'''
+ return assertErrorsInCode(r'''
abstract class A { void test(A arg) { } }
abstract class B extends A {
- void /*error:INVALID_OVERRIDE*/test(B arg) { }
+ void test(B arg) { }
}
abstract class X implements A { }
class C extends B {}
-class /*error:INVALID_OVERRIDE*/D extends B with X { }
+class D extends B with X { }
-class /*error:INVALID_OVERRIDE*/E extends B implements A { }
- ''');
+class E extends B implements A { }
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 78, 4),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 159, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 189, 1),
+ ]);
}
test_privateOverride() async {
- addFile('''
-import 'main.dart' as main;
+ newFile('$testPackageLibPath/helper.dart', content: r'''
+import 'test.dart' as main;
class Base {
var f1;
@@ -3723,10 +4206,11 @@
var _f3;
var _f4;
- String /*error:INVALID_OVERRIDE*/_m1() => null;
+ String _m1() => null;
}
-''', name: '/helper.dart');
- await checkFile('''
+''');
+
+ await assertErrorsInCode('''
import 'helper.dart' as helper;
class Child extends helper.Base {
@@ -3736,11 +4220,15 @@
String _m1() => null;
}
-''');
+''', [
+ error(HintCode.UNUSED_FIELD, 83, 3),
+ error(HintCode.UNUSED_FIELD, 94, 3),
+ error(HintCode.UNUSED_ELEMENT, 109, 3),
+ ]);
}
test_proxy() {
- return checkFile(r'''
+ return assertErrorsInCode(r'''
@proxy class C {}
@proxy class D {
var f;
@@ -3750,8 +4238,8 @@
operator [](int index) => null;
call() => null;
}
-@proxy class F implements Function { noSuchMethod(i) => 42; }
+@proxy class F implements Function { noSuchMethod(i) => 42; }
m() {
D d = new D();
@@ -3764,30 +4252,40 @@
d();
C c = new C();
- c./*error:UNDEFINED_METHOD*/m();
- c./*error:UNDEFINED_GETTER*/m;
- /*error:UNDEFINED_OPERATOR*/-c;
- c /*error:UNDEFINED_OPERATOR*/+ 7;
- c /*error:UNDEFINED_OPERATOR*/[7];
- /*error:INVOCATION_OF_NON_FUNCTION_EXPRESSION*/c();
+ c.m();
+ c.m;
+ -c;
+ c + 7;
+ c[7];
+ c();
F f = new F();
- /*error:INVOCATION_OF_NON_FUNCTION_EXPRESSION*/f();
+ f();
}
- ''');
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 332, 1),
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 341, 1),
+ error(CompileTimeErrorCode.UNDEFINED_OPERATOR, 346, 1),
+ error(CompileTimeErrorCode.UNDEFINED_OPERATOR, 354, 1),
+ error(CompileTimeErrorCode.UNDEFINED_OPERATOR, 362, 3),
+ error(CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 369, 1),
+ error(CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 394, 1),
+ ]);
}
test_redirectingConstructor() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {
A(A x) {}
- A.two() : this(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
+ A.two() : this(3);
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 39, 1),
+ ]);
}
test_relaxedCasts() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class L<T> {}
@@ -3829,8 +4327,8 @@
lOfOs = new L<Object>(); // Reset type propagation.
}
{
- lOfAs = /*error:INVALID_ASSIGNMENT*/mOfDs;
- lOfAs = /*error:INVALID_ASSIGNMENT*/mOfOs;
+ lOfAs = mOfDs;
+ lOfAs = mOfOs;
lOfAs = mOfAs;
lOfAs = lOfDs;
lOfAs = lOfOs;
@@ -3843,7 +4341,7 @@
mOfDs = mOfAs;
mOfDs = lOfDs;
mOfDs = lOfOs;
- mOfDs = /*error:INVALID_ASSIGNMENT*/lOfAs;
+ mOfDs = lOfAs;
mOfDs = new M(); // Reset type propagation.
}
{
@@ -3852,7 +4350,7 @@
mOfOs = mOfAs;
mOfOs = lOfDs;
mOfOs = lOfOs;
- mOfOs = /*error:INVALID_ASSIGNMENT*/lOfAs;
+ mOfOs = lOfAs;
mOfOs = new M<Object>(); // Reset type propagation.
}
{
@@ -3864,139 +4362,16 @@
mOfAs = lOfAs;
}
}
-''');
- }
-
- test_set_ifElement_dynamicCondition_disableImplicitCasts() async {
- addFile(r'''
-dynamic c;
-void main() {
- <int>{if (/*error:NON_BOOL_CONDITION*/c) 0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_set_ifElement_dynamicCondition_implicitCasts() async {
- addFile(r'''
-dynamic c;
-void main() {
- <int>{if (c) 0};
-}
-''');
- await check();
- }
-
- test_set_ifElement_falseBranch_dynamic_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>{if (c) 0 else /*error:SET_ELEMENT_TYPE_NOT_ASSIGNABLE*/dyn};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_set_ifElement_falseBranch_dynamic_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>{if (c) 0 else dyn};
-}
-''');
- await check();
- }
-
- test_set_ifElement_falseBranch_supertype_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>{if (c) 0 else /*error:SET_ELEMENT_TYPE_NOT_ASSIGNABLE*/someNum};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_set_ifElement_falseBranch_supertype_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>{if (c) 0 else someNum};
-}
-''');
- await check();
- }
-
- test_set_ifElement_objectCondition_disableImplicitCasts() async {
- addFile(r'''
-Object c;
-void main() {
- <int>{if (/*error:NON_BOOL_CONDITION*/c) 0};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_set_ifElement_objectCondition_implicitCasts() async {
- addFile(r'''
-Object c;
-void main() {
- <int>{if (c) 0};
-}
-''');
- await check();
- }
-
- test_set_ifElement_trueBranch_dynamic_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>{if (c) /*error:SET_ELEMENT_TYPE_NOT_ASSIGNABLE*/dyn};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_set_ifElement_trueBranch_dynamic_implicitCasts() async {
- addFile(r'''
-bool c;
-dynamic dyn;
-void main() {
- <int>[if (c) dyn];
-}
-''');
- await check();
- }
-
- test_set_ifElement_trueBranch_supertype_disableImplicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>{if (c) /*error:SET_ELEMENT_TYPE_NOT_ASSIGNABLE*/someNum};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_set_ifElement_trueBranch_supertype_implicitCasts() async {
- addFile(r'''
-bool c;
-num someNum;
-void main() {
- <int>{if (c) someNum};
-}
-''');
- await check();
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 764, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 783, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1032, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1202, 5),
+ ]);
}
test_setterOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
typedef void ToVoid<T>(T x);
class F {
void set f(ToVoid<dynamic> x) {}
@@ -4007,40 +4382,52 @@
class G extends F {
void set f(ToVoid<int> x) {}
- void set /*error:INVALID_OVERRIDE*/g(ToVoid<dynamic> x) {}
- void set /*error:INVALID_OVERRIDE*/h(int x) {}
+ void set g(ToVoid<dynamic> x) {}
+ void set h(int x) {}
void set i(dynamic x) {}
}
class H implements F {
void set f(ToVoid<int> x) {}
- void set /*error:INVALID_OVERRIDE*/g(ToVoid<dynamic> x) {}
- void set /*error:INVALID_OVERRIDE*/h(int x) {}
+ void set g(ToVoid<dynamic> x) {}
+ void set h(int x) {}
void set i(dynamic x) {}
}
- ''');
+ ''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 220, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 255, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 362, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 397, 1),
+ ]);
}
test_setterReturnTypes() async {
- await checkFile('''
+ await assertErrorsInCode('''
void voidFn() => null;
class A {
set a(y) => 4;
set b(y) => voidFn();
void set c(y) => 4;
void set d(y) => voidFn();
- /*error:NON_VOID_RETURN_FOR_SETTER*/int set e(y) => 4;
- /*error:NON_VOID_RETURN_FOR_SETTER*/int set f(y) =>
- /*error:RETURN_OF_INVALID_TYPE*/voidFn();
- set g(y) {return /*error:RETURN_OF_INVALID_TYPE*/4;}
- void set h(y) {return /*error:RETURN_OF_INVALID_TYPE*/4;}
- /*error:NON_VOID_RETURN_FOR_SETTER*/int set i(y) {return 4;}
+ int set e(y) => 4;
+ int set f(y) =>
+ voidFn();
+ set g(y) {return 4;}
+ void set h(y) {return 4;}
+ int set i(y) {return 4;}
}
-''');
+''', [
+ error(CompileTimeErrorCode.NON_VOID_RETURN_FOR_SETTER, 127, 3),
+ error(CompileTimeErrorCode.NON_VOID_RETURN_FOR_SETTER, 148, 3),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 168, 8),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 197, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 225, 1),
+ error(CompileTimeErrorCode.NON_VOID_RETURN_FOR_SETTER, 231, 3),
+ ]);
}
test_setterSetterOverride() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends B {}
@@ -4055,186 +4442,58 @@
class Child extends Base {
void set f1(A value) {}
- void set /*error:INVALID_OVERRIDE*/f2(C value) {}
+ void set f2(C value) {}
void set f3(value) {}
void set f4(dynamic value) {}
set f5(B value) {}
}
-''');
- }
-
- @failingTest
- test_spread_dynamicInList_disableImplicitCasts() async {
- // TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
- addFile(r'''
-dynamic dyn;
-void main() {
- [.../*error:INVALID_ASSIGNMENT*/dyn];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_dynamicInList_implicitCasts() async {
- addFile(r'''
-dynamic dyn;
-void main() {
- [...dyn];
-}
-''');
- await check();
- }
-
- @failingTest
- test_spread_dynamicInMap_disableImplicitCasts() async {
- // TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
- addFile(r'''
-dynamic dyn;
-void main() {
- <dynamic, dynamic>{.../*error:INVALID_ASSIGNMENT*/dyn};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_dynamicInMap_implicitCasts() async {
- addFile(r'''
-dynamic dyn;
-void main() {
- <dynamic, dynamic>{...dyn};
-}
-''');
- await check();
- }
-
- @failingTest
- test_spread_dynamicInSet_disableImplicitCasts() async {
- // TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
- addFile(r'''
-dynamic dyn;
-void main() {
- <dynamic>{.../*error:INVALID_ASSIGNMENT*/dyn};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_dynamicInSet_implicitCasts() async {
- addFile(r'''
-dynamic dyn;
-void main() {
- <dynamic>{...dyn};
-}
-''');
- await check();
- }
-
- test_spread_listElement_disableImplicitCasts() async {
- addFile(r'''
-Iterable<num> i;
-void main() {
- <int>[.../*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/i];
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_listElement_implicitCasts() async {
- addFile(r'''
-Iterable<num> i;
-void main() {
- <int>[...i];
-}
-''');
- await check();
- }
-
- test_spread_mapKey_disableImplicitCasts() async {
- addFile(r'''
-Map<num, dynamic> map;
-void main() {
- <int, dynamic>{1: 2, .../*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/map};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_mapKey_implicitCasts() async {
- addFile(r'''
-Map<num, dynamic> map;
-void main() {
- <int, dynamic>{1: 2, ...map};
-}
-''');
- await check();
- }
-
- test_spread_mapValue_disableImplicitCasts() async {
- addFile(r'''
-Map<dynamic, num> map;
-void main() {
- <dynamic, int>{1: 2, .../*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/map};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_mapValue_implicitCasts() async {
- addFile(r'''
-Map<dynamic, num> map;
-void main() {
- <dynamic, int>{1: 2, ...map};
-}
-''');
- await check();
- }
-
- test_spread_setElement_disableImplicitCasts() async {
- addFile(r'''
-Iterable<num> i;
-void main() {
- <int>{.../*error:SET_ELEMENT_TYPE_NOT_ASSIGNABLE*/i};
-}
-''');
- await check(implicitCasts: false);
- }
-
- test_spread_setElement_implicitCasts() async {
- addFile(r'''
-Iterable<num> i;
-void main() {
- <int>{...i};
-}
-''');
- await check();
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 263, 2),
+ ]);
}
test_strictInference_instanceCreation() async {
- addFile(r'''
+ writeTestPackageAnalysisOptionsFile(
+ AnalysisOptionsFileConfig(
+ strictInference: true,
+ ),
+ );
+
+ await assertErrorsInCode(r'''
class C<T> {
C([T t]);
C.of(T t);
factory C.from(Object e) => C();
}
-main() {
+void f() {
// These should be allowed:
C<int> downwardsInferenceIsOK = C();
C<dynamic> downwardsInferenceDynamicIsOK = C();
var inferredFromConstructorParameterIsOK = C(42);
var explicitDynamicIsOK = C<dynamic>(42);
- var rawConstructorCall = /*info:INFERENCE_FAILURE_ON_INSTANCE_CREATION*/C();
- var factoryConstructor = /*info:INFERENCE_FAILURE_ON_INSTANCE_CREATION*/C.from(42);
+ var rawConstructorCall = C();
+ var factoryConstructor = C.from(42);
var upwardsInfersDynamic = C(42 as dynamic);
var namedConstructor = C.of(42 as dynamic);
}
- ''');
- await check(strictInference: true);
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 126, 22),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 169, 29),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 212, 36),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 264, 19),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 309, 18),
+ error(HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION, 330, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 341, 18),
+ error(HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION, 362, 6),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 380, 20),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 427, 16),
+ ]);
}
test_superCallPlacement() async {
- await checkFile('''
+ await assertErrorsInCode('''
class Base {
var x;
Base() : x = print('Base.1') { print('Base.2'); }
@@ -4244,7 +4503,7 @@
var y, z;
Derived()
: y = print('Derived.1'),
- /*error:INVALID_SUPER_INVOCATION*/super(),
+ super(),
z = print('Derived.2') {
print('Derived.3');
}
@@ -4265,11 +4524,13 @@
}
main() => new Derived();
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 170, 7),
+ ]);
}
test_superclassOverrideOfGrandInterface_interfaceOfAbstractSuperclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
@@ -4278,104 +4539,114 @@
}
abstract class Base implements I1 {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
class T1 extends Base {
m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 96, 1),
+ ]);
}
test_superclassOverrideOfGrandInterface_interfaceOfConcreteSuperclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
class Base implements I1 {
- /*error:INVALID_OVERRIDE*/m(B a) {}
+ m(B a) {}
}
class T1 extends Base {
- m(B a) {}
+ m(B a) {}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 85, 1),
+ ]);
}
test_superclassOverrideOfGrandInterface_interfaceOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
+
abstract class I2 implements I1 {}
class Base {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Base implements I2 {}
-''');
+class T1 extends Base implements I2 {}
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 126, 2),
+ ]);
}
test_superclassOverrideOfGrandInterface_mixinOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class M1 {
- m(A a);
+ m(A a);
}
+
abstract class I2 extends Object with M1 {}
class Base {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Base
- implements I2 {}
-''');
+class T1 extends Base implements I2 {}
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 135, 2),
+ ]);
}
test_superclassOverrideOfGrandInterface_superclassOfInterfaceOfChild() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B {}
abstract class I1 {
- m(A a);
+ m(A a);
}
+
abstract class I2 extends I1 {}
class Base {
- m(B a) {}
+ m(B a) {}
}
-class /*error:INCONSISTENT_INHERITANCE*/T1
- extends Base
- implements I2 {}
-''');
+class T1 extends Base implements I2 {}
+''', [
+ error(CompileTimeErrorCode.INCONSISTENT_INHERITANCE, 123, 2),
+ ]);
}
test_superConstructor() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A { A(A x) {} }
class B extends A {
- B() : super(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
+ B() : super(3);
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 56, 1),
+ ]);
}
test_tearOffTreatedConsistentlyAsStrictArrow() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
void foo(void f(String x)) {}
class A {
@@ -4398,11 +4669,11 @@
foo(baz2);
foo(baz3);
}
- ''');
+''', []);
}
test_tearOffTreatedConsistentlyAsStrictArrowNamedParam() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
typedef void Handler(String x);
void foo({Handler f}) {}
@@ -4426,15 +4697,16 @@
foo(f: baz2);
foo(f: baz3);
}
- ''');
+''', []);
}
test_ternaryOperator() async {
- await checkFile('''
+ await assertErrorsInCode('''
abstract class Comparable<T> {
int compareTo(T other);
static int compare(Comparable a, Comparable b) => a.compareTo(b);
}
+
typedef int Comparator<T>(T a, T b);
typedef bool _Predicate<T>(T value);
@@ -4465,30 +4737,35 @@
? v : ((_) => true);
}
}
+
void main() {
Object obj = 42;
dynamic dyn = 42;
int i = 42;
// Check the boolean conversion of the condition.
- print(/*error:NON_BOOL_CONDITION*/i ? false : true);
+ print(i ? false : true);
print((obj) ? false : true);
print((dyn) ? false : true);
}
-''');
+''', [
+ error(HintCode.UNUSED_FIELD, 247, 11),
+ error(HintCode.UNUSED_FIELD, 273, 9),
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 1311, 1),
+ ]);
}
test_typeCheckingLiterals() async {
- await checkFile('''
+ await assertErrorsInCode('''
test() {
num n = 3;
int i = 3;
String s = "hello";
{
List<int> l = <int>[i];
- l = <int>[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/s];
+ l = <int>[s];
l = <int>[n];
- l = <int>[i, n, /*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/s];
+ l = <int>[i, n, s];
}
{
List l = [i];
@@ -4498,11 +4775,9 @@
}
{
Map<String, int> m = <String, int>{s: i};
- m = <String, int>{s: /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/s};
+ m = <String, int>{s: s};
m = <String, int>{s: n};
- m = <String, int>{s: i,
- s: n,
- s: /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/s};
+ m = <String, int>{s: i, s: n, s: s};
}
// TODO(leafp): We can't currently test for key errors since the
// error marker binds to the entire entry.
@@ -4510,47 +4785,60 @@
Map m = {s: i};
m = {s: s};
m = {s: n};
- m = {s: i,
- s: n,
- s: s};
- m = {i: s,
- n: s,
- s: s};
+ m = {s: i, s: n, s: s};
+ m = {i: s, n: s, s: s};
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 76, 1),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 105, 1),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 149, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 171, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 258, 1),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 309, 1),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 381, 1),
+ error(TodoCode.TODO, 393, 61),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 512, 1),
+ ]);
}
test_typePromotionFromDynamic() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
f() {
dynamic x;
if (x is int) {
int y = x;
- String z = /*error:INVALID_ASSIGNMENT*/x;
+ String z = x;
}
}
g() {
Object x;
if (x is int) {
int y = x;
- String z = /*error:INVALID_ASSIGNMENT*/x;
+ String z = x;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 45, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 63, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 67, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 120, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 138, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 142, 1),
+ ]);
}
test_typePromotionFromTypeParameter() async {
// Regression test for:
// https://github.com/dart-lang/sdk/issues/26965
// https://github.com/dart-lang/sdk/issues/27040
- await checkFile(r'''
+ await assertErrorsInCode(r'''
void f<T>(T object) {
if (object is String) print(object.substring(1));
}
void g<T extends num>(T object) {
if (object is int) print(object.isEven);
- if (object is String) print(object./*error:UNDEFINED_METHOD*/substring(1));
+ if (object is String) print(object.substring(1));
}
class Cloneable<T> {}
class SubCloneable<T> extends Cloneable<T> {
@@ -4570,36 +4858,45 @@
// h(object);
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 190, 9),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 470, 1),
+ ]);
}
test_typePromotionFromTypeParameterAndInference() async {
// Regression test for:
// https://github.com/dart-lang/sdk/issues/27040
- await checkFile(r'''
+ await assertErrorsInCode(r'''
void f<T extends num>(T x, T y) {
var z = x;
var f = () => x;
f = () => y;
if (x is int) {
- z./*error:UNDEFINED_GETTER*/isEven;
+ z.isEven;
var q = x;
q = z;
- f()./*error:UNDEFINED_GETTER*/isEven;
+ f().isEven;
// This captures the type `T extends int`.
var g = () => x;
g = f;
- g()./*error:UNDEFINED_GETTER*/isEven;
+ g().isEven;
q = g();
int r = x;
}
}
- ''');
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 105, 6),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 121, 1),
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 147, 6),
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 243, 6),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 272, 1),
+ ]);
}
test_typeSubtyping_assigningClass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -4613,17 +4910,27 @@
B b;
y = a;
o = a;
- i = /*error:INVALID_ASSIGNMENT*/a;
- d = /*error:INVALID_ASSIGNMENT*/a;
- n = /*error:INVALID_ASSIGNMENT*/a;
+ i = a;
+ d = a;
+ n = a;
a = a;
b = a;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 71, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 81, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 98, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 114, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 130, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 160, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 170, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 180, 1),
+ ]);
}
test_typeSubtyping_assigningSubclass() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends A {}
@@ -4639,18 +4946,30 @@
C c;
y = b;
o = b;
- i = /*error:INVALID_ASSIGNMENT*/b;
- d = /*error:INVALID_ASSIGNMENT*/b;
- n = /*error:INVALID_ASSIGNMENT*/b;
+ i = b;
+ d = b;
+ n = b;
a = b;
b = b;
- c = /*error:INVALID_ASSIGNMENT*/b;
+ c = b;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 79, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 92, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 102, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 119, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 135, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 143, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 159, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 189, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 199, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 209, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 239, 1),
+ ]);
}
test_typeSubtyping_dynamicDowncasts() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -4669,11 +4988,18 @@
a = y;
b = y;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 71, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 81, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 98, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 114, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 122, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 130, 1),
+ ]);
}
test_typeSubtyping_dynamicIsTop() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
@@ -4692,11 +5018,13 @@
y = a;
y = b;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 1),
+ ]);
}
test_typeSubtyping_interfaces() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {}
class B extends A {}
class C extends A {}
@@ -4716,12 +5044,12 @@
{
left = top;
left = left;
- left = /*error:INVALID_ASSIGNMENT*/right;
+ left = right;
left = bot;
}
{
right = top;
- right = /*error:INVALID_ASSIGNMENT*/left;
+ right = left;
right = right;
right = bot;
}
@@ -4732,11 +5060,14 @@
bot = bot;
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 274, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 339, 4),
+ ]);
}
test_unaryOperators() async {
- await checkFile('''
+ await assertErrorsInCode('''
class A {
A operator ~() => null;
A operator +(int x) => null;
@@ -4757,7 +5088,7 @@
~a;
(~d);
- !/*error:NON_BOOL_NEGATION_EXPRESSION*/a;
+ !a;
!d;
-a;
@@ -4783,43 +5114,57 @@
takesC(--b);
takesC(b++);
takesC(b--);
-}''');
+}
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 201, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 237, 1),
+ error(CompileTimeErrorCode.NON_BOOL_NEGATION_EXPRESSION, 280, 1),
+ ]);
}
test_unboundRedirectingConstructor() async {
// This is a regression test for https://github.com/dart-lang/sdk/issues/25071
- await checkFile('''
+ await assertErrorsInCode('''
class Foo {
- Foo() : /*error:REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR*/this.init();
+ Foo() : this.init();
}
- ''');
+ ''', [
+ error(CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, 22,
+ 11),
+ ]);
}
test_unboundTypeName() async {
- await checkFile('''
+ await assertErrorsInCode('''
void main() {
- /*error:UNDEFINED_CLASS*/AToB y;
+ AToB y;
}
-''');
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_CLASS, 16, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 21, 1),
+ ]);
}
test_unboundVariable() async {
- await checkFile('''
+ await assertErrorsInCode('''
void main() {
- dynamic y = /*error:UNDEFINED_IDENTIFIER*/unboundVariable;
+ dynamic y = unboundVariable;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 25, 1),
+ error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 29, 15),
+ ]);
}
test_universalFunctionSubtyping() async {
- await checkFile(r'''
+ await assertErrorsInCode(r'''
dynamic foo<T>(dynamic x) => x;
void takesDtoD(dynamic f(dynamic x)) {}
void test() {
// here we currently infer an instantiation.
- takesDtoD(/*pass should be error:INVALID_ASSIGNMENT*/foo);
+ takesDtoD(foo);
}
class A {
@@ -4827,19 +5172,53 @@
}
class B extends A {
- T /*error:INVALID_OVERRIDE*/method<T>(T x) => x;
+ T method<T>(T x) => x;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 227, 6),
+ ]);
}
test_voidSubtyping() async {
// Regression test for https://github.com/dart-lang/sdk/issues/25069
- await checkFile('''
+ await assertErrorsInCode('''
typedef int Foo();
void foo() {}
void main () {
- Foo x = /*error:USE_OF_VOID_RESULT*/foo();
+ Foo x = foo();
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 54, 1),
+ error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 58, 3),
+ ]);
+ }
+
+ Future<void> _assertImplicitCasts(
+ String code,
+ List<ExpectedError> expectedErrorsWhenImplicitCastsDisabled,
+ ) async {
+ newFile(testFilePath, content: code);
+
+ await resolveTestFile();
+ assertNoErrorsInResult();
+
+ disposeAnalysisContextCollection();
+
+ writeTestPackageAnalysisOptionsFile(
+ AnalysisOptionsFileConfig(
+ implicitCasts: false,
+ ),
+ );
+
+ await resolveTestFile();
+ assertErrorsInResult(expectedErrorsWhenImplicitCastsDisabled);
+ }
+
+ void _disableTestPackageImplicitDynamic() {
+ writeTestPackageAnalysisOptionsFile(
+ AnalysisOptionsFileConfig(
+ implicitDynamic: false,
+ ),
+ );
}
}
diff --git a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
index 0ec1da6..43f38c7 100644
--- a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
+++ b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
@@ -7,11 +7,12 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
+import 'package:analyzer/src/error/codes.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../../utils.dart';
-import 'strong_test_helper.dart';
+import '../../dart/resolution/context_collection_resolution.dart';
void main() {
defineReflectiveSuite(() {
@@ -20,61 +21,60 @@
}
@reflectiveTest
-class InferredTypeTest extends AbstractStrongTest {
- /// Add the file, process it (resolve, validate, etc) and return the resolved
- /// unit element.
- Future<CompilationUnitElement> checkFileElement(String content) async {
- CompilationUnit unit = await checkFile(content);
- return unit.declaredElement;
+class InferredTypeTest extends PubPackageResolutionTest {
+ CompilationUnit get _resultUnit => result.unit;
+
+ CompilationUnitElement get _resultUnitElement {
+ return result.unit.declaredElement;
}
test_asyncClosureReturnType_flatten() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
import 'dart:async';
Future<int> futureInt = null;
var f = () => futureInt;
var g = () async => futureInt;
''');
- var futureInt = mainUnit.topLevelVariables[0];
+ var futureInt = _resultUnitElement.topLevelVariables[0];
expect(futureInt.name, 'futureInt');
_assertTypeStr(futureInt.type, 'Future<int>');
- var f = mainUnit.topLevelVariables[1];
+ var f = _resultUnitElement.topLevelVariables[1];
expect(f.name, 'f');
_assertTypeStr(f.type, 'Future<int> Function()');
- var g = mainUnit.topLevelVariables[2];
+ var g = _resultUnitElement.topLevelVariables[2];
expect(g.name, 'g');
_assertTypeStr(g.type, 'Future<int> Function()');
}
test_asyncClosureReturnType_future() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
var f = () async => 0;
''');
- var f = mainUnit.topLevelVariables[0];
+ var f = _resultUnitElement.topLevelVariables[0];
expect(f.name, 'f');
_assertTypeStr(f.type, 'Future<int> Function()');
}
test_asyncClosureReturnType_futureOr() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
import 'dart:async';
FutureOr<int> futureOrInt = null;
var f = () => futureOrInt;
var g = () async => futureOrInt;
''');
- var futureOrInt = mainUnit.topLevelVariables[0];
+ var futureOrInt = _resultUnitElement.topLevelVariables[0];
expect(futureOrInt.name, 'futureOrInt');
_assertTypeStr(futureOrInt.type, 'FutureOr<int>');
- var f = mainUnit.topLevelVariables[1];
+ var f = _resultUnitElement.topLevelVariables[1];
expect(f.name, 'f');
_assertTypeStr(f.type, 'FutureOr<int> Function()');
- var g = mainUnit.topLevelVariables[2];
+ var g = _resultUnitElement.topLevelVariables[2];
expect(g.name, 'g');
_assertTypeStr(g.type, 'Future<int> Function()');
}
test_blockBodiedLambdas_async_allReturnsAreFutures() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
import 'dart:math' show Random;
main() {
@@ -88,13 +88,17 @@
Future<num> g = f();
Future<int> h = f();
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 239, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 262, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Future<num> Function()');
}
test_blockBodiedLambdas_async_allReturnsAreValues() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
import 'dart:math' show Random;
main() {
@@ -108,13 +112,17 @@
Future<num> g = f();
Future<int> h = f();
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 190, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 213, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Future<num> Function()');
}
test_blockBodiedLambdas_async_mixOfValuesAndFutures() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
import 'dart:math' show Random;
main() {
@@ -128,13 +136,17 @@
Future<num> g = f();
Future<int> h = f();
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 213, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 236, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Future<num> Function()');
}
test_blockBodiedLambdas_asyncStar() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
main() {
var f = () async* {
@@ -145,44 +157,54 @@
Stream<num> g = f();
Stream<int> h = f();
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 120, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 143, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Stream<num> Function()');
}
test_blockBodiedLambdas_basic() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
test1() {
List<int> o;
var y = o.map((x) { return x + 1; });
Iterable<int> z = y;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 81, 1),
+ ]);
}
test_blockBodiedLambdas_downwardsIncompatibleWithUpwardsInference() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
main() {
String f() => null;
var g = f;
- g = () { return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/1; };
+ g = () { return 1; };
}
-''');
- var g = findLocalVariable(unit, 'g');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 37, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 62, 1),
+ ]);
+
+ var g = findLocalVariable(_resultUnit, 'g');
_assertTypeStr(g.type, 'String Function()');
}
test_blockBodiedLambdas_downwardsIncompatibleWithUpwardsInference_topLevel() async {
- var unit = await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
String f() => null;
var g = f;
''');
- var g = unit.topLevelVariables[0];
+ var g = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(g.type, 'String Function()');
}
test_blockBodiedLambdas_inferBottom_async() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
main() async {
var f = () async { return null; };
@@ -190,13 +212,18 @@
Future<String> z = f();
String s = await f();
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 82, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 108, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 126, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Future<Null> Function()');
}
test_blockBodiedLambdas_inferBottom_asyncStar() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
main() async {
var f = () async* { yield null; };
@@ -204,13 +231,18 @@
Stream<String> z = f();
String s = await f().first;
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 82, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 108, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 126, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Stream<Null> Function()');
}
test_blockBodiedLambdas_inferBottom_sync() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
var h = null;
void foo(int g(Object _)) {}
@@ -218,32 +250,40 @@
var f = (Object x) { return null; };
String y = f(42);
- f = (x) => /*error:INVALID_CAST_LITERAL*/'hello';
+ f = (x) => 'hello';
foo((x) { return null; });
foo((x) { throw "not implemented"; });
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 101, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL, 126, 7),
+ ]);
- var f = findLocalVariable(unit, 'f');
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Null Function(Object)');
}
test_blockBodiedLambdas_inferBottom_syncStar() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
main() {
var f = () sync* { yield null; };
Iterable y = f();
Iterable<String> z = f();
String s = f().first;
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 56, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 84, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 102, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Iterable<Null> Function()');
}
test_blockBodiedLambdas_LUB() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:math' show Random;
test2() {
List<num> o;
@@ -257,36 +297,45 @@
Iterable<num> w = y;
Iterable<int> z = y;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 210, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 233, 1),
+ ]);
}
test_blockBodiedLambdas_nestedLambdas() async {
// Original feature request: https://github.com/dart-lang/sdk/issues/25487
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
main() {
var f = () {
return (int x) { return 2.0 * x; };
};
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'double Function(int) Function()');
}
test_blockBodiedLambdas_noReturn() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
test1() {
List<int> o;
var y = o.map((x) { });
Iterable<int> z = y;
}
-''');
- var y = findLocalVariable(unit, 'y');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 67, 1),
+ ]);
+
+ var y = findLocalVariable(_resultUnit, 'y');
_assertTypeStr(y.type, 'Iterable<Null>');
}
test_blockBodiedLambdas_syncStar() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
main() {
var f = () sync* {
yield 1;
@@ -295,8 +344,12 @@
Iterable<num> g = f();
Iterable<int> h = f();
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 85, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Iterable<num> Function()');
}
@@ -304,10 +357,10 @@
// When a type is inferred from the expression `null`, the inferred type is
// `dynamic`, but the inferred type of the initializer is `bottom`.
// TODO(paulberry): Is this intentional/desirable?
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
var v = null;
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'dynamic');
_assertTypeStr(v.initializer.type, 'Null Function()');
}
@@ -315,21 +368,25 @@
test_bottom_inClosure() async {
// When a closure's return type is inferred from the expression `null`, the
// inferred type is `dynamic`.
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
var v = () => null;
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'Null Function()');
_assertTypeStr(v.initializer.type, 'Null Function() Function()');
}
test_circularReference_viaClosures() async {
- var mainUnit = await checkFileElement('''
-var x = () => /*error:TOP_LEVEL_CYCLE*/y;
-var y = () => /*error:TOP_LEVEL_CYCLE*/x;
-''');
- var x = mainUnit.topLevelVariables[0];
- var y = mainUnit.topLevelVariables[1];
+ await assertErrorsInCode('''
+var x = () => y;
+var y = () => x;
+''', [
+ error(CompileTimeErrorCode.TOP_LEVEL_CYCLE, 14, 1),
+ error(CompileTimeErrorCode.TOP_LEVEL_CYCLE, 31, 1),
+ ]);
+
+ var x = _resultUnitElement.topLevelVariables[0];
+ var y = _resultUnitElement.topLevelVariables[1];
expect(x.name, 'x');
expect(y.name, 'y');
_assertTypeStr(x.type, 'dynamic');
@@ -337,12 +394,16 @@
}
test_circularReference_viaClosures_initializerTypes() async {
- var mainUnit = await checkFileElement('''
-var x = () => /*error:TOP_LEVEL_CYCLE*/y;
-var y = () => /*error:TOP_LEVEL_CYCLE*/x;
-''');
- var x = mainUnit.topLevelVariables[0];
- var y = mainUnit.topLevelVariables[1];
+ await assertErrorsInCode('''
+var x = () => y;
+var y = () => x;
+''', [
+ error(CompileTimeErrorCode.TOP_LEVEL_CYCLE, 14, 1),
+ error(CompileTimeErrorCode.TOP_LEVEL_CYCLE, 31, 1),
+ ]);
+
+ var x = _resultUnitElement.topLevelVariables[0];
+ var y = _resultUnitElement.topLevelVariables[1];
expect(x.name, 'x');
expect(y.name, 'y');
_assertTypeStr(x.initializer.returnType, 'dynamic Function()');
@@ -350,7 +411,7 @@
}
test_conflictsCanHappen2() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class I1 {
int x;
}
@@ -376,25 +437,30 @@
}
class C2 implements A, B {
- get /*error:INVALID_OVERRIDE,error:INVALID_OVERRIDE*/a => null;
+ get a => null;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 246, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 246, 1),
+ ]);
}
test_constructors_downwardsWithConstraint() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26431
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
class A {}
class B extends A {}
class Foo<T extends A> {}
void main() {
Foo<B> foo = new Foo();
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 81, 3),
+ ]);
}
test_constructors_inferFromArguments() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
T t;
C(this.t);
@@ -413,17 +479,25 @@
// Don't infer from explicit dynamic.
var c_dynamic = new C<dynamic>(42);
- x.t = /*error:INVALID_ASSIGNMENT*/'hello';
+ x.t = 'hello';
}
-''');
- _assertTypeStr(findLocalVariable(unit, 'x').type, 'C<int>');
- _assertTypeStr(findLocalVariable(unit, 'c_int').type, 'C<int>');
- _assertTypeStr(findLocalVariable(unit, 'c_num').type, 'C<num>');
- _assertTypeStr(findLocalVariable(unit, 'c_dynamic').type, 'C<dynamic>');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 85, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 194, 5),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 223, 6),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 309, 9),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 349, 7),
+ ]);
+
+ _assertTypeStr(findLocalVariable(_resultUnit, 'x').type, 'C<int>');
+ _assertTypeStr(findLocalVariable(_resultUnit, 'c_int').type, 'C<int>');
+ _assertTypeStr(findLocalVariable(_resultUnit, 'c_num').type, 'C<num>');
+ _assertTypeStr(
+ findLocalVariable(_resultUnit, 'c_dynamic').type, 'C<dynamic>');
}
test_constructors_inferFromArguments_const() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
final T t;
const C(this.t);
@@ -432,14 +506,17 @@
main() {
var x = const C(42);
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 63, 1),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'C<int>');
}
test_constructors_inferFromArguments_constWithUpperBound() async {
// Regression for https://github.com/dart-lang/sdk/issues/26993
- await checkFileElement('''
+ await assertErrorsInCode('''
class C<T extends num> {
final T x;
const C(this.x);
@@ -452,11 +529,14 @@
C<int> c2 = c;
const D<int> d = const D();
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 143, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 166, 1),
+ ]);
}
test_constructors_inferFromArguments_downwardsFromConstructor() {
- return checkFileElement(r'''
+ return assertErrorsInCode(r'''
class C<T> { C(List<T> list); }
main() {
@@ -467,11 +547,15 @@
// This one however works.
var b = new C<Object>([123]);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 75, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 151, 1),
+ ]);
}
test_constructors_inferFromArguments_factory() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
T t;
@@ -487,15 +571,18 @@
main() {
var x = new C(42);
- x.t = /*error:INVALID_ASSIGNMENT*/'hello';
+ x.t = 'hello';
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 149, 7),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'C<int>');
}
test_constructors_inferFromArguments_factory_callsConstructor() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A<T> {
A<T> f = new A();
A();
@@ -506,7 +593,7 @@
}
test_constructors_inferFromArguments_named() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
T t;
C.named(List<T> t);
@@ -515,15 +602,18 @@
main() {
var x = new C.named(<int>[]);
- x.t = /*error:INVALID_ASSIGNMENT*/'hello';
+ x.t = 'hello';
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 95, 7),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'C<int>');
}
test_constructors_inferFromArguments_namedFactory() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
T t;
C();
@@ -538,15 +628,18 @@
main() {
var x = new C.named(42);
- x.t = /*error:INVALID_ASSIGNMENT*/'hello';
+ x.t = 'hello';
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 156, 7),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'C<int>');
}
test_constructors_inferFromArguments_redirecting() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
T t;
C(this.t);
@@ -556,15 +649,18 @@
main() {
var x = new C.named(<int>[42]);
- x.t = /*error:INVALID_ASSIGNMENT*/'hello';
+ x.t = 'hello';
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 123, 7),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'C<int>');
}
test_constructors_inferFromArguments_redirectingFactory() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
abstract class C<T> {
T get t;
void set t(T t);
@@ -579,16 +675,19 @@
main() {
var x = new C(42);
- x.t = /*error:INVALID_ASSIGNMENT*/'hello';
+ x.t = 'hello';
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 183, 7),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'C<int>');
}
test_constructors_reverseTypeParameters() async {
// Regression for https://github.com/dart-lang/sdk/issues/26990
- await checkFileElement('''
+ await assertNoErrorsInCode('''
class Pair<T, U> {
T t;
U u;
@@ -599,35 +698,43 @@
}
test_constructors_tooManyPositionalArguments() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
class A<T> {}
main() {
- var a = new A/*error:EXTRA_POSITIONAL_ARGUMENTS*/(42);
+ var a = new A(42);
}
-''');
- var a = findLocalVariable(unit, 'a');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 29, 1),
+ error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 38, 4),
+ ]);
+
+ var a = findLocalVariable(_resultUnit, 'a');
_assertTypeStr(a.type, 'A<dynamic>');
}
test_doNotInferOverriddenFieldsThatExplicitlySayDynamic_infer() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
final int x = 2;
}
class B implements A {
- dynamic get /*error:INVALID_OVERRIDE*/x => 3;
+ dynamic get x => 3;
}
foo() {
String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 69, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 97, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 118, 1),
+ ]);
}
test_dontInferFieldTypeWhenInitializerIsNull() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
var x = null;
var y = 3;
class A {
@@ -640,36 +747,44 @@
test() {
x = "hi";
- y = /*error:INVALID_ASSIGNMENT*/"hi";
+ y = "hi";
A.x = "hi";
- A.y = /*error:INVALID_ASSIGNMENT*/"hi";
+ A.y = "hi";
new A().x2 = "hi";
- new A().y2 = /*error:INVALID_ASSIGNMENT*/"hi";
+ new A().y2 = "hi";
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 140, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 168, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 210, 4),
+ ]);
}
test_dontInferTypeOnDynamic() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
test() {
dynamic x = 3;
x = "hi";
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 19, 1),
+ ]);
}
test_dontInferTypeWhenInitializerIsNull() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
test() {
var x = null;
x = "hi";
x = 3;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
}
test_downwardInference_miscellaneous() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
typedef T Function2<S, T>(S x);
class A<T> {
Function2<T, T> x;
@@ -687,11 +802,13 @@
A<int> a = new A(f);
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 266, 1),
+ ]);
}
test_downwardsInference_insideTopLevel() async {
- await checkFileElement('''
+ await assertNoErrorsInCode('''
class A {
B<int> b;
}
@@ -709,7 +826,7 @@
}
test_downwardsInferenceAnnotations() async {
- await checkFileElement('''
+ await assertNoErrorsInCode('''
class Foo {
const Foo(List<String> l);
const Foo.named(List<String> l);
@@ -722,29 +839,34 @@
}
test_downwardsInferenceAssignmentStatements() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
void main() {
List<int> l;
- l = [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"];
+ l = ["hello"];
l = (l = [1]);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 26, 1),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 36, 7),
+ ]);
}
test_downwardsInferenceAsyncAwait() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
import 'dart:async';
Future test() async {
dynamic d;
List<int> l0 = await [d];
- List<int> l1 = await new Future.value(
- [d]);
+ List<int> l1 = await new Future.value([d]);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 68, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 96, 2),
+ ]);
}
test_downwardsInferenceForEach() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
import 'dart:async';
abstract class MyStream<T> extends Stream<T> {
@@ -755,11 +877,14 @@
for(int x in [1, 2, 3]) {}
await for(int x in new MyStream()) {}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 137, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 172, 1),
+ ]);
}
test_downwardsInferenceInitializingFormalDefaultFormal() async {
- await checkFileElement('''
+ await assertNoErrorsInCode('''
typedef T Function2<S, T>([S x]);
class Foo {
List<int> x;
@@ -773,7 +898,7 @@
}
test_downwardsInferenceOnConstructorArguments_inferDownwards() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class F0 {
F0(List<int> a) {}
}
@@ -792,37 +917,45 @@
void main() {
new F0([]);
new F0([3]);
- new F0([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- new F0([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello",
- 3]);
+ new F0(["hello"]);
+ new F0(["hello", 3]);
new F1(a: []);
new F1(a: [3]);
- new F1(a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- new F1(a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ new F1(a: ["hello"]);
+ new F1(a: ["hello", 3]);
new F2([]);
new F2([3]);
- new F2([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- new F2([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ new F2(["hello"]);
+ new F2(["hello", 3]);
new F3([]);
new F3([[3]]);
- new F3([[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]]);
- new F3([[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"],
- [3]]);
+ new F3([["hello"]]);
+ new F3([["hello"], [3]]);
new F4(a: []);
new F4(a: [[3]]);
- new F4(a: [[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]]);
- new F4(a: [[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"],
- [3]]);
+ new F4(a: [["hello"]]);
+ new F4(a: [["hello"], [3]]);
}
-''');
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 259, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 280, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 343, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 367, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 421, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 442, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 499, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 522, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 591, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 617, 7),
+ ]);
}
test_downwardsInferenceOnFunctionArguments_inferDownwards() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
void f0(List<int> a) {}
void f1({List<int> a}) {}
void f2(Iterable<int> a) {}
@@ -831,71 +964,114 @@
void main() {
f0([]);
f0([3]);
- f0([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- f0([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ f0(["hello"]);
+ f0(["hello", 3]);
f1(a: []);
f1(a: [3]);
- f1(a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- f1(a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ f1(a: ["hello"]);
+ f1(a: ["hello", 3]);
f2([]);
f2([3]);
- f2([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- f2([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ f2(["hello"]);
+ f2(["hello", 3]);
f3([]);
f3([[3]]);
- f3([[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]]);
- f3([[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"], [3]]);
+ f3([["hello"]]);
+ f3([["hello"], [3]]);
f4(a: []);
f4(a: [[3]]);
- f4(a: [[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]]);
- f4(a: [[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"], [3]]);
+ f4(a: [["hello"]]);
+ f4(a: [["hello"], [3]]);
}
-''');
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 197, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 214, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 265, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 285, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 327, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 344, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 389, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 408, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 465, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 487, 7),
+ ]);
}
test_downwardsInferenceOnFunctionExpressions() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
typedef T Function2<S, T>(S x);
void main () {
{
Function2<int, String> l0 = (int x) => null;
Function2<int, String> l1 = (int x) => "hello";
- Function2<int, String> l2 = /*error:INVALID_ASSIGNMENT*/(String x) => "hello";
- Function2<int, String> l3 = (int x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;
- Function2<int, String> l4 = (int x) {return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;};
+ Function2<int, String> l2 = (String x) => "hello";
+ Function2<int, String> l3 = (int x) => 3;
+ Function2<int, String> l4 = (int x) {return 3;};
}
{
Function2<int, String> l0 = (x) => null;
Function2<int, String> l1 = (x) => "hello";
- Function2<int, String> l2 = (x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;
- Function2<int, String> l3 = (x) {return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;};
- Function2<int, String> l4 = (x) {return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/x;};
+ Function2<int, String> l2 = (x) => 3;
+ Function2<int, String> l3 = (x) {return 3;};
+ Function2<int, String> l4 = (x) {return x;};
}
{
Function2<int, List<String>> l0 = (int x) => null;
Function2<int, List<String>> l1 = (int x) => ["hello"];
- Function2<int, List<String>> l2 = /*error:INVALID_ASSIGNMENT*/(String x) => ["hello"];
- Function2<int, List<String>> l3 = (int x) => [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3];
- Function2<int, List<String>> l4 = (int x) {return [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3];};
+ Function2<int, List<String>> l2 = (String x) => ["hello"];
+ Function2<int, List<String>> l3 = (int x) => [3];
+ Function2<int, List<String>> l4 = (int x) {return [3];};
}
{
Function2<int, int> l0 = (x) => x;
Function2<int, int> l1 = (x) => x+1;
- Function2<int, String> l2 = (x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/x;
- Function2<int, String> l3 = (x) => x./*error:UNDEFINED_METHOD*/substring(3);
+ Function2<int, String> l2 = (x) => x;
+ Function2<int, String> l3 = (x) => x.substring(3);
Function2<String, String> l4 = (x) => x.substring(3);
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 79, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 128, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 180, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 185, 21),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 235, 2),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 251, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 281, 2),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 302, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 342, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 387, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 435, 2),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 447, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 477, 2),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 494, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 526, 2),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 543, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 589, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 644, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 704, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 709, 23),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 767, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 784, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 821, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 843, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 881, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 920, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 964, 2),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 976, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1006, 2),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 1020, 9),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1064, 2),
+ ]);
}
test_downwardsInferenceOnFunctionOfTUsingTheT() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
void main () {
{
T f<T>(T x) => null;
@@ -913,11 +1089,18 @@
Iterable<num> v = v2<num>(42);
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 52, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 179, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 212, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 253, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 288, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 318, 1),
+ ]);
}
test_downwardsInferenceOnGenericConstructorArguments_emptyList() async {
- await checkFileElement('''
+ await assertNoErrorsInCode('''
class F3<T> {
F3(Iterable<Iterable<T>> a) {}
}
@@ -932,7 +1115,7 @@
}
test_downwardsInferenceOnGenericConstructorArguments_inferDownwards() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class F0<T> {
F0(List<T> a) {}
}
@@ -954,79 +1137,87 @@
void main() {
new F0<int>([]);
new F0<int>([3]);
- new F0<int>([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- new F0<int>([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello",
- 3]);
+ new F0<int>(["hello"]);
+ new F0<int>(["hello", 3]);
new F1<int>(a: []);
new F1<int>(a: [3]);
- new F1<int>(a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- new F1<int>(a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ new F1<int>(a: ["hello"]);
+ new F1<int>(a: ["hello", 3]);
new F2<int>([]);
new F2<int>([3]);
- new F2<int>([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]);
- new F2<int>([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3]);
+ new F2<int>(["hello"]);
+ new F2<int>(["hello", 3]);
new F3<int>([]);
new F3<int>([[3]]);
- new F3<int>([[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]]);
- new F3<int>([[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"],
- [3]]);
+ new F3<int>([["hello"]]);
+ new F3<int>([["hello"], [3]]);
new F4<int>(a: []);
new F4<int>(a: [[3]]);
- new F4<int>(a: [[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"]]);
- new F4<int>(a: [[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"],
- [3]]);
+ new F4<int>(a: [["hello"]]);
+ new F4<int>(a: [["hello"], [3]]);
new F3([]);
var f31 = new F3([[3]]);
var f32 = new F3([["hello"]]);
- var f33 = new F3([["hello"],
- [3]]);
+ var f33 = new F3([["hello"], [3]]);
new F4(a: []);
new F4(a: [[3]]);
new F4(a: [["hello"]]);
- new F4(a: [["hello"],
- [3]]);
+ new F4(a: [["hello"], [3]]);
- new F5([[
- [3]]]);
+ new F5([[[3]]]);
}
-''');
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 338, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 364, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 442, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 471, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 540, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 566, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 638, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 666, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 750, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 781, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 819, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 846, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 879, 3),
+ ]);
}
test_downwardsInferenceOnGenericFunctionExpressions() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
void main () {
{
String f<S>(int x) => null;
var v = f;
v = <T>(int x) => null;
v = <T>(int x) => "hello";
- v = /*error:INVALID_ASSIGNMENT*/<T>(String x) => "hello";
- v = <T>(int x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;
- v = <T>(int x) {return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;};
+ v = <T>(String x) => "hello";
+ v = <T>(int x) => 3;
+ v = <T>(int x) {return 3;};
}
{
String f<S>(int x) => null;
var v = f;
v = <T>(x) => null;
v = <T>(x) => "hello";
- v = <T>(x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;
- v = <T>(x) {return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/3;};
- v = <T>(x) {return /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/x;};
+ v = <T>(x) => 3;
+ v = <T>(x) {return 3;};
+ v = <T>(x) {return x;};
}
{
List<String> f<S>(int x) => null;
var v = f;
v = <T>(int x) => null;
v = <T>(int x) => ["hello"];
- v = /*error:INVALID_ASSIGNMENT*/<T>(String x) => ["hello"];
- v = <T>(int x) => [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3];
- v = <T>(int x) {return [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3];};
+ v = <T>(String x) => ["hello"];
+ v = <T>(int x) => [3];
+ v = <T>(int x) {return [3];};
}
{
int int2int<S>(int x) => null;
@@ -1036,17 +1227,35 @@
x = <T>(x) => x;
x = <T>(x) => x+1;
var y = int2String;
- y = <T>(x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/x;
- y = <T>(x) => x./*error:UNDEFINED_METHOD*/substring(3);
+ y = <T>(x) => x;
+ y = <T>(x) => x.substring(3);
var z = string2String;
z = <T>(x) => x.substring(3);
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 59, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 133, 24),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 181, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 211, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 264, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 340, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 366, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 394, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 453, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 529, 26),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 580, 1),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 612, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 757, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 822, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 856, 1),
+ error(CompileTimeErrorCode.UNDEFINED_METHOD, 879, 9),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 901, 1),
+ ]);
}
test_downwardsInferenceOnInstanceCreations_inferDownwards() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A<S, T> {
S x;
T y;
@@ -1084,60 +1293,48 @@
A<int, String> a1 = new A.named(3, "hello");
A<int, String> a2 = new A<int, String>(3, "hello");
A<int, String> a3 = new A<int, String>.named(3, "hello");
- A<int, String> a4 = /*error:INVALID_CAST_NEW_EXPR*/new A<int, dynamic>(3, "hello");
- A<int, String> a5 = /*error:INVALID_CAST_NEW_EXPR*/new A<dynamic, dynamic>.named(3, "hello");
+ A<int, String> a4 = new A<int, dynamic>(3, "hello");
+ A<int, String> a5 = new A<dynamic, dynamic>.named(3, "hello");
}
{
- A<int, String> a0 = new A(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello",
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
- A<int, String> a1 = new A.named(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello",
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
+ A<int, String> a0 = new A("hello", 3);
+ A<int, String> a1 = new A.named("hello", 3);
}
{
A<int, String> a0 = new B("hello", 3);
A<int, String> a1 = new B.named("hello", 3);
A<int, String> a2 = new B<String, int>("hello", 3);
A<int, String> a3 = new B<String, int>.named("hello", 3);
- A<int, String> a4 = /*error:INVALID_ASSIGNMENT*/new B<String, dynamic>("hello", 3);
- A<int, String> a5 = /*error:INVALID_ASSIGNMENT*/new B<dynamic, dynamic>.named("hello", 3);
+ A<int, String> a4 = new B<String, dynamic>("hello", 3);
+ A<int, String> a5 = new B<dynamic, dynamic>.named("hello", 3);
}
{
- A<int, String> a0 = new B(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
- A<int, String> a1 = new B.named(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3,
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
+ A<int, String> a0 = new B(3, "hello");
+ A<int, String> a1 = new B.named(3, "hello");
}
{
A<int, int> a0 = new C(3);
A<int, int> a1 = new C.named(3);
A<int, int> a2 = new C<int>(3);
A<int, int> a3 = new C<int>.named(3);
- A<int, int> a4 = /*error:INVALID_ASSIGNMENT*/new C<dynamic>(3);
- A<int, int> a5 = /*error:INVALID_ASSIGNMENT*/new C<dynamic>.named(3);
+ A<int, int> a4 = new C<dynamic>(3);
+ A<int, int> a5 = new C<dynamic>.named(3);
}
{
- A<int, int> a0 = new C(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
- A<int, int> a1 = new C.named(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
+ A<int, int> a0 = new C("hello");
+ A<int, int> a1 = new C.named("hello");
}
{
A<int, String> a0 = new D("hello");
A<int, String> a1 = new D.named("hello");
A<int, String> a2 = new D<int, String>("hello");
A<int, String> a3 = new D<String, String>.named("hello");
- A<int, String> a4 = /*error:INVALID_ASSIGNMENT*/new D<num, dynamic>("hello");
- A<int, String> a5 = /*error:INVALID_ASSIGNMENT*/new D<dynamic, dynamic>.named("hello");
+ A<int, String> a4 = new D<num, dynamic>("hello");
+ A<int, String> a5 = new D<dynamic, dynamic>.named("hello");
}
{
- A<int, String> a0 = new D(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
- A<int, String> a1 = new D.named(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
+ A<int, String> a0 = new D(3);
+ A<int, String> a1 = new D.named(3);
}
{
A<C<int>, String> a0 = new E("hello");
@@ -1147,31 +1344,94 @@
a: [3],
b: ["hello"]);
A<int, String> a1 = new F(3, "hello",
- a: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"],
- b: [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/3]);
+ a: ["hello"],
+ b: [3]);
A<int, String> a2 = new F.named(3, "hello", 3, "hello");
A<int, String> a3 = new F.named(3, "hello");
- A<int, String> a4 = new F.named(3, "hello",
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello", /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
- A<int, String> a5 = new F.named(3, "hello",
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
+ A<int, String> a4 = new F.named(3, "hello", "hello", 3);
+ A<int, String> a5 = new F.named(3, "hello", "hello");
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 612, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 655, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 704, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 760, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 822, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_NEW_EXPR, 827, 31),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 879, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_NEW_EXPR, 884, 41),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 954, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 965, 7),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 974, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 997, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1014, 7),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1023, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1054, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1097, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1146, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1202, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1264, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1269, 34),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1324, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1329, 41),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1399, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1410, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1413, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1442, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1459, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1462, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1496, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1527, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1564, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1600, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1642, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1647, 17),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1682, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 1687, 23),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1736, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1747, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1773, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1790, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1827, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1867, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1913, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1966, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2028, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 2033, 28),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2082, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 2087, 38),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2154, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2165, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2188, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2205, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2239, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2325, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2406, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 2441, 7),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 2463, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2487, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2548, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2597, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2626, 7),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2635, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 2658, 2),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2687, 7),
+ ]);
}
test_downwardsInferenceOnListLiterals_inferDownwards() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
void foo([List<String> list1 = const [],
- List<String> list2 = const [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/42]]) {
+ List<String> list2 = const [42]]) {
}
void main() {
{
List<int> l0 = [];
List<int> l1 = [3];
- List<int> l2 = [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"];
- List<int> l3 = [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3];
+ List<int> l2 = ["hello"];
+ List<int> l3 = ["hello", 3];
}
{
List<dynamic> l0 = [];
@@ -1180,29 +1440,63 @@
List<dynamic> l3 = ["hello", 3];
}
{
- List<int> l0 = /*error:INVALID_CAST_LITERAL_LIST*/<num>[];
- List<int> l1 = /*error:INVALID_CAST_LITERAL_LIST*/<num>[3];
- List<int> l2 = /*error:INVALID_CAST_LITERAL_LIST*/<num>[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"];
- List<int> l3 = /*error:INVALID_CAST_LITERAL_LIST*/<num>[/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3];
+ List<int> l0 = <num>[];
+ List<int> l1 = <num>[3];
+ List<int> l2 = <num>["hello"];
+ List<int> l3 = <num>["hello", 3];
}
{
Iterable<int> i0 = [];
Iterable<int> i1 = [3];
- Iterable<int> i2 = [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"];
- Iterable<int> i3 = [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3];
+ Iterable<int> i2 = ["hello"];
+ Iterable<int> i3 = ["hello", 3];
}
{
const List<int> c0 = const [];
const List<int> c1 = const [3];
- const List<int> c2 = const [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello"];
- const List<int> c3 = const [/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/"hello", 3];
+ const List<int> c2 = const ["hello"];
+ const List<int> c3 = const ["hello", 3];
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 79, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 122, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 145, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 169, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 175, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 199, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 205, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 244, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 271, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 299, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 333, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 374, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_LIST, 379, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 402, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_LIST, 407, 8),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 431, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_LIST, 436, 14),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 442, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 466, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_LIST, 471, 17),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 477, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 516, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 543, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 571, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 577, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 605, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 611, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 652, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 687, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 723, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 735, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 765, 2),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 777, 7),
+ ]);
}
test_downwardsInferenceOnListLiterals_inferIfValueTypesMatchContext() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class DartType {}
typedef void Asserter<T>(T type);
typedef Asserter<T> AsserterBuilder<S, T>(S arg);
@@ -1261,12 +1555,11 @@
}
test_downwardsInferenceOnMapLiterals() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
void foo([Map<int, String> m1 = const {1: "hello"},
Map<int, String> m2 = const {
// One error is from type checking and the other is from const evaluation.
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello":
- "world"
+ "hello": "world"
}]) {
}
void main() {
@@ -1274,15 +1567,14 @@
Map<int, String> l0 = {};
Map<int, String> l1 = {3: "hello"};
Map<int, String> l2 = {
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello": "hello"
+ "hello": "hello"
};
Map<int, String> l3 = {
- 3: /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/3
+ 3: 3
};
Map<int, String> l4 = {
3: "hello",
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello":
- /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/3
+ "hello": 3
};
}
{
@@ -1296,75 +1588,116 @@
Map<dynamic, String> l0 = {};
Map<dynamic, String> l1 = {3: "hello"};
Map<dynamic, String> l2 = {"hello": "hello"};
- Map<dynamic, String> l3 = {
- 3: /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/3
- };
+ Map<dynamic, String> l3 = {3: 3};
Map<dynamic, String> l4 = {
3: "hello",
- "hello": /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/3
+ "hello": 3
};
}
{
Map<int, dynamic> l0 = {};
Map<int, dynamic> l1 = {3: "hello"};
Map<int, dynamic> l2 = {
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello": "hello"
+ "hello": "hello"
};
Map<int, dynamic> l3 = {3: 3};
Map<int, dynamic> l4 = {
3:"hello",
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello": 3
+ "hello": 3
};
}
{
- Map<int, String> l0 = /*error:INVALID_CAST_LITERAL_MAP*/<num, dynamic>{};
- Map<int, String> l1 = /*error:INVALID_CAST_LITERAL_MAP*/<num, dynamic>{3: "hello"};
- Map<int, String> l3 = /*error:INVALID_CAST_LITERAL_MAP*/<num, dynamic>{3: 3};
+ Map<int, String> l0 = <num, dynamic>{};
+ Map<int, String> l1 = <num, dynamic>{3: "hello"};
+ Map<int, String> l3 = <num, dynamic>{3: 3};
}
{
const Map<int, String> l0 = const {};
const Map<int, String> l1 = const {3: "hello"};
const Map<int, String> l2 = const {
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello":
- "hello"
+ "hello": "hello"
};
const Map<int, String> l3 = const {
- 3: /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/3
+ 3: 3
};
const Map<int, String> l4 = const {
3:"hello",
- /*error:MAP_KEY_TYPE_NOT_ASSIGNABLE*/"hello":
- /*error:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/3
+ "hello": 3
};
}
}
-''');
+''', [
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 173, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 241, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 271, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 311, 2),
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 324, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 369, 2),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 385, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 415, 2),
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 446, 7),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 455, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 498, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 533, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 578, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 629, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 668, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 731, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 765, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 809, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 859, 2),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 868, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 897, 2),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 937, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 976, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1007, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1048, 2),
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 1061, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1107, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1142, 2),
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 1172, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1219, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_MAP, 1224, 16),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1263, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_MAP, 1268, 26),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1317, 2),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL_MAP, 1322, 20),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1379, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1421, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1473, 2),
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 1492, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1543, 2),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 1565, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 1601, 2),
+ error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 1637, 7),
+ error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 1646, 1),
+ ]);
}
test_fieldRefersToStaticGetter() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
final x = _x;
static int get _x => null;
}
''');
- var x = mainUnit.types[0].fields[0];
+ var x = _resultUnitElement.types[0].fields[0];
_assertTypeStr(x.type, 'int');
}
test_fieldRefersToTopLevelGetter() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
final x = y;
}
int get y => null;
''');
- var x = mainUnit.types[0].fields[0];
+ var x = _resultUnitElement.types[0].fields[0];
_assertTypeStr(x.type, 'int');
}
test_futureOr_subtyping() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
void add(int x) {}
add2(int y) {}
@@ -1373,7 +1706,10 @@
var a = f.then(add);
var b = f.then(add2);
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 87, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 1),
+ ]);
}
test_futureThen() async {
@@ -1402,17 +1738,17 @@
}
''';
- await checkFileElement(
+ await _assertNoErrors(
build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
- await checkFileElement(
+ await _assertNoErrors(
build(declared: "MyFuture", downwards: "Future", upwards: "MyFuture"));
- await checkFileElement(
+ await _assertNoErrors(
build(declared: "MyFuture", downwards: "MyFuture", upwards: "Future"));
- await checkFileElement(build(
+ await _assertNoErrors(build(
declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"));
- await checkFileElement(
+ await _assertNoErrors(
build(declared: "Future", downwards: "Future", upwards: "MyFuture"));
- await checkFileElement(
+ await _assertNoErrors(
build(declared: "Future", downwards: "Future", upwards: "Future"));
}
@@ -1438,23 +1774,34 @@
(x) {return x ? 2 : new $upwards<int>.value(3);});
}
''';
- await checkFileElement(
+ await _assertNoErrors(
build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
- await checkFileElement(
+ disposeAnalysisContextCollection();
+
+ await _assertNoErrors(
build(declared: "MyFuture", downwards: "Future", upwards: "MyFuture"));
- await checkFileElement(
+ disposeAnalysisContextCollection();
+
+ await _assertNoErrors(
build(declared: "MyFuture", downwards: "MyFuture", upwards: "Future"));
- await checkFileElement(build(
+ disposeAnalysisContextCollection();
+
+ await _assertNoErrors(build(
declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"));
- await checkFileElement(
+ disposeAnalysisContextCollection();
+
+ await _assertNoErrors(
build(declared: "Future", downwards: "Future", upwards: "MyFuture"));
- await checkFileElement(
+ disposeAnalysisContextCollection();
+
+ await _assertNoErrors(
build(declared: "Future", downwards: "Future", upwards: "Future"));
+ disposeAnalysisContextCollection();
}
test_futureThen_downwardsMethodTarget() async {
// Not working yet, see: https://github.com/dart-lang/sdk/issues/27114
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
main() {
Future<int> f;
@@ -1463,24 +1810,30 @@
.whenComplete(() {});
b = f.then((x) => []);
}
- ''');
+ ''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 67, 1),
+ ]);
}
test_futureThen_explicitFuture() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import "dart:async";
m1() {
Future<int> f;
- var x = f.then<Future<List<int>>>(
- (x) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/[]);
- Future<List<int>> y = /*error:INVALID_ASSIGNMENT*/x;
+ var x = f.then<Future<List<int>>>((x) => []);
+ Future<List<int>> y = x;
}
m2() {
Future<int> f;
var x = f.then<List<int>>((x) => []);
Future<List<int>> y = x;
}
- ''');
+''', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 88, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 113, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 117, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 206, 1),
+ ]);
}
test_futureThen_upwards() async {
@@ -1496,26 +1849,53 @@
void main() {
var f = foo().then((_) => 2.3);
- $downwards<int> f2 = /*error:INVALID_ASSIGNMENT*/f;
+ $downwards<int> f2 = f;
// The unnecessary cast is to illustrate that we inferred <double> for
// the generic type args, even though we had a return type context.
- $downwards<num> f3 = /*info:UNNECESSARY_CAST*/foo().then(
+ $downwards<num> f3 = foo().then(
(_) => 2.3) as $upwards<double>;
}
$declared foo() => new $declared<int>.value(1);
''';
- await checkFileElement(
- build(declared: "MyFuture", downwards: "Future", upwards: "Future"));
- await checkFileElement(build(
- declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"));
- await checkFileElement(
- build(declared: "Future", downwards: "Future", upwards: "Future"));
+
+ await assertErrorsInCode(
+ build(declared: "MyFuture", downwards: "Future", upwards: "Future"),
+ [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 309, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 314, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 475, 2),
+ error(HintCode.UNNECESSARY_CAST, 480, 47),
+ ],
+ );
+ disposeAnalysisContextCollection();
+
+ await assertErrorsInCode(
+ build(declared: "MyFuture", downwards: "MyFuture", upwards: "MyFuture"),
+ [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 311, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 316, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 479, 2),
+ error(HintCode.UNNECESSARY_CAST, 484, 49),
+ ],
+ );
+ disposeAnalysisContextCollection();
+
+ await assertErrorsInCode(
+ build(declared: "Future", downwards: "Future", upwards: "Future"),
+ [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 309, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 314, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 475, 2),
+ error(HintCode.UNNECESSARY_CAST, 480, 47),
+ ],
+ );
+ disposeAnalysisContextCollection();
}
test_futureThen_upwardsFromBlock() async {
// Regression test for https://github.com/dart-lang/sdk/issues/27113.
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
main() {
Future<int> base;
@@ -1524,7 +1904,9 @@
Future<bool> b = f;
b = g;
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 146, 1),
+ ]);
}
test_futureUnion_asyncConditional() async {
@@ -1551,9 +1933,16 @@
return y;
}
''';
- await checkFileElement(
- build(downwards: "Future", upwards: "Future", expectedInfo: ''));
- await checkFileElement(build(downwards: "Future", upwards: "MyFuture"));
+
+ await assertNoErrorsInCode(
+ build(downwards: "Future", upwards: "Future", expectedInfo: ''),
+ );
+ disposeAnalysisContextCollection();
+
+ await assertNoErrorsInCode(
+ build(downwards: "Future", upwards: "MyFuture"),
+ );
+ disposeAnalysisContextCollection();
}
test_futureUnion_downwards() async {
@@ -1585,20 +1974,51 @@
''';
}
- await checkFileElement(build(
+ await assertErrorsInCode(
+ build(
declared: "MyFuture",
downwards: "Future",
upwards: "Future",
- expectedError: '/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'));
- await checkFileElement(
- build(declared: "MyFuture", downwards: "Future", upwards: "MyFuture"));
- await checkFileElement(build(
+ expectedError: '',
+ ),
+ [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 338, 4),
+ ],
+ );
+ disposeAnalysisContextCollection();
+
+ await assertErrorsInCode(
+ build(
+ declared: "MyFuture",
+ downwards: "Future",
+ upwards: "MyFuture",
+ ),
+ [],
+ );
+ disposeAnalysisContextCollection();
+
+ await assertErrorsInCode(
+ build(
declared: "Future",
downwards: "Future",
upwards: "Future",
- expectedError: '/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'));
- await checkFileElement(
- build(declared: "Future", downwards: "Future", upwards: "MyFuture"));
+ expectedError: '',
+ ),
+ [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 336, 4),
+ ],
+ );
+ disposeAnalysisContextCollection();
+
+ await assertErrorsInCode(
+ build(
+ declared: "Future",
+ downwards: "Future",
+ upwards: "MyFuture",
+ ),
+ [],
+ );
+ disposeAnalysisContextCollection();
}
test_futureUnion_downwardsGenericMethodWithFutureReturn() async {
@@ -1606,7 +2026,7 @@
//
// We need to take a future union into account for both directions of
// generic method inference.
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
foo() async {
@@ -1616,12 +2036,14 @@
}
class A {}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 6),
+ ]);
}
test_futureUnion_downwardsGenericMethodWithGenericReturn() async {
// Regression test for https://github.com/dart-lang/sdk/issues/27284
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
T id<T>(T x) => x;
@@ -1630,12 +2052,14 @@
Future<String> f;
String s = await id(f);
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 86, 1),
+ ]);
}
test_futureUnion_upwardsGenericMethods() async {
// Regression test for https://github.com/dart-lang/sdk/issues/27151
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:async';
main() async {
@@ -1651,11 +2075,13 @@
class A {}
class B extends A {}
class C extends A {}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 229, 4),
+ ]);
}
test_genericFunctions_returnTypedef() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
typedef void ToValue<T>(T value);
main() {
@@ -1665,21 +2091,26 @@
ToValue<int> takesInt = x;
takesInt = y;
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 130, 8),
+ ]);
}
test_genericMethods_basicDownwardInference() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
T f<S, T>(S s) => null;
main() {
String x = f(42);
String y = (f)(42);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 42, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ ]);
}
test_genericMethods_dartMathMinMax() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
import 'dart:math';
void printInt(int x) => print(x);
@@ -1699,51 +2130,60 @@
printInt(myMax(1, 2) as int);
// An int context means doubles are rejected
- printInt(max(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/2.0));
- printInt(min(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/2.0));
+ printInt(max(1, 2.0));
+ printInt(min(1, 2.0));
// A double context means ints are accepted as doubles
printDouble(max(1, 2.0));
printDouble(min(1, 2.0));
// Types other than int and double are not accepted.
- printInt(
- min(
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hi",
- /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"there"));
+ printInt(min("hi", "there"));
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 467, 3),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 492, 3),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 683, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 689, 7),
+ ]);
}
test_genericMethods_doNotInferInvalidOverrideOfGenericMethod() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class C {
T m<T>(T x) => x;
}
class D extends C {
-/*error:INVALID_OVERRIDE*/m(x) => x;
+m(x) => x;
}
main() {
- int y = new D().m/*error:WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD*/<int>(42);
+ int y = new D().m<int>(42);
print(y);
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 50, 1),
+ error(CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD, 91, 5),
+ ]);
}
test_genericMethods_downwardsInferenceAffectsArguments() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
T f<T>(List<T> s) => null;
main() {
String x = f(['hi']);
- String y = f([/*error:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/42]);
+ String y = f([42]);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 45, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 69, 1),
+ error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 76, 2),
+ ]);
}
test_genericMethods_downwardsInferenceFold() async {
// Regression from https://github.com/dart-lang/sdk/issues/25491
// The first example works now, but the latter requires a full solution to
// https://github.com/dart-lang/sdk/issues/25490
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
void main() {
List<int> o;
int y = o.fold(0, (x, y) => x + y);
@@ -1756,38 +2196,48 @@
var z = (o.fold)(0, (x, y) => x + y);
y = z;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 35, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 175, 1),
+ ]);
}
test_genericMethods_handleOverrideOfNonGenericWithGeneric() async {
// Regression test for crash when adding genericity
- await checkFileElement('''
+ await assertErrorsInCode('''
class C {
m(x) => x;
dynamic g(int x) => x;
}
class D extends C {
- T /*error:INVALID_OVERRIDE*/m<T>(T x) => x;
- T /*error:INVALID_OVERRIDE*/g<T>(T x) => x;
+ T m<T>(T x) => x;
+ T g<T>(T x) => x;
}
main() {
- int y = (/*info:UNNECESSARY_CAST*/new D() as C).m(42);
+ int y = (new D() as C).m(42);
print(y);
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 74, 1),
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 94, 1),
+ error(HintCode.UNNECESSARY_CAST, 132, 12),
+ ]);
}
test_genericMethods_inferenceError() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
main() {
List<String> y;
- Iterable<String> x = y.map((String z) => /*error:RETURN_OF_INVALID_TYPE_FROM_CLOSURE*/1.0);
+ Iterable<String> x = y.map((String z) => 1.0);
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 46, 1),
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 70, 3),
+ ]);
}
test_genericMethods_inferGenericFunctionParameterType() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C<T> extends D<T> {
f<U>(x) { return null; }
}
@@ -1796,12 +2246,12 @@
}
typedef void F<V>(V v);
''');
- var f = mainUnit.getType('C').methods[0];
+ var f = _resultUnitElement.getType('C').methods[0];
_assertTypeStr(f.type, 'void Function(U) Function<U>(U)');
}
test_genericMethods_inferGenericFunctionParameterType2() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C<T> extends D<T> {
f<U>(g) => null;
}
@@ -1810,12 +2260,12 @@
}
typedef List<V> G<V>();
''');
- var f = mainUnit.getType('C').methods[0];
+ var f = _resultUnitElement.getType('C').methods[0];
_assertTypeStr(f.type, 'void Function<U>(List<U> Function())');
}
test_genericMethods_inferGenericFunctionReturnType() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C<T> extends D<T> {
f<U>(x) { return null; }
}
@@ -1824,13 +2274,13 @@
}
typedef V F<V>();
''');
- var f = mainUnit.getType('C').methods[0];
+ var f = _resultUnitElement.getType('C').methods[0];
_assertTypeStr(f.type, 'U Function() Function<U>(U)');
}
test_genericMethods_inferGenericMethodType() async {
// Regression test for https://github.com/dart-lang/sdk/issues/25668
- await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
T m<T>(T x) => x;
}
@@ -1845,7 +2295,7 @@
}
test_genericMethods_IterableAndFuture() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
import 'dart:async';
Future<int> make(int x) => (new Future(() => x));
@@ -1854,19 +2304,25 @@
Iterable<Future<int>> list = <int>[1, 2, 3].map(make);
Future<List<int>> results = Future.wait(list);
Future<String> results2 = results.then((List<int> list)
- => list.fold('', (x, y) => x /*error:UNDEFINED_OPERATOR*/+ y.toString()));
+ => list.fold('', (x, y) => x + y.toString()));
Future<String> results3 = results.then((List<int> list)
- => list.fold('', /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/(String x, y) => x + y.toString()));
+ => list.fold('', (String x, y) => x + y.toString()));
Future<String> results4 = results.then((List<int> list)
=> list.fold<String>('', (x, y) => x + y.toString()));
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 205, 8),
+ error(CompileTimeErrorCode.UNDEFINED_OPERATOR, 279, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 315, 8),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 377, 33),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 432, 8),
+ ]);
}
test_genericMethods_nestedGenericInstantiation() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
import 'dart:math' as math;
class Trace {
List<Frame> frames = [];
@@ -1881,11 +2337,13 @@
.fold(0, math.max);
}).fold(0, math.max);
}
- ''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 153, 7),
+ ]);
}
test_genericMethods_usesGreatestLowerBound() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
typedef Iterable<num> F(int x);
typedef List<int> G(double x);
@@ -1894,13 +2352,16 @@
main() {
var v = generic((F f) => null, (G g) => null);
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 118, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int> Function(num)');
}
test_genericMethods_usesGreatestLowerBound_topLevel() async {
- var mainUnit = await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
typedef Iterable<num> F(int x);
typedef List<int> G(double x);
@@ -1908,19 +2369,19 @@
var v = generic((F f) => null, (G g) => null);
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'List<int> Function(num)');
}
test_infer_assignToIndex() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
List<double> a = <double>[];
var b = (a[0] = 1.0);
''');
}
test_infer_assignToProperty() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A {
int f;
}
@@ -1936,7 +2397,7 @@
}
test_infer_assignToProperty_custom() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A {
A operator +(other) => this;
A operator -(other) => this;
@@ -1952,7 +2413,7 @@
}
test_infer_assignToRef() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A {
int f;
}
@@ -1964,7 +2425,7 @@
}
test_infer_binary_custom() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A {
int operator +(other) => 1;
double operator -(other) => 2.0;
@@ -1975,7 +2436,7 @@
}
test_infer_binary_doubleDouble() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a_equal = 1.0 == 2.0;
var a_notEqual = 1.0 != 2.0;
var a_add = 1.0 + 2.0;
@@ -1992,7 +2453,7 @@
}
test_infer_binary_doubleInt() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a_equal = 1.0 == 2;
var a_notEqual = 1.0 != 2;
var a_add = 1.0 + 2;
@@ -2009,7 +2470,7 @@
}
test_infer_binary_intDouble() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a_equal = 1 == 2.0;
var a_notEqual = 1 != 2.0;
var a_add = 1 + 2.0;
@@ -2026,7 +2487,7 @@
}
test_infer_binary_intInt() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a_equal = 1 == 2;
var a_notEqual = 1 != 2;
var a_bitXor = 1 ^ 2;
@@ -2048,14 +2509,14 @@
}
test_infer_conditional() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a = 1 == 2 ? 1 : 2.0;
var b = 1 == 2 ? 1.0 : 2;
''');
}
test_infer_prefixExpression() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a_not = !true;
var a_complement = ~1;
var a_negate = -1;
@@ -2063,7 +2524,7 @@
}
test_infer_prefixExpression_custom() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A {
A();
int operator ~() => 1;
@@ -2076,7 +2537,7 @@
}
test_infer_throw() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var t = true;
var a = (throw 0);
var b = (throw 0) ? 1 : 2;
@@ -2086,7 +2547,7 @@
}
test_infer_typeCast() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
class A<T> {}
class B<T> extends A<T> {
foo() {}
@@ -2100,7 +2561,7 @@
}
test_infer_typedListLiteral() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a = <int>[];
var b = <double>[1.0, 2.0, 3.0];
var c = <List<int>>[];
@@ -2109,7 +2570,7 @@
}
test_infer_typedMapLiteral() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var a = <int, String>{0: 'aaa', 1: 'bbb'};
var b = <double, int>{1.1: 1, 2.2: 2};
var c = <List<int>, Map<String, double>>{};
@@ -2120,28 +2581,32 @@
}
test_infer_use_of_void() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class B {
void f() {}
}
class C extends B {
f() {}
}
-var x = /*error:TOP_LEVEL_INSTANCE_METHOD*/new C().f();
-''');
+var x = new C().f();
+''', [
+ error(StrongModeCode.TOP_LEVEL_INSTANCE_METHOD, 65, 11),
+ ]);
}
test_inferConstsTransitively() async {
- addFile('''
+ newFile('$testPackageLibPath/b.dart', content: '''
const b1 = 2;
-''', name: '/b.dart');
- addFile('''
-import 'main.dart';
+''');
+
+ newFile('$testPackageLibPath/a.dart', content: '''
+import 'test.dart';
import 'b.dart';
const a1 = m2;
const a2 = b1;
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertErrorsInCode('''
import 'a.dart';
const m1 = a1;
const m2 = a2;
@@ -2150,11 +2615,13 @@
int i;
i = m1;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ ]);
}
test_inferCorrectlyOnMultipleVariablesDeclaredTogether() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
var x, y = 2, z = "hi";
}
@@ -2168,26 +2635,32 @@
int i;
s = new B().x;
- s = /*error:INVALID_ASSIGNMENT*/new B().y;
+ s = new B().y;
s = new B().z;
- s = /*error:INVALID_ASSIGNMENT*/new B().w;
+ s = new B().w;
i = new B().x;
i = new B().y;
- i = /*error:INVALID_ASSIGNMENT*/new B().z;
+ i = new B().z;
i = new B().w;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 112, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 121, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 148, 9),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 182, 9),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 234, 9),
+ ]);
}
test_inferFromComplexExpressionsIfOuterMostValueIsPrecise() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A { int x; B operator+(other) => null; }
class B extends A { B(ignore); }
var a = new A();
// Note: it doesn't matter that some of these refer to 'x'.
-var b = new B(/*error:UNDEFINED_IDENTIFIER*/x); // allocations
-var c1 = [/*error:UNDEFINED_IDENTIFIER*/x]; // list literals
+var b = new B(x); // allocations
+var c1 = [x]; // list literals
var c2 = const [];
var d = <dynamic, dynamic>{'a': 'b'}; // map literals
var e = new A()..x = 3; // cascades
@@ -2196,38 +2669,54 @@
// connected component.
var g = -3;
var h = new A() + 3;
-var i = /*error:UNDEFINED_OPERATOR*/- new A();
-var j = /*info:UNNECESSARY_CAST*/null as B;
+var i = - new A();
+var j = null as B;
test1() {
- a = /*error:INVALID_ASSIGNMENT*/"hi";
+ a = "hi";
a = new B(3);
- b = /*error:INVALID_ASSIGNMENT*/"hi";
+ b = "hi";
b = new B(3);
c1 = [];
- c1 = /*error:INVALID_ASSIGNMENT*/{};
+ c1 = {};
c2 = [];
- c2 = /*error:INVALID_ASSIGNMENT*/{};
+ c2 = {};
d = {};
- d = /*error:INVALID_ASSIGNMENT*/3;
+ d = 3;
e = new A();
- e = /*error:INVALID_ASSIGNMENT*/{};
+ e = {};
f = 3;
- f = /*error:INVALID_ASSIGNMENT*/false;
+ f = false;
g = 1;
- g = /*error:INVALID_ASSIGNMENT*/false;
- h = /*error:INVALID_ASSIGNMENT*/false;
+ g = false;
+ h = false;
h = new B('b');
i = false;
j = new B('b');
- j = /*error:INVALID_ASSIGNMENT*/false;
- j = /*error:INVALID_ASSIGNMENT*/[];
+ j = false;
+ j = [];
}
-''');
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 171, 1),
+ error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 201, 1),
+ error(CompileTimeErrorCode.UNDEFINED_OPERATOR, 572, 1),
+ error(HintCode.UNNECESSARY_CAST, 591, 9),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 619, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 647, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 687, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 709, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 729, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 753, 2),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 772, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 794, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 807, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 869, 5),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 882, 2),
+ ]);
}
test_inferFromRhsOnlyIfItWontConflictWithOverriddenFields() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
var x;
}
@@ -2240,11 +2729,14 @@
String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 78, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 99, 1),
+ ]);
}
test_inferFromRhsOnlyIfItWontConflictWithOverriddenFields2() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
final x = null;
}
@@ -2257,19 +2749,24 @@
String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 1),
+ ]);
}
test_inferFromVariablesInCycleLibsWhenFlagIsOn() async {
- addFile('''
-import 'main.dart';
+ newFile('$testPackageLibPath/a.dart', content: '''
+import 'test.dart';
var x = 2; // ok to infer
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertNoErrorsInCode('''
import 'a.dart';
var y = x; // now ok :)
test1() {
+ // ignore:unused_local_variable
int t = 3;
t = x;
t = y;
@@ -2278,15 +2775,17 @@
}
test_inferFromVariablesInCycleLibsWhenFlagIsOn2() async {
- addFile('''
-import 'main.dart';
+ newFile('$testPackageLibPath/a.dart', content: '''
+import 'test.dart';
class A { static var x = 2; }
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertNoErrorsInCode('''
import 'a.dart';
class B { static var y = A.x; }
test1() {
+ // ignore:unused_local_variable
int t = 3;
t = A.x;
t = B.y;
@@ -2295,89 +2794,109 @@
}
test_inferFromVariablesInNonCycleImportsWithFlag() async {
- addFile('''
+ newFile('$testPackageLibPath/a.dart', content: '''
var x = 2;
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertErrorsInCode('''
import 'a.dart';
var y = x;
test1() {
- x = /*error:INVALID_ASSIGNMENT*/"hi";
- y = /*error:INVALID_ASSIGNMENT*/"hi";
+ x = "hi";
+ y = "hi";
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 45, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 57, 4),
+ ]);
}
test_inferFromVariablesInNonCycleImportsWithFlag2() async {
- addFile('''
+ newFile('$testPackageLibPath/a.dart', content: '''
class A { static var x = 2; }
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertErrorsInCode('''
import 'a.dart';
class B { static var y = A.x; }
test1() {
- A.x = /*error:INVALID_ASSIGNMENT*/"hi";
- B.y = /*error:INVALID_ASSIGNMENT*/"hi";
+ A.x = "hi";
+ B.y = "hi";
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 68, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 82, 4),
+ ]);
}
test_inferGenericMethodType_named() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
T m<T>(int a, {String b, T c}) => null;
}
main() {
var y = new C().m(1, b: 'bbb', c: 2.0);
}
-''');
- var y = findLocalVariable(unit, 'y');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 68, 1),
+ ]);
+
+ var y = findLocalVariable(_resultUnit, 'y');
_assertTypeStr(y.type, 'double');
}
test_inferGenericMethodType_positional() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
T m<T>(int a, [T b]) => null;
}
main() {
var y = new C().m(1, 2.0);
}
-''');
- var y = findLocalVariable(unit, 'y');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 59, 1),
+ ]);
+
+ var y = findLocalVariable(_resultUnit, 'y');
_assertTypeStr(y.type, 'double');
}
test_inferGenericMethodType_positional2() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
T m<T>(int a, [String b, T c]) => null;
}
main() {
var y = new C().m(1, 'bbb', 2.0);
}
-''');
- var y = findLocalVariable(unit, 'y');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 69, 1),
+ ]);
+
+ var y = findLocalVariable(_resultUnit, 'y');
_assertTypeStr(y.type, 'double');
}
test_inferGenericMethodType_required() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
T m<T>(T x) => x;
}
main() {
var y = new C().m(42);
}
-''');
- var y = findLocalVariable(unit, 'y');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 47, 1),
+ ]);
+
+ var y = findLocalVariable(_resultUnit, 'y');
_assertTypeStr(y.type, 'int');
}
test_inferListLiteralNestedInMapLiteral() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
class Resource {}
class Folder extends Resource {}
@@ -2403,12 +2922,16 @@
[getResource('/pkgA/lib/')]
);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 161, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 313, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 467, 3),
+ ]);
}
test_inferLocalFunctionReturnType() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26414
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
main() {
f0 () => 42;
f1 () async => 42;
@@ -2421,33 +2944,47 @@
num f6() => 42;
f7 () => f7();
- f8 () => /*error:REFERENCED_BEFORE_DECLARATION*/f9();
+ f8 () => f9();
f9 () => f5();
}
-''');
- _assertTypeStr(findLocalFunction(unit, 'f0').type, 'int Function()');
- _assertTypeStr(
- findLocalFunction(unit, 'f1').type, 'Future<int> Function()');
+''', [
+ error(HintCode.UNUSED_ELEMENT, 11, 2),
+ error(HintCode.UNUSED_ELEMENT, 26, 2),
+ error(HintCode.UNUSED_ELEMENT, 48, 2),
+ error(HintCode.UNUSED_ELEMENT, 71, 2),
+ error(HintCode.UNUSED_ELEMENT, 100, 2),
+ error(HintCode.UNUSED_ELEMENT, 162, 2),
+ error(HintCode.UNUSED_ELEMENT, 177, 2),
+ error(HintCode.UNUSED_ELEMENT, 194, 2),
+ error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 203, 2,
+ contextMessages: [message(testFilePath, 211, 2)]),
+ ]);
- _assertTypeStr(findLocalFunction(unit, 'f2').type, 'int Function()');
+ _assertTypeStr(findLocalFunction(_resultUnit, 'f0').type, 'int Function()');
_assertTypeStr(
- findLocalFunction(unit, 'f3').type, 'Future<int> Function()');
- _assertTypeStr(
- findLocalFunction(unit, 'f4').type, 'Iterable<int> Function()');
- _assertTypeStr(
- findLocalFunction(unit, 'f5').type, 'Stream<int> Function()');
+ findLocalFunction(_resultUnit, 'f1').type, 'Future<int> Function()');
- _assertTypeStr(findLocalFunction(unit, 'f6').type, 'num Function()');
+ _assertTypeStr(findLocalFunction(_resultUnit, 'f2').type, 'int Function()');
+ _assertTypeStr(
+ findLocalFunction(_resultUnit, 'f3').type, 'Future<int> Function()');
+ _assertTypeStr(
+ findLocalFunction(_resultUnit, 'f4').type, 'Iterable<int> Function()');
+ _assertTypeStr(
+ findLocalFunction(_resultUnit, 'f5').type, 'Stream<int> Function()');
+
+ _assertTypeStr(findLocalFunction(_resultUnit, 'f6').type, 'num Function()');
// Recursive cases: these infer in declaration order.
- _assertTypeStr(findLocalFunction(unit, 'f7').type, 'dynamic Function()');
- _assertTypeStr(findLocalFunction(unit, 'f8').type, 'dynamic Function()');
_assertTypeStr(
- findLocalFunction(unit, 'f9').type, 'Stream<int> Function()');
+ findLocalFunction(_resultUnit, 'f7').type, 'dynamic Function()');
+ _assertTypeStr(
+ findLocalFunction(_resultUnit, 'f8').type, 'dynamic Function()');
+ _assertTypeStr(
+ findLocalFunction(_resultUnit, 'f9').type, 'Stream<int> Function()');
}
test_inferParameterType_setter_fromField() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C extends D {
set foo(x) {}
}
@@ -2455,12 +2992,12 @@
int foo;
}
''');
- var f = mainUnit.getType('C').accessors[0];
+ var f = _resultUnitElement.getType('C').accessors[0];
_assertTypeStr(f.type, 'void Function(int)');
}
test_inferParameterType_setter_fromSetter() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C extends D {
set foo(x) {}
}
@@ -2468,12 +3005,12 @@
set foo(int x) {}
}
''');
- var f = mainUnit.getType('C').accessors[0];
+ var f = _resultUnitElement.getType('C').accessors[0];
_assertTypeStr(f.type, 'void Function(int)');
}
test_inferred_nonstatic_field_depends_on_static_field_complex() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
static var x = 'x';
var y = {
@@ -2482,49 +3019,55 @@
};
}
''');
- var x = mainUnit.getType('C').fields[0];
+ var x = _resultUnitElement.getType('C').fields[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'String');
- var y = mainUnit.getType('C').fields[1];
+ var y = _resultUnitElement.getType('C').fields[1];
expect(y.name, 'y');
_assertTypeStr(y.type, 'Map<String, Map<String, String>>');
}
test_inferred_nonstatic_field_depends_on_toplevel_var_simple() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
var x = 'x';
class C {
var y = x;
}
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'String');
- var y = mainUnit.getType('C').fields[0];
+ var y = _resultUnitElement.getType('C').fields[0];
expect(y.name, 'y');
_assertTypeStr(y.type, 'String');
}
test_inferredInitializingFormalChecksDefaultValue() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class Foo {
var x = 1;
- Foo([this.x = /*error:INVALID_ASSIGNMENT*/"1"]);
-}''');
+ Foo([this.x = "1"]);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 41, 3),
+ ]);
}
test_inferredType_blockClosure_noArgs_noReturn() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var f = () {};
}
-''');
- var f = findLocalVariable(unit, 'f');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var f = findLocalVariable(_resultUnit, 'f');
_assertTypeStr(f.type, 'Null Function()');
}
test_inferredType_cascade() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class A {
int a;
List<int> b;
@@ -2532,25 +3075,25 @@
}
var v = new A()..a = 1..b.add(2)..m();
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'A');
}
test_inferredType_customBinaryOp() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
bool operator*(C other) => true;
}
C c;
var x = c*c;
''');
- var x = mainUnit.topLevelVariables[1];
+ var x = _resultUnitElement.topLevelVariables[1];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_customBinaryOp_viaInterface() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class I {
bool operator*(C other) => true;
}
@@ -2558,13 +3101,13 @@
C c;
var x = c*c;
''');
- var x = mainUnit.topLevelVariables[1];
+ var x = _resultUnitElement.topLevelVariables[1];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_customIndexOp() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
bool operator[](int index) => true;
}
@@ -2572,14 +3115,17 @@
C c;
var x = c[0];
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 72, 1),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_customIndexOp_viaInterface() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class I {
bool operator[](int index) => true;
}
@@ -2588,27 +3134,30 @@
C c;
var x = c[0];
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 105, 1),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_customUnaryOp() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
bool operator-() => true;
}
C c;
var x = -c;
''');
- var x = mainUnit.topLevelVariables[1];
+ var x = _resultUnitElement.topLevelVariables[1];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_customUnaryOp_viaInterface() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class I {
bool operator-() => true;
}
@@ -2616,26 +3165,26 @@
C c;
var x = -c;
''');
- var x = mainUnit.topLevelVariables[1];
+ var x = _resultUnitElement.topLevelVariables[1];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_extractMethodTearOff() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
bool g() => true;
}
C f() => null;
var x = f().g;
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool Function()');
}
test_inferredType_extractMethodTearOff_viaInterface() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class I {
bool g() => true;
}
@@ -2643,34 +3192,34 @@
C f() => null;
var x = f().g;
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool Function()');
}
test_inferredType_fromTopLevelExecutableTearoff() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
var v = print;
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'void Function(Object)');
}
test_inferredType_invokeMethod() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
bool g() => true;
}
C f() => null;
var x = f().g();
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_invokeMethod_viaInterface() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class I {
bool g() => true;
}
@@ -2678,139 +3227,139 @@
C f() => null;
var x = f().g();
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'bool');
}
test_inferredType_isEnum() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
enum E { v1 }
final x = E.v1;
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'E');
}
test_inferredType_isEnumValues() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
enum E { v1 }
final x = E.values;
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'List<E>');
}
test_inferredType_isTypedef() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
typedef void F();
final x = <String, F>{};
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'Map<String, void Function()>');
}
test_inferredType_isTypedef_parameterized() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
typedef T F<T>();
final x = <String, F<int>>{};
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'Map<String, int Function()>');
}
test_inferredType_usesSyntheticFunctionType() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
int f() => null;
String g() => null;
var v = [f, g];
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'List<Object Function()>');
}
test_inferredType_usesSyntheticFunctionType_functionTypedParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
int f(int x(String y)) => null;
String g(int x(String y)) => null;
var v = [f, g];
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'List<Object Function(int Function(String))>');
}
test_inferredType_usesSyntheticFunctionType_namedParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
int f({int x}) => null;
String g({int x}) => null;
var v = [f, g];
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'List<Object Function({int x})>');
}
test_inferredType_usesSyntheticFunctionType_positionalParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
int f([int x]) => null;
String g([int x]) => null;
var v = [f, g];
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'List<Object Function([int])>');
}
test_inferredType_usesSyntheticFunctionType_requiredParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
int f(int x) => null;
String g(int x) => null;
var v = [f, g];
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'List<Object Function(int)>');
}
test_inferredType_viaClosure_multipleLevelsOfNesting() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
static final f = (bool b) =>
(int i) => {i: b};
}
''');
- var f = mainUnit.getType('C').fields[0];
+ var f = _resultUnitElement.getType('C').fields[0];
_assertTypeStr(f.type, 'Map<int, bool> Function(int) Function(bool)');
}
test_inferredType_viaClosure_typeDependsOnArgs() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
static final f = (bool b) => b;
}
''');
- var f = mainUnit.getType('C').fields[0];
+ var f = _resultUnitElement.getType('C').fields[0];
_assertTypeStr(f.type, 'bool Function(bool)');
}
test_inferredType_viaClosure_typeIndependentOfArgs_field() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
static final f = (bool b) => 1;
}
''');
- var f = mainUnit.getType('C').fields[0];
+ var f = _resultUnitElement.getType('C').fields[0];
_assertTypeStr(f.type, 'int Function(bool)');
}
test_inferredType_viaClosure_typeIndependentOfArgs_topLevel() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
final f = (bool b) => 1;
''');
- var f = mainUnit.topLevelVariables[0];
+ var f = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(f.type, 'int Function(bool)');
}
test_inferReturnOfStatementLambda() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26139
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
List<String> strings() {
var stuff = [].expand((i) {
return <String>[];
@@ -2821,23 +3370,26 @@
}
test_inferStaticsTransitively() async {
- addFile('''
+ newFile('$testPackageLibPath/b.dart', content: '''
final b1 = 2;
-''', name: '/b.dart');
- addFile('''
-import 'main.dart';
+''');
+
+ newFile('$testPackageLibPath/a.dart', content: '''
+import 'test.dart';
import 'b.dart';
final a1 = m2;
class A {
static final a2 = b1;
}
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertNoErrorsInCode('''
import 'a.dart';
final m1 = a1;
final m2 = A.a2;
foo() {
+ // ignore:unused_local_variable
int i;
i = m1;
}
@@ -2845,7 +3397,7 @@
}
test_inferStaticsTransitively2() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
const x1 = 1;
final x2 = 1;
final y1 = x1;
@@ -2856,18 +3408,21 @@
i = y1;
i = y2;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 73, 1),
+ ]);
}
test_inferStaticsTransitively3() async {
- addFile('''
+ newFile('$testPackageLibPath/a.dart', content: '''
const a1 = 3;
const a2 = 4;
class A {
static const a3 = null;
}
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertNoErrorsInCode('''
import 'a.dart' show a1, A;
import 'a.dart' as p show a2, A;
const t1 = 1;
@@ -2878,6 +3433,7 @@
const t6 = p.A.a3;
foo() {
+ // ignore:unused_local_variable
int i;
i = t1;
i = t2;
@@ -2888,10 +3444,11 @@
}
test_inferStaticsWithMethodInvocations() async {
- addFile('''
+ newFile('$testPackageLibPath/a.dart', content: '''
m3(String a, String b, [a1,a2]) {}
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertNoErrorsInCode('''
import 'a.dart';
class T {
static final T foo = m1(m2(m3('', '')));
@@ -2902,7 +3459,7 @@
}
test_inferTypeOnOverriddenFields2() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
int x = 2;
}
@@ -2912,14 +3469,18 @@
}
foo() {
- String y = /*error:INVALID_ASSIGNMENT*/new B().x;
+ String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 80, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 84, 9),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 101, 1),
+ ]);
}
test_inferTypeOnOverriddenFields4() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
final int x = 2;
}
@@ -2929,83 +3490,108 @@
}
foo() {
- String y = /*error:INVALID_ASSIGNMENT*/new B().x;
+ String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 93, 9),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 110, 1),
+ ]);
}
test_inferTypeOnVar() async {
// Error also expected when declared type is `int`.
- await checkFileElement('''
+ await assertErrorsInCode('''
test1() {
int x = 3;
- x = /*error:INVALID_ASSIGNMENT*/"hi";
+ x = "hi";
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 16, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 29, 4),
+ ]);
}
test_inferTypeOnVar2() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
test2() {
var x = 3;
- x = /*error:INVALID_ASSIGNMENT*/"hi";
+ x = "hi";
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 16, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 29, 4),
+ ]);
}
test_inferTypeOnVarFromField() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
int x = 0;
test1() {
var a = x;
- a = /*error:INVALID_ASSIGNMENT*/"hi";
+ a = "hi";
a = 3;
var b = y;
- b = /*error:INVALID_ASSIGNMENT*/"hi";
+ b = "hi";
b = 4;
var c = z;
- c = /*error:INVALID_ASSIGNMENT*/"hi";
+ c = "hi";
c = 4;
}
int y; // field def after use
final z = 42; // should infer `int`
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 44, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 59, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 84, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 99, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 124, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 139, 4),
+ ]);
}
test_inferTypeOnVarFromTopLevel() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
int x = 0;
test1() {
var a = x;
- a = /*error:INVALID_ASSIGNMENT*/"hi";
+ a = "hi";
a = 3;
var b = y;
- b = /*error:INVALID_ASSIGNMENT*/"hi";
+ b = "hi";
b = 4;
var c = z;
- c = /*error:INVALID_ASSIGNMENT*/"hi";
+ c = "hi";
c = 4;
}
int y = 0; // field def after use
final z = 42; // should infer `int`
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 28, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 41, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 75, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 96, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 109, 4),
+ ]);
}
test_inferTypeRegardlessOfDeclarationOrderOrCycles() async {
- addFile('''
-import 'main.dart';
+ newFile('$testPackageLibPath/a.dart', content: '''
+import 'test.dart';
class B extends A { }
-''', name: '/b.dart');
- await checkFileElement('''
-import 'b.dart';
+''');
+
+ await assertErrorsInCode('''
+import 'a.dart';
class C extends B {
get x => null;
}
@@ -3014,13 +3600,17 @@
}
foo() {
int y = new C().x;
- String z = /*error:INVALID_ASSIGNMENT*/new C().x;
+ String z = new C().x;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 100, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 124, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 128, 9),
+ ]);
}
test_inferTypesOnGenericInstantiations_3() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A<T> {
final T x = null;
final T w = null;
@@ -3028,18 +3618,23 @@
class B implements A<int> {
get x => 3;
- get w => /*error:RETURN_OF_INVALID_TYPE*/"hello";
+ get w => "hello";
}
foo() {
- String y = /*error:INVALID_ASSIGNMENT*/new B().x;
+ String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 109, 7),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 138, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 142, 9),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 159, 1),
+ ]);
}
test_inferTypesOnGenericInstantiations_4() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A<T> {
T x;
}
@@ -3050,14 +3645,18 @@
}
foo() {
- int y = /*error:INVALID_ASSIGNMENT*/new B<String>().x;
+ int y = new B<String>().x;
String z = new B<String>().x;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 87, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 91, 17),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 119, 1),
+ ]);
}
test_inferTypesOnGenericInstantiations_5() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
abstract class I<E> {
String m(a, String f(v, E e));
}
@@ -3079,38 +3678,47 @@
}
foo () {
- int y = /*error:INVALID_ASSIGNMENT*/new B().m(null, null);
+ int y = new B().m(null, null);
String z = new B().m(null, null);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 310, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 314, 21),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 346, 1),
+ ]);
}
test_inferTypesOnGenericInstantiations_infer() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A<T> {
final T x = null;
}
class B implements A<int> {
- dynamic get /*error:INVALID_OVERRIDE*/x => 3;
+ dynamic get x => 3;
}
foo() {
String y = new B().x;
int z = new B().x;
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 78, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 106, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 127, 1),
+ ]);
}
test_inferTypesOnGenericInstantiationsInLibraryCycle() async {
// Note: this is a regression test for bug #48.
- addFile('''
-import 'main.dart';
+ newFile('$testPackageLibPath/a.dart', content: '''
+import 'test.dart';
abstract class I<E> {
A<E> m(a, String f(v, int e));
}
-''', name: '/a.dart');
- await checkFileElement('''
+''');
+
+ await assertErrorsInCode('''
import 'a.dart';
abstract class A<E> implements I<E> {
@@ -3131,14 +3739,18 @@
}
foo () {
- int y = /*error:INVALID_ASSIGNMENT*/new B<String>().m(null, null).value;
+ int y = new B<String>().m(null, null).value;
String z = new B<String>().m(null, null).value;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 264, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 268, 35),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 314, 1),
+ ]);
}
test_inferTypesOnLoopIndices_forEachLoop() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class Foo {
int bar = 42;
}
@@ -3146,7 +3758,7 @@
class Bar<T extends Iterable<String>> {
void foo(T t) {
for (var i in t) {
- int x = /*error:INVALID_ASSIGNMENT*/i;
+ int x = i;
}
}
}
@@ -3154,7 +3766,7 @@
class Baz<T, E extends Iterable<T>, S extends E> {
void foo(S t) {
for (var i in t) {
- int x = /*error:INVALID_ASSIGNMENT*/i;
+ int x = i;
T y = i;
}
}
@@ -3163,14 +3775,14 @@
test() {
var list = <Foo>[];
for (var x in list) {
- String y = /*error:INVALID_ASSIGNMENT*/x;
+ String y = x;
}
for (dynamic x in list) {
String y = x;
}
- for (String x in /*error:FOR_IN_OF_INVALID_ELEMENT_TYPE*/list) {
+ for (String x in list) {
String y = x;
}
@@ -3191,7 +3803,7 @@
var map = <String, Foo>{};
// Error: map must be an Iterable.
- for (var x in /*error:FOR_IN_OF_INVALID_TYPE*/map) {
+ for (var x in map) {
String y = x;
}
@@ -3201,31 +3813,50 @@
String y = x;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 122, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 126, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 244, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 248, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 259, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 345, 1),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 349, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 396, 1),
+ error(CompileTimeErrorCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 427, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 446, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 497, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 565, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 634, 1),
+ error(CompileTimeErrorCode.FOR_IN_OF_INVALID_TYPE, 728, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 746, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 897, 1),
+ ]);
}
test_inferTypesOnLoopIndices_forLoopWithInference() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
test() {
for (var i = 0; i < 10; i++) {
int j = i + 1;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 50, 1),
+ ]);
}
test_inferVariableVoid() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
void f() {}
var x = f();
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
expect(x.name, 'x');
_assertTypeStr(x.type, 'void');
}
test_lambdaDoesNotHavePropagatedTypeHint() async {
- await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
List<String> getListOfString() => const <String>[];
void foo() {
@@ -3246,141 +3877,176 @@
}
test_listLiterals() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
test1() {
var x = [1, 2, 3];
- x.add(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi');
- x.add(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/4.0);
+ x.add('hi');
+ x.add(4.0);
x.add(4);
List<num> y = x;
}
test2() {
var x = [1, 2.0, 3];
- x.add(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi');
+ x.add('hi');
x.add(4.0);
List<int> y = x;
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 39, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 54, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 84, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 134, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 167, 1),
+ ]);
}
test_listLiterals_topLevel() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
var x1 = [1, 2, 3];
test1() {
- x1.add(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi');
- x1.add(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/4.0);
+ x1.add('hi');
+ x1.add(4.0);
x1.add(4);
List<num> y = x1;
}
var x2 = [1, 2.0, 3];
test2() {
- x2.add(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi');
+ x2.add('hi');
x2.add(4.0);
List<int> y = x2;
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 39, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 55, 3),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 86, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 137, 4),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 171, 1),
+ ]);
}
test_listLiteralsCanInferNull_topLevel() async {
- var unit = await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var x = [null];
''');
- var x = unit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'List<Null>');
}
test_listLiteralsCanInferNullBottom() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
test1() {
var x = [null];
- x.add(/*error:INVALID_CAST_LITERAL*/42);
+ x.add(42);
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL, 36, 2),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'List<Null>');
}
test_mapLiterals() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
test1() {
var x = { 1: 'x', 2: 'y' };
x[3] = 'z';
- x[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'] = 'w';
- x[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/4.0] = 'u';
- x[3] = /*error:INVALID_ASSIGNMENT*/42;
+ x['hi'] = 'w';
+ x[4.0] = 'u';
+ x[3] = 42;
Map<num, String> y = x;
}
test2() {
var x = { 1: 'x', 2: 'y', 3.0: new RegExp('.') };
x[3] = 'z';
- x[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'] = 'w';
+ x['hi'] = 'w';
x[4.0] = 'u';
- x[3] = /*error:INVALID_ASSIGNMENT*/42;
+ x[3] = 42;
Pattern p = null;
x[2] = p;
Map<int, String> y = x;
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 58, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 75, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 96, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 119, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 209, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 247, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 302, 1),
+ ]);
}
test_mapLiterals_topLevel() async {
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
var x1 = { 1: 'x', 2: 'y' };
test1() {
x1[3] = 'z';
- x1[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'] = 'w';
- x1[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/4.0] = 'u';
- x1[3] = /*error:INVALID_ASSIGNMENT*/42;
+ x1['hi'] = 'w';
+ x1[4.0] = 'u';
+ x1[3] = 42;
Map<num, String> y = x1;
}
var x2 = { 1: 'x', 2: 'y', 3.0: new RegExp('.') };
test2() {
x2[3] = 'z';
- x2[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi'] = 'w';
+ x2['hi'] = 'w';
x2[4.0] = 'u';
- x2[3] = /*error:INVALID_ASSIGNMENT*/42;
+ x2[3] = 42;
Pattern p = null;
x2[2] = p;
Map<int, String> y = x2;
}
-''');
+''', [
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 59, 4),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 77, 3),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 99, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 122, 1),
+ error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 214, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 254, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 310, 1),
+ ]);
}
test_mapLiteralsCanInferNull() async {
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
test1() {
var x = { null: null };
- x[/*error:INVALID_CAST_LITERAL*/3] = /*error:INVALID_CAST_LITERAL*/'z';
+ x[3] = 'z';
}
-''');
- var x = findLocalVariable(unit, 'x');
+''', [
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL, 40, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL, 45, 3),
+ ]);
+
+ var x = findLocalVariable(_resultUnit, 'x');
_assertTypeStr(x.type, 'Map<Null, Null>');
}
test_mapLiteralsCanInferNull_topLevel() async {
- var unit = await checkFileElement(r'''
+ await assertNoErrorsInCode(r'''
var x = { null: null };
''');
- var x = unit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'Map<Null, Null>');
}
test_methodCall_withTypeArguments_instanceMethod() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
D<T> f<T>() => null;
}
class D<T> {}
var f = new C().f<int>();
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'D<int>');
}
test_methodCall_withTypeArguments_instanceMethod_identifierSequence() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
D<T> f<T>() => null;
}
@@ -3388,65 +4054,75 @@
C c;
var f = c.f<int>();
''');
- var v = mainUnit.topLevelVariables[1];
+ var v = _resultUnitElement.topLevelVariables[1];
expect(v.name, 'f');
_assertTypeStr(v.type, 'D<int>');
}
test_methodCall_withTypeArguments_staticMethod() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
static D<T> f<T>() => null;
}
class D<T> {}
var f = C.f<int>();
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'D<int>');
}
test_methodCall_withTypeArguments_topLevelFunction() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
D<T> f<T>() => null;
class D<T> {}
var g = f<int>();
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'D<int>');
}
test_noErrorWhenDeclaredTypeIsNumAndAssignedNull() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
test1() {
num x = 3;
x = null;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 16, 1),
+ ]);
}
test_nullCoalescingOperator() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26552
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
main() {
List<int> x;
var y = x ?? [];
List<int> z = y;
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 55, 1),
+ ]);
+ }
+
+ test_nullCoalescingOperator2() async {
// Don't do anything if we already have a context type.
- var unit = await checkFile(r'''
+ await assertErrorsInCode(r'''
main() {
List<int> x;
List<num> y = x ?? [];
}
-''');
- var y = findLocalVariable(unit, 'y');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 36, 1),
+ ]);
+
+ var y = findLocalVariable(_resultUnit, 'y');
_assertTypeStr(y.initializer.returnType, 'List<num>');
}
test_nullLiteralShouldNotInferAsBottom() async {
// Regression test for https://github.com/dart-lang/dev_compiler/issues/47
- await checkFileElement(r'''
+ await assertErrorsInCode(r'''
var h = null;
void foo(int f(Object _)) {}
@@ -3454,7 +4130,7 @@
var f = (Object x) => null;
String y = f(42);
- f = (x) => /*error:INVALID_CAST_LITERAL*/'hello';
+ f = (x) => 'hello';
var g = null;
g = 'hello';
@@ -3466,11 +4142,14 @@
foo((x) => null);
foo((x) => throw "not implemented");
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 92, 1),
+ error(CompileTimeErrorCode.INVALID_CAST_LITERAL, 117, 7),
+ ]);
}
test_propagateInferenceToFieldInClass() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
int x = 2;
}
@@ -3481,11 +4160,13 @@
print(a.x); // doesn't require dynamic invoke
print(a.x + 2); // ok to use in bigger expression
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 1),
+ ]);
}
test_propagateInferenceToFieldInClassDynamicWarnings() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
int x = 2;
}
@@ -3496,27 +4177,32 @@
print(a.x);
print((a.x) + 2);
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ ]);
}
test_propagateInferenceTransitively() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class A {
int x = 2;
}
test5() {
var a1 = new A();
- a1.x = /*error:INVALID_ASSIGNMENT*/"hi";
+ a1.x = "hi";
A a2 = new A();
- a2.x = /*error:INVALID_ASSIGNMENT*/"hi";
+ a2.x = "hi";
}
-''');
+''', [
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 65, 4),
+ error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 99, 4),
+ ]);
}
test_propagateInferenceTransitively2() async {
- await checkFileElement('''
+ await assertNoErrorsInCode('''
class A {
int x = 42;
}
@@ -3544,16 +4230,16 @@
}
test_referenceToTypedef() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
typedef void F();
final x = F;
''');
- var x = mainUnit.topLevelVariables[0];
+ var x = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(x.type, 'Type');
}
test_refineBinaryExpressionType_typeParameter_T_double() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class C<T extends num> {
T a;
@@ -3564,11 +4250,16 @@
double r4 = a / b;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 66, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 112, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 135, 2),
+ ]);
}
test_refineBinaryExpressionType_typeParameter_T_int() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class C<T extends num> {
T a;
@@ -3584,11 +4275,15 @@
a *= b;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 76, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 94, 2),
+ ]);
}
test_refineBinaryExpressionType_typeParameter_T_T() async {
- await checkFileElement('''
+ await assertErrorsInCode('''
class C<T extends num> {
T a;
@@ -3604,58 +4299,65 @@
a *= b;
}
}
-''');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 56, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 74, 2),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 92, 2),
+ ]);
}
test_staticMethod_tearoff() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
const v = C.f;
class C {
static int f(String s) => null;
}
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
_assertTypeStr(v.type, 'int Function(String)');
}
test_unsafeBlockClosureInference_closureCall() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26962
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = ((x) => 1.0)(() { return 1; });
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
expect(v.name, 'v');
_assertTypeStr(v.type, 'double');
}
test_unsafeBlockClosureInference_constructorCall_explicitDynamicParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C<T> {
C(T x());
}
var v = new C<dynamic>(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'C<dynamic>');
}
test_unsafeBlockClosureInference_constructorCall_explicitTypeParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C<T> {
C(T x());
}
var v = new C<int>(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'C<int>');
}
test_unsafeBlockClosureInference_constructorCall_implicitTypeParam() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C<T> {
C(T x());
}
@@ -3665,30 +4367,33 @@
return 1;
});
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 42, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
expect(v.name, 'v');
_assertTypeStr(v.type, 'C<int>');
}
test_unsafeBlockClosureInference_constructorCall_noTypeParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
C(x());
}
var v = new C(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'C');
}
test_unsafeBlockClosureInference_functionCall_explicitDynamicParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
List<T> f<T>(T g()) => <T>[g()];
var v = f<dynamic>(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'List<dynamic>');
}
@@ -3696,31 +4401,31 @@
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/25824')
test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr1() async {
// Note: (f<dynamic>) is not a valid syntax.
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
List<T> f<T>(T g()) => <T>[g()];
var v = (f<dynamic>)(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'List<dynamic>');
}
test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr2() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
List<T> f<T>(T g()) => <T>[g()];
var v = (f)<dynamic>(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'List<dynamic>');
}
test_unsafeBlockClosureInference_functionCall_explicitTypeParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
List<T> f<T>(T g()) => <T>[g()];
var v = f<int>(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'List<int>');
}
@@ -3728,27 +4433,27 @@
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/25824')
test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr1() async {
// Note: (f<int>) is not a valid syntax.
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
List<T> f<T>(T g()) => <T>[g()];
var v = (f<int>)(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'List<int>');
}
test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
List<T> f<T>(T g()) => <T>[g()];
var v = (f)<int>(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'List<int>');
}
test_unsafeBlockClosureInference_functionCall_implicitTypeParam() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = f(
() {
@@ -3756,13 +4461,16 @@
});
}
List<T> f<T>(T g()) => <T>[g()];
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int>');
}
test_unsafeBlockClosureInference_functionCall_implicitTypeParam_viaExpr() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = (f)(
() {
@@ -3770,129 +4478,162 @@
});
}
List<T> f<T>(T g()) => <T>[g()];
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int>');
}
test_unsafeBlockClosureInference_functionCall_noTypeParam() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = f(() { return 1; });
}
double f(x) => 1.0;
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'double');
}
test_unsafeBlockClosureInference_functionCall_noTypeParam_viaExpr() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = (f)(() { return 1; });
}
double f(x) => 1.0;
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'double');
}
test_unsafeBlockClosureInference_inList_dynamic() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = <dynamic>[() { return 1; }];
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<dynamic>');
}
test_unsafeBlockClosureInference_inList_typed() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
typedef int F();
main() {
var v = <F>[() { return 1; }];
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 32, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int Function()>');
}
test_unsafeBlockClosureInference_inList_untyped() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = [
() {
return 1;
}];
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int Function()>');
}
test_unsafeBlockClosureInference_inMap_dynamic() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = <int, dynamic>{1: () { return 1; }};
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'Map<int, dynamic>');
}
test_unsafeBlockClosureInference_inMap_typed() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
typedef int F();
main() {
var v = <int, F>{1: () { return 1; }};
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 32, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'Map<int, int Function()>');
}
test_unsafeBlockClosureInference_inMap_untyped() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
main() {
var v = {
1: () {
return 1;
}};
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'Map<int, int Function()>');
}
test_unsafeBlockClosureInference_methodCall_explicitDynamicParam() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
List<T> f<T>(T g()) => <T>[g()];
}
main() {
var v = new C().f<dynamic>(() { return 1; });
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<dynamic>');
}
test_unsafeBlockClosureInference_methodCall_explicitTypeParam() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
List<T> f<T>(T g()) => <T>[g()];
}
main() {
var v = new C().f<int>(() { return 1; });
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int>');
}
test_unsafeBlockClosureInference_methodCall_implicitTypeParam() async {
- var unit = await checkFile('''
+ await assertErrorsInCode('''
class C {
List<T> f<T>(T g()) => <T>[g()];
}
@@ -3902,25 +4643,28 @@
return 1;
});
}
-''');
- var v = findLocalVariable(unit, 'v');
+''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 62, 1),
+ ]);
+
+ var v = findLocalVariable(_resultUnit, 'v');
_assertTypeStr(v.type, 'List<int>');
}
test_unsafeBlockClosureInference_methodCall_noTypeParam() async {
- var mainUnit = await checkFileElement('''
+ await assertNoErrorsInCode('''
class C {
double f(x) => 1.0;
}
var v = new C().f(() { return 1; });
''');
- var v = mainUnit.topLevelVariables[0];
+ var v = _resultUnitElement.topLevelVariables[0];
expect(v.name, 'v');
_assertTypeStr(v.type, 'double');
}
test_voidReturnTypeEquivalentToDynamic() async {
- var unit = await checkFileElement(r'''
+ await assertErrorsInCode(r'''
T run<T>(T f()) {
print("running");
var t = f();
@@ -3942,14 +4686,28 @@
y = 123;
y = 'hi';
}
- ''');
+ ''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 259, 1),
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 297, 1),
+ ]);
- var x = unit.topLevelVariables[0];
- var y = unit.topLevelVariables[1];
+ var x = _resultUnitElement.topLevelVariables[0];
+ var y = _resultUnitElement.topLevelVariables[1];
_assertTypeStr(x.type, 'dynamic');
_assertTypeStr(y.type, 'void');
}
+ Future<void> _assertNoErrors(String code) async {
+ await resolveTestCode(code);
+ assertErrorsInList(
+ result.errors.where((e) {
+ return e.errorCode != HintCode.UNUSED_LOCAL_VARIABLE &&
+ e.errorCode is! TodoCode;
+ }).toList(),
+ [],
+ );
+ }
+
void _assertTypeStr(DartType type, String expected) {
var typeStr = type.getDisplayString(withNullability: false);
expect(typeStr, expected);
diff --git a/pkg/analyzer/test/src/task/strong/strong_test_helper.dart b/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
deleted file mode 100644
index aa6edf5..0000000
--- a/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
+++ /dev/null
@@ -1,441 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// TODO(jmesserly): this file needs to be refactored, it's a port from
-// package:dev_compiler's tests
-import 'dart:async';
-import 'dart:collection';
-
-import 'package:analyzer/dart/analysis/features.dart';
-import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer/dart/ast/token.dart';
-import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/error/error.dart';
-import 'package:analyzer/file_system/file_system.dart';
-import 'package:analyzer/source/error_processor.dart';
-import 'package:analyzer/src/context/packages.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/dart/ast/token.dart';
-import 'package:analyzer/src/error/codes.dart';
-import 'package:analyzer/src/file_system/file_system.dart';
-import 'package:analyzer/src/generated/engine.dart';
-import 'package:analyzer/src/generated/source.dart';
-import 'package:analyzer/src/source/package_map_resolver.dart';
-import 'package:analyzer/src/test_utilities/mock_sdk.dart';
-import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
-import 'package:source_span/source_span.dart';
-import 'package:test/test.dart';
-
-SourceSpanWithContext _createSpanHelper(
- LineInfo lineInfo, int start, Source source, String content,
- {int end}) {
- var startLoc = _locationForOffset(lineInfo, source.uri, start);
- var endLoc = _locationForOffset(lineInfo, source.uri, end ?? start);
-
- var lineStart = startLoc.offset - startLoc.column;
- // Find the end of the line. This is not exposed directly on LineInfo, but
- // we can find it pretty easily.
- // TODO(jmesserly): for now we do the simple linear scan. Ideally we can get
- // some help from the LineInfo API.
- int lineEnd = endLoc.offset;
- int lineNum = lineInfo.getLocation(lineEnd).lineNumber;
- while (lineEnd < content.length &&
- lineInfo.getLocation(++lineEnd).lineNumber == lineNum) {}
-
- if (end == null) {
- end = lineEnd;
- endLoc = _locationForOffset(lineInfo, source.uri, lineEnd);
- }
-
- var text = content.substring(start, end);
- var lineText = content.substring(lineStart, lineEnd);
- return SourceSpanWithContext(startLoc, endLoc, text, lineText);
-}
-
-ErrorSeverity _errorSeverity(
- AnalysisOptions analysisOptions, AnalysisError error) {
- // TODO(brianwilkerson) Remove the if when top-level inference is made an
- // error again.
- if (error.errorCode.name.startsWith('TOP_LEVEL_')) {
- return ErrorSeverity.ERROR;
- }
- return ErrorProcessor.getProcessor(analysisOptions, error)?.severity ??
- error.errorCode.errorSeverity;
-}
-
-void _expectErrors(AnalysisOptions analysisOptions, CompilationUnit unit,
- Iterable<AnalysisError> actualErrors) {
- var expectedErrors = _findExpectedErrors(unit.beginToken);
-
- var actualMap = SplayTreeMap<int, List<AnalysisError>>();
- for (var e in actualErrors) {
- actualMap.putIfAbsent(e.offset, () => []).add(e);
- }
- var expectedMap = SplayTreeMap<int, List<_ErrorExpectation>>();
- for (var e in expectedErrors) {
- expectedMap.putIfAbsent(e.offset, () => []).add(e);
- }
-
- // Categorize the differences, if any.
- var unreported = <_ErrorExpectation>[];
- var different = <List<_ErrorExpectation>, List<AnalysisError>>{};
-
- expectedMap.forEach((offset, expectedList) {
- var actualList = actualMap[offset] ?? [];
-
- var unmatched = <_ErrorExpectation>[];
- for (var expected in expectedList) {
- var match = actualList.firstWhere(
- (a) => expected.matches(analysisOptions, a),
- orElse: () => null);
- if (match != null) {
- actualList.remove(match);
- if (actualList.isEmpty) actualMap.remove(offset);
- } else {
- unmatched.add(expected);
- }
- }
-
- if (actualList.isEmpty) {
- unreported.addAll(unmatched);
- } else if (unmatched.isNotEmpty) {
- different[unmatched] = actualList;
- actualMap.remove(offset);
- }
- });
-
- // Whatever is left was an unexpected error.
- List<AnalysisError> unexpected = actualMap.values.expand((a) => a).toList();
-
- if (unreported.isNotEmpty || unexpected.isNotEmpty || different.isNotEmpty) {
- _reportFailure(analysisOptions, unit, unreported, unexpected, different);
- }
-}
-
-List<_ErrorExpectation> _findExpectedErrors(Token beginToken) {
- var expectedErrors = <_ErrorExpectation>[];
-
- // Collect expectations like "error:STATIC_TYPE_ERROR" from comment tokens.
- for (Token t = beginToken; t.type != TokenType.EOF; t = t.next) {
- for (CommentToken c = t.precedingComments; c != null; c = c.next) {
- if (c.type == TokenType.MULTI_LINE_COMMENT) {
- String value = c.lexeme.substring(2, c.lexeme.length - 2);
- if (value.contains(':')) {
- int offset = t.offset;
- Token previous = t.previous;
- while (previous != null && previous.offset > c.offset) {
- offset = previous.offset;
- previous = previous.previous;
- }
- for (var expectCode in value.split(',')) {
- var expected = _ErrorExpectation.parse(offset, expectCode);
- if (expected != null) {
- expectedErrors.add(expected);
- }
- }
- }
- }
- }
- }
- return expectedErrors;
-}
-
-SourceLocation _locationForOffset(LineInfo lineInfo, Uri uri, int offset) {
- var loc = lineInfo.getLocation(offset);
- return SourceLocation(offset,
- sourceUrl: uri, line: loc.lineNumber - 1, column: loc.columnNumber - 1);
-}
-
-/// Returns all libraries transitively imported or exported from [start].
-Set<LibraryElement> _reachableLibraries(LibraryElement start) {
- Set<LibraryElement> results = <LibraryElement>{};
-
- void find(LibraryElement library) {
- if (results.add(library)) {
- library.importedLibraries.forEach(find);
- library.exportedLibraries.forEach(find);
- }
- }
-
- find(start);
- return results;
-}
-
-void _reportFailure(
- AnalysisOptions analysisOptions,
- CompilationUnit unit,
- List<_ErrorExpectation> unreported,
- List<AnalysisError> unexpected,
- Map<List<_ErrorExpectation>, List<AnalysisError>> different) {
- // Get the source code. This reads the data again, but it's safe because
- // all tests use memory file system.
- var sourceCode = unit.declaredElement.source.contents.data;
-
- String formatActualError(AnalysisError error) {
- int offset = error.offset;
- int length = error.length;
- var span = _createSpanHelper(
- unit.lineInfo, offset, unit.declaredElement.source, sourceCode,
- end: offset + length);
- var levelName = _errorSeverity(analysisOptions, error).displayName;
- return '@$offset $levelName:${error.errorCode.name}\n' +
- span.message(error.message);
- }
-
- String formatExpectedError(_ErrorExpectation error,
- {bool showSource = true}) {
- int offset = error.offset;
- var severity = error.severity.displayName;
- var result = '@$offset $severity:${error.typeName}';
- if (!showSource) return result;
- var span = _createSpanHelper(
- unit.lineInfo, offset, unit.declaredElement.source, sourceCode);
- return '$result\n${span.message('')}';
- }
-
- var message = StringBuffer();
- if (unreported.isNotEmpty) {
- message.writeln('Expected errors that were not reported:');
- unreported.map(formatExpectedError).forEach(message.writeln);
- message.writeln();
- }
- if (unexpected.isNotEmpty) {
- message.writeln('Errors that were not expected:');
- unexpected.map(formatActualError).forEach(message.writeln);
- message.writeln();
- }
- if (different.isNotEmpty) {
- message.writeln('Errors that were reported, but different than expected:');
- different.forEach((expected, actual) {
- // The source location is the same for the expected and actual, so we only
- // print it once.
- message.writeln('Expected: ' +
- expected
- .map((e) => formatExpectedError(e, showSource: false))
- .join(', '));
- message.writeln('Actual: ' + actual.map(formatActualError).join(', '));
- });
- message.writeln();
- }
- fail('Checker errors do not match expected errors:\n\n$message');
-}
-
-class AbstractStrongTest with ResourceProviderMixin {
- bool _checkCalled = true;
-
- AnalysisDriver _driver;
-
- Map<String, List<Folder>> packageMap;
-
- List<String> get enabledExperiments => [];
-
- /// Adds a file to check. The file should contain:
- ///
- /// * all expected failures are listed in the source code using comments
- /// immediately in front of the AST node that should contain the error.
- ///
- /// * errors are formatted as a token `severity:ErrorCode`, where
- /// `severity` is the ErrorSeverity the error would be reported at, and
- /// `ErrorCode` is the error code's name.
- ///
- /// For example to check that an assignment produces a type error, you can
- /// create a file like:
- ///
- /// addFile('''
- /// String x = /*error:STATIC_TYPE_ERROR*/3;
- /// ''');
- /// check();
- ///
- /// For a single file, you may also use [checkFile].
- void addFile(String content, {String name = '/main.dart'}) {
- name = name.replaceFirst(RegExp('^package:'), '/packages/');
- newFile(name, content: content);
- _checkCalled = false;
- }
-
- /// Run the checker on a program, staring from '/main.dart', and verifies that
- /// errors/warnings/hints match the expected value.
- ///
- /// See [addFile] for more information about how to encode expectations in
- /// the file text.
- ///
- /// Returns the main resolved library. This can be used for further checks.
- Future<CompilationUnit> check(
- {bool implicitCasts = true,
- bool implicitDynamic = true,
- bool strictInference = false,
- bool strictRawTypes = false}) async {
- _checkCalled = true;
-
- File mainFile = getFile('/main.dart');
- expect(mainFile.exists, true, reason: '`/main.dart` is missing');
-
- AnalysisOptionsImpl analysisOptions = AnalysisOptionsImpl();
- analysisOptions.implicitCasts = implicitCasts;
- analysisOptions.implicitDynamic = implicitDynamic;
- analysisOptions.strictInference = strictInference;
- analysisOptions.strictRawTypes = strictRawTypes;
- analysisOptions.contextFeatures = FeatureSet.fromEnableFlags(
- enabledExperiments,
- );
-
- var mockSdk = MockSdk(
- resourceProvider: resourceProvider,
- analysisOptions: analysisOptions,
- );
-
- SourceFactory sourceFactory = SourceFactory([
- DartUriResolver(mockSdk),
- PackageMapUriResolver(resourceProvider, packageMap),
- ResourceUriResolver(resourceProvider),
- ]);
-
- CompilationUnit mainUnit;
- StringBuffer logBuffer = StringBuffer();
- FileContentOverlay fileContentOverlay = FileContentOverlay();
- PerformanceLog log = PerformanceLog(logBuffer);
- AnalysisDriverScheduler scheduler = AnalysisDriverScheduler(log);
- _driver = AnalysisDriver(
- scheduler,
- log,
- resourceProvider,
- MemoryByteStore(),
- fileContentOverlay,
- null,
- sourceFactory,
- analysisOptions,
- packages: Packages.empty);
- scheduler.start();
-
- mainUnit = (await _driver.getResult(mainFile.path)).unit;
-
- bool isRelevantError(AnalysisError error) {
- var code = error.errorCode;
- // We don't care about these.
- if (code == HintCode.UNUSED_ELEMENT ||
- code == HintCode.UNUSED_FIELD ||
- code == HintCode.UNUSED_IMPORT ||
- code == HintCode.UNUSED_LOCAL_VARIABLE ||
- code == TodoCode.TODO) {
- return false;
- }
- if (strictInference || strictRawTypes) {
- // When testing strict-inference or strict-raw-types, ignore anything
- // else.
- return code.errorSeverity.ordinal > ErrorSeverity.INFO.ordinal ||
- code == HintCode.INFERENCE_FAILURE_ON_COLLECTION_LITERAL ||
- code == HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION ||
- code == HintCode.STRICT_RAW_TYPE;
- }
- return true;
- }
-
- // Extract expectations from the comments in the test files, and
- // check that all errors we emit are included in the expected map.
- LibraryElement mainLibrary = mainUnit.declaredElement.library;
- Set<LibraryElement> allLibraries = _reachableLibraries(mainLibrary);
-
- for (LibraryElement library in allLibraries) {
- for (CompilationUnitElement unit in library.units) {
- var source = unit.source;
- if (source.uri.scheme == 'dart') {
- continue;
- }
-
- var analysisResult = await _resolve(source);
-
- Iterable<AnalysisError> errors =
- analysisResult.errors.where(isRelevantError);
- _expectErrors(analysisOptions, analysisResult.unit, errors);
- }
- }
-
- return mainUnit;
- }
-
- /// Adds a file using [addFile] and calls [check].
- ///
- /// Also returns the resolved compilation unit.
- Future<CompilationUnit> checkFile(String content,
- {bool implicitCasts = true, bool implicitDynamic = true}) async {
- addFile(content);
- return await check(
- implicitCasts: implicitCasts,
- implicitDynamic: implicitDynamic,
- );
- }
-
- void setUp() {
- packageMap = {
- 'meta': [getFolder('/.pub-cache/meta/lib')],
- };
- }
-
- void tearDown() {
- // This is a sanity check, in case only addFile is called.
- expect(_checkCalled, true, reason: 'must call check() method in test case');
- _driver?.dispose();
- AnalysisEngine.instance.clearCaches();
- }
-
- Future<_TestAnalysisResult> _resolve(Source source) async {
- var result = await _driver.getResult(source.fullName);
- return _TestAnalysisResult(source, result.unit, result.errors);
- }
-}
-
-/// Describes an expected message that should be produced by the checker.
-class _ErrorExpectation {
- final int offset;
- final ErrorSeverity severity;
- final String typeName;
-
- _ErrorExpectation(this.offset, this.severity, this.typeName);
-
- bool matches(AnalysisOptions options, AnalysisError e) {
- return _errorSeverity(options, e) == severity &&
- e.errorCode.name == typeName;
- }
-
- @override
- String toString() => '@$offset ${severity.displayName}: [$typeName]';
-
- static _ErrorExpectation parse(int offset, String descriptor) {
- descriptor = descriptor.trim();
- var tokens = descriptor.split(' ');
- if (tokens.length == 1) return _parse(offset, tokens[0]);
- expect(tokens.length, 4, reason: 'invalid error descriptor');
- expect(tokens[1], "should", reason: 'invalid error descriptor');
- expect(tokens[2], "be", reason: 'invalid error descriptor');
- if (tokens[0] == "pass") return null;
- // TODO(leafp) For now, we just use whatever the current expectation is,
- // eventually we could do more automated reporting here.
- return _parse(offset, tokens[0]);
- }
-
- static _ErrorExpectation _parse(offset, String descriptor) {
- var tokens = descriptor.split(':');
- expect(tokens.length, 2, reason: 'invalid error descriptor');
- var name = tokens[0].toUpperCase();
- var typeName = tokens[1];
-
- var level = ErrorSeverity.values
- .firstWhere((l) => l.name == name, orElse: () => null);
- expect(level, isNotNull,
- reason: 'invalid severity in error descriptor: `${tokens[0]}`');
- expect(typeName, isNotNull,
- reason: 'invalid type in error descriptor: ${tokens[1]}');
- return _ErrorExpectation(offset, level, typeName);
- }
-}
-
-class _TestAnalysisResult {
- final Source source;
- final CompilationUnit unit;
- final List<AnalysisError> errors;
- _TestAnalysisResult(this.source, this.unit, this.errors);
-}
diff --git a/pkg/front_end/lib/src/fasta/builder/field_builder.dart b/pkg/front_end/lib/src/fasta/builder/field_builder.dart
index cbcc354..59afedc 100644
--- a/pkg/front_end/lib/src/fasta/builder/field_builder.dart
+++ b/pkg/front_end/lib/src/fasta/builder/field_builder.dart
@@ -399,11 +399,16 @@
DartType get builtType => fieldType;
- @override
- List<ClassMember> get localMembers => _fieldEncoding.getLocalMembers(this);
+ List<ClassMember> _localMembers;
+ List<ClassMember> _localSetters;
@override
- List<ClassMember> get localSetters => _fieldEncoding.getLocalSetters(this);
+ List<ClassMember> get localMembers =>
+ _localMembers ??= _fieldEncoding.getLocalMembers(this);
+
+ @override
+ List<ClassMember> get localSetters =>
+ _localSetters ??= _fieldEncoding.getLocalSetters(this);
static String createFieldName(FieldNameType type, String name,
{bool isInstanceMember,
diff --git a/pkg/pkg.status b/pkg/pkg.status
index 52583d6..2656ab6 100644
--- a/pkg/pkg.status
+++ b/pkg/pkg.status
@@ -85,6 +85,8 @@
front_end/test/fasta/text_serialization_test: Pass, ExtraSlow
front_end/test/fasta/types/dart2js_benchmark_test: Pass, Slow
front_end/test/fasta/types/large_app_benchmark_test: Pass, ExtraSlow
+front_end/test/incremental_compiler_leak_test.dart: Pass, Slow
+front_end/test/incremental_dart2js_test.dart: Pass, Slow
front_end/test/minimal_incremental_kernel_generator_test: Slow, Pass
front_end/test/whole_program_test: Slow, Pass
front_end/testcases/*: Skip # These are not tests but input for tests.
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index bbd4a7a..00e51e3 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -61,11 +61,6 @@
# ...........packages
# ..........resources/
# ..........templates/
-# ......model/
-# ........lexeme/
-# ..........idx2word.json
-# ..........model.tflite
-# ..........word2idx.json
# ....include/
# ......dart_api.h
# ......dart_native_api.h
@@ -323,16 +318,6 @@
}
if (target_cpu == "x64") {
- copy_tree_specs += [
- {
- target = "copy_language_model"
- visibility = [ ":create_common_sdk" ]
- deps = [ ":copy_libraries" ]
- source = "../pkg/analysis_server/language_model"
- dest = "$root_out_dir/dart-sdk/bin/model"
- ignore_patterns = "{}"
- },
- ]
if (is_linux || is_android || is_fuchsia) {
copy_tree_specs += [
{
@@ -915,10 +900,7 @@
public_deps += [ ":copy_7zip" ]
}
if (target_cpu == "x64") {
- public_deps += [
- ":copy_language_model",
- ":copy_libtensorflowlite_c",
- ]
+ public_deps += [ ":copy_libtensorflowlite_c" ]
}
}
diff --git a/tools/VERSION b/tools/VERSION
index 5d4c061..2753997 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 10
PATCH 0
-PRERELEASE 12
+PRERELEASE 13
PRERELEASE_PATCH 0
\ No newline at end of file