Version 2.17.0-95.0.dev
Merge commit '7605a36ab3e1601ee561758fc6936c707c0f90c0' into 'dev'
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/sort_constructor_first.dart b/pkg/analysis_server/lib/src/services/correction/dart/sort_constructor_first.dart
new file mode 100644
index 0000000..3eb4641
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/correction/dart/sort_constructor_first.dart
@@ -0,0 +1,49 @@
+// Copyright (c) 2022, 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/correction/dart/abstract_producer.dart';
+import 'package:analysis_server/src/services/correction/fix.dart';
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
+import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
+import 'package:analyzer_plugin/utilities/range_factory.dart';
+
+class SortConstructorFirst extends CorrectionProducer {
+ @override
+ bool get canBeAppliedInBulk => true;
+
+ @override
+ bool get canBeAppliedToFile => true;
+
+ @override
+ FixKind get fixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST;
+
+ @override
+ FixKind get multiFixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST_MULTI;
+
+ @override
+ Future<void> compute(ChangeBuilder builder) async {
+ var constructor = coveredNode?.parent;
+ var clazz = constructor?.parent;
+ if (clazz is! ClassDeclaration || constructor is! ConstructorDeclaration) {
+ return;
+ }
+
+ await builder.addDartFileEdit(file, (builder) {
+ var deletionRange = range.endEnd(
+ constructor.beginToken.previous!,
+ constructor.endToken,
+ );
+
+ builder.addDeletion(deletionRange);
+ builder.addSimpleInsertion(
+ clazz.leftBracket.end,
+ utils.getRangeText(deletionRange),
+ );
+ });
+ }
+
+ /// Return an instance of this class. Used as a tear-off in `FixProcessor`.
+ static SortConstructorFirst newInstance() => SortConstructorFirst();
+}
diff --git a/pkg/analysis_server/lib/src/services/correction/fix.dart b/pkg/analysis_server/lib/src/services/correction/fix.dart
index 8a91925..874bbdb 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix.dart
@@ -1440,6 +1440,16 @@
DartFixKindPriority.IN_FILE,
'Move child properties to ends of arguments everywhere in file',
);
+ static const SORT_CONSTRUCTOR_FIRST = FixKind(
+ 'dart.fix.sort.sortConstructorFirst',
+ DartFixKindPriority.DEFAULT,
+ 'Move before other members',
+ );
+ static const SORT_CONSTRUCTOR_FIRST_MULTI = FixKind(
+ 'dart.fix.sort.sortConstructorFirst.multi',
+ DartFixKindPriority.DEFAULT,
+ 'Move all constructors before other members',
+ );
static const SORT_UNNAMED_CONSTRUCTOR_FIRST = FixKind(
'dart.fix.sort.sortUnnamedConstructorFirst',
DartFixKindPriority.DEFAULT,
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index a09d76c..6f03b72 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -170,6 +170,7 @@
import 'package:analysis_server/src/services/correction/dart/replace_with_tear_off.dart';
import 'package:analysis_server/src/services/correction/dart/replace_with_var.dart';
import 'package:analysis_server/src/services/correction/dart/sort_child_property_last.dart';
+import 'package:analysis_server/src/services/correction/dart/sort_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/sort_unnamed_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/update_sdk_constraints.dart';
import 'package:analysis_server/src/services/correction/dart/use_const.dart';
@@ -572,6 +573,9 @@
LintNames.sort_child_properties_last: [
SortChildPropertyLast.newInstance,
],
+ LintNames.sort_constructors_first: [
+ SortConstructorFirst.newInstance,
+ ],
LintNames.sort_unnamed_constructors_first: [
SortUnnamedConstructorFirst.newInstance,
],
diff --git a/pkg/analysis_server/test/src/services/correction/fix/sort_constructor_first_test.dart b/pkg/analysis_server/test/src/services/correction/fix/sort_constructor_first_test.dart
new file mode 100644
index 0000000..a1f240b
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/sort_constructor_first_test.dart
@@ -0,0 +1,97 @@
+// Copyright (c) 2022, 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/correction/fix.dart';
+import 'package:analysis_server/src/services/linter/lint_names.dart';
+import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import 'fix_processor.dart';
+
+void main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(SortConstructorFirstBulkTest);
+ defineReflectiveTests(SortConstructorFirstTest);
+ });
+}
+
+@reflectiveTest
+class SortConstructorFirstBulkTest extends BulkFixProcessorTest {
+ @override
+ String get lintCode => LintNames.sort_constructors_first;
+
+ Future<void> test_multiple_classes() async {
+ await resolveTestCode('''
+class A {
+ X() {}
+ A();
+}
+
+class B {
+ Y() {}
+ B();
+}
+''');
+ await assertHasFix('''
+class A {
+ A();
+ X() {}
+}
+
+class B {
+ B();
+ Y() {}
+}
+''');
+ }
+
+ Future<void> test_single_class() async {
+ await resolveTestCode('''
+class A {
+ X() {}
+
+ A();
+
+ Y() {}
+
+ A._();
+}
+''');
+ await assertHasFix('''
+class A {
+
+ A();
+
+ A._();
+ X() {}
+
+ Y() {}
+}
+''');
+ }
+}
+
+@reflectiveTest
+class SortConstructorFirstTest extends FixProcessorLintTest {
+ @override
+ FixKind get kind => DartFixKind.SORT_CONSTRUCTOR_FIRST;
+
+ @override
+ String get lintCode => LintNames.sort_constructors_first;
+
+ Future<void> test_one_fix() async {
+ await resolveTestCode('''
+class A {
+ X() {}
+ A();
+}
+''');
+ await assertHasFix('''
+class A {
+ A();
+ X() {}
+}
+''');
+ }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
index 4196118..c61f1a5 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
@@ -207,6 +207,7 @@
import 'replace_with_tear_off_test.dart' as replace_with_tear_off;
import 'replace_with_var_test.dart' as replace_with_var;
import 'sort_child_property_last_test.dart' as sort_properties_last;
+import 'sort_constructor_first_test.dart' as sort_constructor_first_test;
import 'sort_unnamed_constructor_first_test.dart'
as sort_unnamed_constructor_first_test;
import 'update_sdk_constraints_test.dart' as update_sdk_constraints;
@@ -400,6 +401,7 @@
replace_with_tear_off.main();
replace_with_var.main();
sort_properties_last.main();
+ sort_constructor_first_test.main();
sort_unnamed_constructor_first_test.main();
update_sdk_constraints.main();
use_const.main();
diff --git a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
index 29b2ae2..1202cc6 100644
--- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
+++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
@@ -623,7 +623,7 @@
.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY,
);
- var expressionValueType = _typeSystem.toLegacyType(
+ var expressionValueType = _typeSystem.toLegacyTypeIfOptOut(
expressionValue.type,
);
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 72131f5..0e8ee0a 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -2605,7 +2605,7 @@
DartType type,
) {
if (!isNonNullableByDefault) {
- type = toLegacyType(type);
+ type = toLegacyTypeIfOptOut(type);
}
var objType = obj.type;
return isSubtypeOf(objType, type);
diff --git a/pkg/analyzer/lib/src/dart/element/class_hierarchy.dart b/pkg/analyzer/lib/src/dart/element/class_hierarchy.dart
index 0a44e08..1a8a0ca 100644
--- a/pkg/analyzer/lib/src/dart/element/class_hierarchy.dart
+++ b/pkg/analyzer/lib/src/dart/element/class_hierarchy.dart
@@ -183,7 +183,7 @@
);
}
} else {
- var legacyType = _typeSystem.toLegacyType(type) as InterfaceType;
+ var legacyType = _typeSystem.toLegacyTypeIfOptOut(type) as InterfaceType;
if (_currentResult == null) {
_currentResult = legacyType;
} else {
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 681ae44..7179b60 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -1365,9 +1365,6 @@
}
@override
- bool get isStatic => false;
-
- @override
ElementKind get kind => ElementKind.CONSTRUCTOR;
@override
@@ -2880,6 +2877,15 @@
bool get isOperator => false;
@override
+ bool get isStatic {
+ return hasModifier(Modifier.STATIC);
+ }
+
+ set isStatic(bool isStatic) {
+ setModifier(Modifier.STATIC, isStatic);
+ }
+
+ @override
bool get isSynchronous => !isAsynchronous;
@override
@@ -3250,16 +3256,6 @@
return hasModifier(Modifier.EXTERNAL);
}
- @override
- bool get isStatic {
- return hasModifier(Modifier.STATIC);
- }
-
- /// Set whether this field is static.
- set isStatic(bool isStatic) {
- setModifier(Modifier.STATIC, isStatic);
- }
-
/// Return `true` if this element is a synthetic enum field.
///
/// It is synthetic because it is not written explicitly in code, but it
@@ -3353,9 +3349,6 @@
}
@override
- bool get isStatic => enclosingElement is CompilationUnitElement;
-
- @override
ElementKind get kind => ElementKind.FUNCTION;
@override
@@ -4209,16 +4202,6 @@
}
@override
- bool get isStatic {
- return hasModifier(Modifier.STATIC);
- }
-
- /// Set whether this method is static.
- set isStatic(bool isStatic) {
- setModifier(Modifier.STATIC, isStatic);
- }
-
- @override
ElementKind get kind => ElementKind.METHOD;
@override
@@ -5048,16 +5031,6 @@
}
@override
- bool get isStatic {
- return hasModifier(Modifier.STATIC);
- }
-
- /// Set whether this accessor is static.
- set isStatic(bool isStatic) {
- setModifier(Modifier.STATIC, isStatic);
- }
-
- @override
ElementKind get kind {
if (isGetter) {
return ElementKind.GETTER;
@@ -5931,6 +5904,10 @@
@override
bool get isStatic => hasModifier(Modifier.STATIC);
+ set isStatic(bool isStatic) {
+ setModifier(Modifier.STATIC, isStatic);
+ }
+
@override
String get name => super.name!;
diff --git a/pkg/analyzer/lib/src/dart/element/least_upper_bound.dart b/pkg/analyzer/lib/src/dart/element/least_upper_bound.dart
index df0e9e2..94dd226 100644
--- a/pkg/analyzer/lib/src/dart/element/least_upper_bound.dart
+++ b/pkg/analyzer/lib/src/dart/element/least_upper_bound.dart
@@ -248,7 +248,7 @@
return result;
} else {
return result.map((e) {
- return e.mapArguments(typeSystem.toLegacyType);
+ return e.mapArguments(typeSystem.toLegacyTypeIfOptOut);
}).toSet();
}
}
diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart
index f12c602..1b41aeb5 100644
--- a/pkg/analyzer/lib/src/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_system.dart
@@ -544,7 +544,7 @@
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
);
- type = toLegacyType(type) as InterfaceType;
+ type = toLegacyTypeIfOptOut(type) as InterfaceType;
return type;
} else if (typeAliasElement != null) {
var typeParameters = typeAliasElement.typeParameters;
@@ -553,7 +553,7 @@
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
);
- type = toLegacyType(type);
+ type = toLegacyTypeIfOptOut(type);
return type;
} else {
throw ArgumentError('Missing element');
@@ -1295,8 +1295,8 @@
// TODO(scheglov) waiting for the spec
// https://github.com/dart-lang/sdk/issues/42605
} else {
- srcType = toLegacyType(srcType);
- destType = toLegacyType(destType);
+ srcType = toLegacyTypeIfOptOut(srcType);
+ destType = toLegacyTypeIfOptOut(destType);
}
if (srcType != destType) {
// Failed to find an appropriate substitution
@@ -1480,17 +1480,10 @@
return RuntimeTypeEqualityHelper(this).equal(T1, T2);
}
- DartType toLegacyType(DartType type) {
- if (isNonNullableByDefault) return type;
- return NullabilityEliminator.perform(typeProvider, type);
- }
-
/// If a legacy library, return the legacy version of the [type].
/// Otherwise, return the original type.
DartType toLegacyTypeIfOptOut(DartType type) {
- if (isNonNullableByDefault) {
- return type;
- }
+ if (isNonNullableByDefault) return type;
return NullabilityEliminator.perform(typeProvider, type);
}
diff --git a/pkg/analyzer/lib/src/dart/element/well_bounded.dart b/pkg/analyzer/lib/src/dart/element/well_bounded.dart
index 35185ec..9ca8629 100644
--- a/pkg/analyzer/lib/src/dart/element/well_bounded.dart
+++ b/pkg/analyzer/lib/src/dart/element/well_bounded.dart
@@ -101,7 +101,7 @@
continue;
}
- bound = typeSystem.toLegacyType(bound);
+ bound = typeSystem.toLegacyTypeIfOptOut(bound);
bound = substitution.substituteType(bound);
if (!typeSystem.isSubtypeOf(typeArgument, bound)) {
diff --git a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
index 969d189..5063c86 100644
--- a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
@@ -213,7 +213,7 @@
typeArguments: typeArguments,
nullabilitySuffix: nullability,
);
- type = typeSystem.toLegacyType(type);
+ type = typeSystem.toLegacyTypeIfOptOut(type);
return _verifyTypeAliasForContext(node, element, type);
} else if (_isInstanceCreation(node)) {
_ErrorHelper(errorReporter).reportNewWithNonType(node);
diff --git a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
index e0e84d6..f835414 100644
--- a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
+++ b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
@@ -86,10 +86,7 @@
void checkStaticAccessors(List<PropertyAccessorElement> accessors) {
for (var getter in accessors) {
- // TODO(scheglov) Update `isStatic` instead
- if ((getter.isStatic ||
- getter.enclosingElement is CompilationUnitElement) &&
- getter.isGetter) {
+ if (getter.isStatic && getter.isGetter) {
_checkLocalGetter(getter);
}
}
diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart
index 892c2fb..3330307 100644
--- a/pkg/analyzer/lib/src/summary2/element_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/element_builder.dart
@@ -564,6 +564,7 @@
if (node.isGetter) {
var element = PropertyAccessorElementImpl(name, nameOffset);
element.isGetter = true;
+ element.isStatic = true;
reference = _enclosingContext.addGetter(name, element);
executableElement = element;
@@ -572,6 +573,7 @@
} else if (node.isSetter) {
var element = PropertyAccessorElementImpl(name, nameOffset);
element.isSetter = true;
+ element.isStatic = true;
reference = _enclosingContext.addSetter(name, element);
executableElement = element;
@@ -579,6 +581,7 @@
_buildSyntheticVariable(name: name, accessorElement: element);
} else {
var element = FunctionElementImpl(name, nameOffset);
+ element.isStatic = true;
reference = _enclosingContext.addFunction(name, element);
executableElement = element;
}
diff --git a/pkg/analyzer/lib/src/summary2/element_flags.dart b/pkg/analyzer/lib/src/summary2/element_flags.dart
index ff4cdbc..201c671 100644
--- a/pkg/analyzer/lib/src/summary2/element_flags.dart
+++ b/pkg/analyzer/lib/src/summary2/element_flags.dart
@@ -119,6 +119,7 @@
static const int _isAsynchronous = 1 << 1;
static const int _isExternal = 1 << 2;
static const int _isGenerator = 1 << 3;
+ static const int _isStatic = 1 << 4;
static void read(SummaryDataReader reader, FunctionElementImpl element) {
var byte = reader.readByte();
@@ -126,6 +127,7 @@
element.isAsynchronous = (byte & _isAsynchronous) != 0;
element.isExternal = (byte & _isExternal) != 0;
element.isGenerator = (byte & _isGenerator) != 0;
+ element.isStatic = (byte & _isStatic) != 0;
}
static void write(BufferedSink sink, FunctionElementImpl element) {
@@ -134,6 +136,7 @@
result |= element.isAsynchronous ? _isAsynchronous : 0;
result |= element.isExternal ? _isExternal : 0;
result |= element.isGenerator ? _isGenerator : 0;
+ result |= element.isStatic ? _isStatic : 0;
sink.writeByte(result);
}
}
diff --git a/pkg/analyzer/lib/src/summary2/named_type_builder.dart b/pkg/analyzer/lib/src/summary2/named_type_builder.dart
index e6cd97a..9b4f698 100644
--- a/pkg/analyzer/lib/src/summary2/named_type_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/named_type_builder.dart
@@ -103,7 +103,7 @@
typeArguments: arguments,
nullabilitySuffix: nullabilitySuffix,
);
- type = typeSystem.toLegacyType(type) as InterfaceType;
+ type = typeSystem.toLegacyTypeIfOptOut(type) as InterfaceType;
_type = type;
} else if (element is TypeAliasElementImpl) {
var aliasedType = _getAliasedType(element);
@@ -114,7 +114,7 @@
typeArguments: arguments,
nullabilitySuffix: nullabilitySuffix,
);
- type = typeSystem.toLegacyType(type);
+ type = typeSystem.toLegacyTypeIfOptOut(type);
_type = type;
} else if (element is NeverElementImpl) {
if (typeSystem.isNonNullableByDefault) {
diff --git a/pkg/analyzer/test/generated/invalid_code_test.dart b/pkg/analyzer/test/generated/invalid_code_test.dart
index 54794d7..51d910d 100644
--- a/pkg/analyzer/test/generated/invalid_code_test.dart
+++ b/pkg/analyzer/test/generated/invalid_code_test.dart
@@ -10,16 +10,82 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(InvalidCodeTest);
- defineReflectiveTests(InvalidCodeWithNullSafetyTest);
+ defineReflectiveTests(InvalidCodeWithoutNullSafetyTest);
});
}
+@reflectiveTest
+class InvalidCodeTest extends PubPackageResolutionTest {
+ test_functionExpression_emptyBody() async {
+ await _assertCanBeAnalyzed(r'''
+var v = <T>();
+''');
+ }
+
+ test_functionExpressionInvocation_mustBeNullShortingTerminated() async {
+ // It looks like MethodInvocation, but because `8` is not SimpleIdentifier,
+ // we parse it as FunctionExpressionInvocation.
+ await _assertCanBeAnalyzed(r'''
+var v = a?.8(b);
+''');
+ }
+
+ test_inAnnotation_noFlow_labeledStatement() async {
+ await _assertCanBeAnalyzed('''
+@A(() { label: })
+typedef F = void Function();
+''');
+ }
+
+ test_inDefaultValue_noFlow_ifExpression() async {
+ await _assertCanBeAnalyzed('''
+typedef void F({a = [if (true) 0]});
+''');
+ }
+
+ test_inDefaultValue_noFlow_ifStatement() async {
+ await _assertCanBeAnalyzed('''
+typedef void F([a = () { if (true) 0; }]);
+''');
+ }
+
+ test_issue_40837() async {
+ await _assertCanBeAnalyzed('''
+class A {
+ const A(_);
+}
+
+@A(() => 0)
+class B {}
+''');
+ }
+
+ test_methodInvocation_ofGenericClass_generic_static_fromLegacy() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A<T> {
+ static void foo<T2>() {}
+}
+''');
+ await _assertCanBeAnalyzed('''
+// @dart = 2.9
+import 'a.dart';
+
+const bar = A.foo();
+''');
+ }
+
+ Future<void> _assertCanBeAnalyzed(String text) async {
+ await resolveTestCode(text);
+ assertHasTestErrors();
+ }
+}
+
/// Tests for various end-to-end cases when invalid code caused exceptions
/// in one or another Analyzer subsystem. We are not interested not in specific
/// errors generated, but we want to make sure that there is at least one,
/// and analysis finishes without exceptions.
@reflectiveTest
-class InvalidCodeTest extends PubPackageResolutionTest
+class InvalidCodeWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
// test cases.
@@ -409,69 +475,3 @@
assertHasTestErrors();
}
}
-
-@reflectiveTest
-class InvalidCodeWithNullSafetyTest extends PubPackageResolutionTest {
- test_functionExpression_emptyBody() async {
- await _assertCanBeAnalyzed(r'''
-var v = <T>();
-''');
- }
-
- test_functionExpressionInvocation_mustBeNullShortingTerminated() async {
- // It looks like MethodInvocation, but because `8` is not SimpleIdentifier,
- // we parse it as FunctionExpressionInvocation.
- await _assertCanBeAnalyzed(r'''
-var v = a?.8(b);
-''');
- }
-
- test_inAnnotation_noFlow_labeledStatement() async {
- await _assertCanBeAnalyzed('''
-@A(() { label: })
-typedef F = void Function();
-''');
- }
-
- test_inDefaultValue_noFlow_ifExpression() async {
- await _assertCanBeAnalyzed('''
-typedef void F({a = [if (true) 0]});
-''');
- }
-
- test_inDefaultValue_noFlow_ifStatement() async {
- await _assertCanBeAnalyzed('''
-typedef void F([a = () { if (true) 0; }]);
-''');
- }
-
- test_issue_40837() async {
- await _assertCanBeAnalyzed('''
-class A {
- const A(_);
-}
-
-@A(() => 0)
-class B {}
-''');
- }
-
- test_methodInvocation_ofGenericClass_generic_static_fromLegacy() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A<T> {
- static void foo<T2>() {}
-}
-''');
- await _assertCanBeAnalyzed('''
-// @dart = 2.9
-import 'a.dart';
-
-const bar = A.foo();
-''');
- }
-
- Future<void> _assertCanBeAnalyzed(String text) async {
- await resolveTestCode(text);
- assertHasTestErrors();
- }
-}
diff --git a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
index 73da833..704c6ed 100644
--- a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
+++ b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
@@ -12,12 +12,295 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(InheritanceManager3Test);
- defineReflectiveTests(InheritanceManager3WithNullSafetyTest);
+ defineReflectiveTests(InheritanceManager3WithoutNullSafetyTest);
});
}
@reflectiveTest
class InheritanceManager3Test extends _InheritanceManager3Base {
+ test_getInheritedMap_topMerge_method() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.6
+class A {
+ void foo({int a}) {}
+}
+''');
+
+ await resolveTestCode('''
+import 'a.dart';
+
+class B {
+ void foo({required int? a}) {}
+}
+
+class C implements A, B {
+ void foo({int? a}) {}
+}
+''');
+
+ _assertInheritedMap('C', r'''
+A.foo: void Function({int a})
+''');
+ }
+
+ test_getMember_mixin_notMerge_replace() async {
+ await resolveTestCode('''
+class A<T> {
+ T foo() => throw 0;
+}
+
+mixin M<T> {
+ T foo() => throw 1;
+}
+
+class X extends A<dynamic> with M<Object?> {}
+class Y extends A<Object?> with M<dynamic> {}
+''');
+ _assertGetMember2(
+ className: 'X',
+ name: 'foo',
+ expected: 'M.foo: Object? Function()',
+ );
+ _assertGetMember2(
+ className: 'Y',
+ name: 'foo',
+ expected: 'M.foo: dynamic Function()',
+ );
+ }
+
+ test_getMember_optIn_inheritsOptIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ int foo(int a, int? b) => 0;
+}
+''');
+ await resolveTestCode('''
+import 'a.dart';
+class B extends A {
+ int? bar(int a) => 0;
+}
+''');
+ _assertGetMember(
+ className: 'B',
+ name: 'foo',
+ expected: 'A.foo: int Function(int, int?)',
+ );
+ _assertGetMember(
+ className: 'B',
+ name: 'bar',
+ expected: 'B.bar: int? Function(int)',
+ );
+ }
+
+ test_getMember_optIn_inheritsOptOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.6
+class A {
+ int foo(int a, int b) => 0;
+}
+''');
+ await resolveTestCode('''
+import 'a.dart';
+class B extends A {
+ int? bar(int a) => 0;
+}
+''');
+ _assertGetMember(
+ className: 'B',
+ name: 'foo',
+ expected: 'A.foo: int* Function(int*, int*)*',
+ );
+ _assertGetMember(
+ className: 'B',
+ name: 'bar',
+ expected: 'B.bar: int? Function(int)',
+ );
+ }
+
+ test_getMember_optIn_topMerge_getter_existing() async {
+ await resolveTestCode('''
+class A {
+ dynamic get foo => 0;
+}
+
+class B {
+ Object? get foo => 0;
+}
+
+class X extends A implements B {}
+''');
+
+ _assertGetMember(
+ className: 'X',
+ name: 'foo',
+ expected: 'B.foo: Object? Function()',
+ );
+ }
+
+ test_getMember_optIn_topMerge_getter_synthetic() async {
+ await resolveTestCode('''
+abstract class A {
+ Future<void> get foo;
+}
+
+abstract class B {
+ Future<dynamic> get foo;
+}
+
+abstract class X extends A implements B {}
+''');
+
+ _assertGetMember(
+ className: 'X',
+ name: 'foo',
+ expected: 'X.foo: Future<Object?> Function()',
+ );
+ }
+
+ test_getMember_optIn_topMerge_method() async {
+ await resolveTestCode('''
+class A {
+ Object? foo(dynamic x) {}
+}
+
+class B {
+ dynamic foo(Object? x) {}
+}
+
+class X extends A implements B {}
+''');
+
+ _assertGetMember(
+ className: 'X',
+ name: 'foo',
+ expected: 'X.foo: Object? Function(Object?)',
+ );
+ }
+
+ test_getMember_optIn_topMerge_setter_existing() async {
+ await resolveTestCode('''
+class A {
+ set foo(dynamic _) {}
+}
+
+class B {
+ set foo(Object? _) {}
+}
+
+class X extends A implements B {}
+''');
+
+ _assertGetMember(
+ className: 'X',
+ name: 'foo=',
+ expected: 'B.foo=: void Function(Object?)',
+ );
+ }
+
+ test_getMember_optIn_topMerge_setter_synthetic() async {
+ await resolveTestCode('''
+abstract class A {
+ set foo(Future<void> _);
+}
+
+abstract class B {
+ set foo(Future<dynamic> _);
+}
+
+abstract class X extends A implements B {}
+''');
+
+ _assertGetMember(
+ className: 'X',
+ name: 'foo=',
+ expected: 'X.foo=: void Function(Future<Object?>)',
+ );
+ }
+
+ test_getMember_optOut_inheritsOptIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ int foo(int a, int? b) => 0;
+}
+''');
+ await resolveTestCode('''
+// @dart = 2.6
+import 'a.dart';
+class B extends A {
+ int bar(int a) => 0;
+}
+''');
+ _assertGetMember2(
+ className: 'B',
+ name: 'foo',
+ expected: 'A.foo: int* Function(int*, int*)*',
+ );
+
+ _assertGetMember2(
+ className: 'B',
+ name: 'bar',
+ expected: 'B.bar: int* Function(int*)*',
+ );
+ }
+
+ test_getMember_optOut_mixesOptIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ int foo(int a, int? b) => 0;
+}
+''');
+ await resolveTestCode('''
+// @dart = 2.6
+import 'a.dart';
+class B with A {
+ int bar(int a) => 0;
+}
+''');
+ _assertGetMember2(
+ className: 'B',
+ name: 'foo',
+ expected: 'A.foo: int* Function(int*, int*)*',
+ );
+ _assertGetMember2(
+ className: 'B',
+ name: 'bar',
+ expected: 'B.bar: int* Function(int*)*',
+ );
+ }
+
+ test_getMember_optOut_passOptIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ int foo(int a, int? b) => 0;
+}
+''');
+ newFile('$testPackageLibPath/b.dart', content: r'''
+// @dart = 2.6
+import 'a.dart';
+class B extends A {
+ int bar(int a) => 0;
+}
+''');
+ await resolveTestCode('''
+import 'b.dart';
+class C extends B {}
+''');
+ _assertGetMember(
+ className: 'C',
+ name: 'foo',
+ expected: 'A.foo: int* Function(int*, int*)*',
+ );
+ _assertGetMember(
+ className: 'C',
+ name: 'bar',
+ expected: 'B.bar: int* Function(int*)*',
+ );
+ }
+}
+
+@reflectiveTest
+class InheritanceManager3WithoutNullSafetyTest
+ extends _InheritanceManager3Base {
test_getInherited_closestSuper() async {
await resolveTestCode('''
class A {
@@ -1122,288 +1405,6 @@
}
}
-@reflectiveTest
-class InheritanceManager3WithNullSafetyTest extends _InheritanceManager3Base {
- test_getInheritedMap_topMerge_method() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-// @dart = 2.6
-class A {
- void foo({int a}) {}
-}
-''');
-
- await resolveTestCode('''
-import 'a.dart';
-
-class B {
- void foo({required int? a}) {}
-}
-
-class C implements A, B {
- void foo({int? a}) {}
-}
-''');
-
- _assertInheritedMap('C', r'''
-A.foo: void Function({int a})
-''');
- }
-
- test_getMember_mixin_notMerge_replace() async {
- await resolveTestCode('''
-class A<T> {
- T foo() => throw 0;
-}
-
-mixin M<T> {
- T foo() => throw 1;
-}
-
-class X extends A<dynamic> with M<Object?> {}
-class Y extends A<Object?> with M<dynamic> {}
-''');
- _assertGetMember2(
- className: 'X',
- name: 'foo',
- expected: 'M.foo: Object? Function()',
- );
- _assertGetMember2(
- className: 'Y',
- name: 'foo',
- expected: 'M.foo: dynamic Function()',
- );
- }
-
- test_getMember_optIn_inheritsOptIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- int foo(int a, int? b) => 0;
-}
-''');
- await resolveTestCode('''
-import 'a.dart';
-class B extends A {
- int? bar(int a) => 0;
-}
-''');
- _assertGetMember(
- className: 'B',
- name: 'foo',
- expected: 'A.foo: int Function(int, int?)',
- );
- _assertGetMember(
- className: 'B',
- name: 'bar',
- expected: 'B.bar: int? Function(int)',
- );
- }
-
- test_getMember_optIn_inheritsOptOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-// @dart = 2.6
-class A {
- int foo(int a, int b) => 0;
-}
-''');
- await resolveTestCode('''
-import 'a.dart';
-class B extends A {
- int? bar(int a) => 0;
-}
-''');
- _assertGetMember(
- className: 'B',
- name: 'foo',
- expected: 'A.foo: int* Function(int*, int*)*',
- );
- _assertGetMember(
- className: 'B',
- name: 'bar',
- expected: 'B.bar: int? Function(int)',
- );
- }
-
- test_getMember_optIn_topMerge_getter_existing() async {
- await resolveTestCode('''
-class A {
- dynamic get foo => 0;
-}
-
-class B {
- Object? get foo => 0;
-}
-
-class X extends A implements B {}
-''');
-
- _assertGetMember(
- className: 'X',
- name: 'foo',
- expected: 'B.foo: Object? Function()',
- );
- }
-
- test_getMember_optIn_topMerge_getter_synthetic() async {
- await resolveTestCode('''
-abstract class A {
- Future<void> get foo;
-}
-
-abstract class B {
- Future<dynamic> get foo;
-}
-
-abstract class X extends A implements B {}
-''');
-
- _assertGetMember(
- className: 'X',
- name: 'foo',
- expected: 'X.foo: Future<Object?> Function()',
- );
- }
-
- test_getMember_optIn_topMerge_method() async {
- await resolveTestCode('''
-class A {
- Object? foo(dynamic x) {}
-}
-
-class B {
- dynamic foo(Object? x) {}
-}
-
-class X extends A implements B {}
-''');
-
- _assertGetMember(
- className: 'X',
- name: 'foo',
- expected: 'X.foo: Object? Function(Object?)',
- );
- }
-
- test_getMember_optIn_topMerge_setter_existing() async {
- await resolveTestCode('''
-class A {
- set foo(dynamic _) {}
-}
-
-class B {
- set foo(Object? _) {}
-}
-
-class X extends A implements B {}
-''');
-
- _assertGetMember(
- className: 'X',
- name: 'foo=',
- expected: 'B.foo=: void Function(Object?)',
- );
- }
-
- test_getMember_optIn_topMerge_setter_synthetic() async {
- await resolveTestCode('''
-abstract class A {
- set foo(Future<void> _);
-}
-
-abstract class B {
- set foo(Future<dynamic> _);
-}
-
-abstract class X extends A implements B {}
-''');
-
- _assertGetMember(
- className: 'X',
- name: 'foo=',
- expected: 'X.foo=: void Function(Future<Object?>)',
- );
- }
-
- test_getMember_optOut_inheritsOptIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- int foo(int a, int? b) => 0;
-}
-''');
- await resolveTestCode('''
-// @dart = 2.6
-import 'a.dart';
-class B extends A {
- int bar(int a) => 0;
-}
-''');
- _assertGetMember2(
- className: 'B',
- name: 'foo',
- expected: 'A.foo: int* Function(int*, int*)*',
- );
-
- _assertGetMember2(
- className: 'B',
- name: 'bar',
- expected: 'B.bar: int* Function(int*)*',
- );
- }
-
- test_getMember_optOut_mixesOptIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- int foo(int a, int? b) => 0;
-}
-''');
- await resolveTestCode('''
-// @dart = 2.6
-import 'a.dart';
-class B with A {
- int bar(int a) => 0;
-}
-''');
- _assertGetMember2(
- className: 'B',
- name: 'foo',
- expected: 'A.foo: int* Function(int*, int*)*',
- );
- _assertGetMember2(
- className: 'B',
- name: 'bar',
- expected: 'B.bar: int* Function(int*)*',
- );
- }
-
- test_getMember_optOut_passOptIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- int foo(int a, int? b) => 0;
-}
-''');
- newFile('$testPackageLibPath/b.dart', content: r'''
-// @dart = 2.6
-import 'a.dart';
-class B extends A {
- int bar(int a) => 0;
-}
-''');
- await resolveTestCode('''
-import 'b.dart';
-class C extends B {}
-''');
- _assertGetMember(
- className: 'C',
- name: 'foo',
- expected: 'A.foo: int* Function(int*, int*)*',
- );
- _assertGetMember(
- className: 'C',
- name: 'bar',
- expected: 'B.bar: int* Function(int*)*',
- );
- }
-}
-
class _InheritanceManager3Base extends PubPackageResolutionTest {
late final InheritanceManager3 manager;
diff --git a/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart
index cd5dd24..8a3ba86 100644
--- a/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/await_expression_test.dart
@@ -9,39 +9,12 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AwaitExpressionResolutionTest);
- defineReflectiveTests(AwaitExpressionResolutionWithNullSafetyTest);
+ defineReflectiveTests(AwaitExpressionResolutionWithoutNullSafetyTest);
});
}
@reflectiveTest
-class AwaitExpressionResolutionTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
- test_future() async {
- await assertNoErrorsInCode(r'''
-f(Future<int> a) async {
- await a;
-}
-''');
-
- assertType(findNode.awaitExpression('await a'), 'int');
- }
-
- test_futureOr() async {
- await assertNoErrorsInCode(r'''
-import 'dart:async';
-
-f(FutureOr<int> a) async {
- await a;
-}
-''');
-
- assertType(findNode.awaitExpression('await a'), 'int');
- }
-}
-
-@reflectiveTest
-class AwaitExpressionResolutionWithNullSafetyTest
- extends PubPackageResolutionTest {
+class AwaitExpressionResolutionTest extends PubPackageResolutionTest {
test_futureOrQ() async {
await assertNoErrorsInCode(r'''
import 'dart:async';
@@ -64,3 +37,29 @@
assertType(findNode.awaitExpression('await a'), 'int?');
}
}
+
+@reflectiveTest
+class AwaitExpressionResolutionWithoutNullSafetyTest
+ extends PubPackageResolutionTest with WithoutNullSafetyMixin {
+ test_future() async {
+ await assertNoErrorsInCode(r'''
+f(Future<int> a) async {
+ await a;
+}
+''');
+
+ assertType(findNode.awaitExpression('await a'), 'int');
+ }
+
+ test_futureOr() async {
+ await assertNoErrorsInCode(r'''
+import 'dart:async';
+
+f(FutureOr<int> a) async {
+ await a;
+}
+''');
+
+ assertType(findNode.awaitExpression('await a'), 'int');
+ }
+}
diff --git a/pkg/analyzer/test/src/dart/resolution/constant_test.dart b/pkg/analyzer/test/src/dart/resolution/constant_test.dart
index 2e49834..286ec22 100644
--- a/pkg/analyzer/test/src/dart/resolution/constant_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/constant_test.dart
@@ -16,12 +16,187 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConstantResolutionTest);
- defineReflectiveTests(ConstantResolutionWithNullSafetyTest);
+ defineReflectiveTests(ConstantResolutionWithoutNullSafetyTest);
});
}
@reflectiveTest
-class ConstantResolutionTest extends PubPackageResolutionTest
+class ConstantResolutionTest extends PubPackageResolutionTest {
+ test_constructor_nullSafe_fromLegacy_super() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ const A(List<Object> a);
+}
+
+class B extends A {
+ const B(List<Object> a) : super(a);
+}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.8
+import 'a.dart';
+
+const a = <dynamic>[];
+const b = B(a);
+''');
+
+ var b = findElement.topVar('b');
+ assertType(b.computeConstantValue()!.type, 'B*');
+ }
+
+ test_constructor_nullSafe_fromLegacy_this() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ const A(List<Object> a) : this(a);
+ const A.second(List<Object> a);
+}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.8
+import 'a.dart';
+
+const a = <dynamic>[];
+const b = A(a);
+''');
+
+ var b = findElement.topVar('b');
+ assertType(b.computeConstantValue()!.type, 'A*');
+ }
+
+ test_context_eliminateTypeVariables() async {
+ await assertNoErrorsInCode(r'''
+class A<T> {
+ const A({List<T> a = const []});
+}
+''');
+ assertType(findNode.listLiteral('const []'), 'List<Never>');
+ }
+
+ test_context_eliminateTypeVariables_functionType() async {
+ await assertNoErrorsInCode(r'''
+class A<T, U> {
+ const A({List<T Function(U)> a = const []});
+}
+''');
+ assertType(
+ findNode.listLiteral('const []'),
+ 'List<Never Function(Object?)>',
+ );
+ }
+
+ test_field_optIn_fromOptOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ static const foo = 42;
+}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.5
+import 'a.dart';
+
+const bar = A.foo;
+''');
+
+ var bar = findElement.topVar('bar');
+ _assertIntValue(bar, 42);
+ }
+
+ test_fromEnvironment_optOut_fromOptIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.5
+
+const cBool = const bool.fromEnvironment('foo', defaultValue: false);
+const cInt = const int.fromEnvironment('foo', defaultValue: 1);
+const cString = const String.fromEnvironment('foo', defaultValue: 'bar');
+''');
+
+ await assertErrorsInCode(r'''
+import 'a.dart';
+
+const vBool = cBool;
+const vInt = cInt;
+const vString = cString;
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
+
+ DartObjectImpl evaluate(String name) {
+ return findElement.topVar(name).computeConstantValue() as DartObjectImpl;
+ }
+
+ expect(evaluate('vBool').toBoolValue(), false);
+ expect(evaluate('vInt').toIntValue(), 1);
+ expect(evaluate('vString').toStringValue(), 'bar');
+ }
+
+ test_topLevelVariable_optIn_fromOptOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+const foo = 42;
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.5
+import 'a.dart';
+
+const bar = foo;
+''');
+
+ var bar = findElement.topVar('bar');
+ assertType(bar.type, 'int*');
+ _assertIntValue(bar, 42);
+ }
+
+ test_topLevelVariable_optOut2() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+const a = 42;
+''');
+
+ newFile('$testPackageLibPath/b.dart', content: r'''
+import 'a.dart';
+
+const b = a;
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.5
+import 'b.dart';
+
+const c = b;
+''');
+
+ var c = findElement.topVar('c');
+ assertType(c.type, 'int*');
+ _assertIntValue(c, 42);
+ }
+
+ test_topLevelVariable_optOut3() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.7
+const a = int.fromEnvironment('a', defaultValue: 42);
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.7
+import 'a.dart';
+
+const b = a;
+''');
+
+ var c = findElement.topVar('b');
+ assertType(c.type, 'int*');
+ _assertIntValue(c, 42);
+ }
+
+ void _assertIntValue(VariableElement element, int value) {
+ expect(element.computeConstantValue()!.toIntValue(), value);
+ }
+}
+
+@reflectiveTest
+class ConstantResolutionWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_constantValue_defaultParameter_noDefaultValue() async {
newFile('$testPackageLibPath/a.dart', content: r'''
@@ -251,178 +426,3 @@
''');
}
}
-
-@reflectiveTest
-class ConstantResolutionWithNullSafetyTest extends PubPackageResolutionTest {
- test_constructor_nullSafe_fromLegacy_super() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- const A(List<Object> a);
-}
-
-class B extends A {
- const B(List<Object> a) : super(a);
-}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.8
-import 'a.dart';
-
-const a = <dynamic>[];
-const b = B(a);
-''');
-
- var b = findElement.topVar('b');
- assertType(b.computeConstantValue()!.type, 'B*');
- }
-
- test_constructor_nullSafe_fromLegacy_this() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- const A(List<Object> a) : this(a);
- const A.second(List<Object> a);
-}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.8
-import 'a.dart';
-
-const a = <dynamic>[];
-const b = A(a);
-''');
-
- var b = findElement.topVar('b');
- assertType(b.computeConstantValue()!.type, 'A*');
- }
-
- test_context_eliminateTypeVariables() async {
- await assertNoErrorsInCode(r'''
-class A<T> {
- const A({List<T> a = const []});
-}
-''');
- assertType(findNode.listLiteral('const []'), 'List<Never>');
- }
-
- test_context_eliminateTypeVariables_functionType() async {
- await assertNoErrorsInCode(r'''
-class A<T, U> {
- const A({List<T Function(U)> a = const []});
-}
-''');
- assertType(
- findNode.listLiteral('const []'),
- 'List<Never Function(Object?)>',
- );
- }
-
- test_field_optIn_fromOptOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- static const foo = 42;
-}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.5
-import 'a.dart';
-
-const bar = A.foo;
-''');
-
- var bar = findElement.topVar('bar');
- _assertIntValue(bar, 42);
- }
-
- test_fromEnvironment_optOut_fromOptIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-// @dart = 2.5
-
-const cBool = const bool.fromEnvironment('foo', defaultValue: false);
-const cInt = const int.fromEnvironment('foo', defaultValue: 1);
-const cString = const String.fromEnvironment('foo', defaultValue: 'bar');
-''');
-
- await assertErrorsInCode(r'''
-import 'a.dart';
-
-const vBool = cBool;
-const vInt = cInt;
-const vString = cString;
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
- ]);
-
- DartObjectImpl evaluate(String name) {
- return findElement.topVar(name).computeConstantValue() as DartObjectImpl;
- }
-
- expect(evaluate('vBool').toBoolValue(), false);
- expect(evaluate('vInt').toIntValue(), 1);
- expect(evaluate('vString').toStringValue(), 'bar');
- }
-
- test_topLevelVariable_optIn_fromOptOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-const foo = 42;
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.5
-import 'a.dart';
-
-const bar = foo;
-''');
-
- var bar = findElement.topVar('bar');
- assertType(bar.type, 'int*');
- _assertIntValue(bar, 42);
- }
-
- test_topLevelVariable_optOut2() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-const a = 42;
-''');
-
- newFile('$testPackageLibPath/b.dart', content: r'''
-import 'a.dart';
-
-const b = a;
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.5
-import 'b.dart';
-
-const c = b;
-''');
-
- var c = findElement.topVar('c');
- assertType(c.type, 'int*');
- _assertIntValue(c, 42);
- }
-
- test_topLevelVariable_optOut3() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-// @dart = 2.7
-const a = int.fromEnvironment('a', defaultValue: 42);
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.7
-import 'a.dart';
-
-const b = a;
-''');
-
- var c = findElement.topVar('b');
- assertType(c.type, 'int*');
- _assertIntValue(c, 42);
- }
-
- void _assertIntValue(VariableElement element, int value) {
- expect(element.computeConstantValue()!.toIntValue(), value);
- }
-}
diff --git a/pkg/analyzer/test/src/dart/resolution/function_expression_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/function_expression_invocation_test.dart
index 031eb7e..0ed4d13 100644
--- a/pkg/analyzer/test/src/dart/resolution/function_expression_invocation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/function_expression_invocation_test.dart
@@ -10,49 +10,12 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(FunctionExpressionInvocationTest);
- defineReflectiveTests(FunctionExpressionInvocationWithNullSafetyTest);
+ defineReflectiveTests(FunctionExpressionInvocationWithoutNullSafetyTest);
});
}
@reflectiveTest
-class FunctionExpressionInvocationTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
- test_dynamic_withoutTypeArguments() async {
- await assertNoErrorsInCode(r'''
-main() {
- (main as dynamic)(0);
-}
-''');
-
- assertFunctionExpressionInvocation(
- findNode.functionExpressionInvocation('(0)'),
- element: null,
- typeArgumentTypes: [],
- invokeType: 'dynamic',
- type: 'dynamic',
- );
- }
-
- test_dynamic_withTypeArguments() async {
- await assertNoErrorsInCode(r'''
-main() {
- (main as dynamic)<bool, int>(0);
-}
-''');
-
- assertFunctionExpressionInvocation(
- findNode.functionExpressionInvocation('(0)'),
- element: null,
- typeArgumentTypes: ['bool', 'int'],
- invokeType: 'dynamic',
- type: 'dynamic',
- );
- }
-}
-
-@reflectiveTest
-class FunctionExpressionInvocationWithNullSafetyTest
- extends PubPackageResolutionTest {
+class FunctionExpressionInvocationTest extends PubPackageResolutionTest {
test_call_infer_fromArguments() async {
await assertNoErrorsInCode(r'''
class A {
@@ -230,3 +193,39 @@
);
}
}
+
+@reflectiveTest
+class FunctionExpressionInvocationWithoutNullSafetyTest
+ extends PubPackageResolutionTest with WithoutNullSafetyMixin {
+ test_dynamic_withoutTypeArguments() async {
+ await assertNoErrorsInCode(r'''
+main() {
+ (main as dynamic)(0);
+}
+''');
+
+ assertFunctionExpressionInvocation(
+ findNode.functionExpressionInvocation('(0)'),
+ element: null,
+ typeArgumentTypes: [],
+ invokeType: 'dynamic',
+ type: 'dynamic',
+ );
+ }
+
+ test_dynamic_withTypeArguments() async {
+ await assertNoErrorsInCode(r'''
+main() {
+ (main as dynamic)<bool, int>(0);
+}
+''');
+
+ assertFunctionExpressionInvocation(
+ findNode.functionExpressionInvocation('(0)'),
+ element: null,
+ typeArgumentTypes: ['bool', 'int'],
+ invokeType: 'dynamic',
+ type: 'dynamic',
+ );
+ }
+}
diff --git a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
index eb3fbbc..e843e9c 100644
--- a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
@@ -13,14 +13,601 @@
main() {
defineReflectiveSuite(() {
+ defineReflectiveTests(MethodInvocationResolutionWithoutNullSafetyTest);
defineReflectiveTests(MethodInvocationResolutionTest);
- defineReflectiveTests(MethodInvocationResolutionWithNullSafetyTest);
});
}
@reflectiveTest
class MethodInvocationResolutionTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, MethodInvocationResolutionTestCases {}
+ with MethodInvocationResolutionTestCases {
+ test_hasReceiver_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {}
+''');
+
+ await assertErrorsInCode(r'''
+// @dart = 2.7
+import 'a.dart' deferred as a;
+
+main() {
+ a.loadLibrary();
+}
+''', [
+ error(HintCode.UNUSED_IMPORT, 22, 8),
+ ]);
+
+ var import = findElement.importFind('package:test/a.dart');
+
+ var invocation = findNode.methodInvocation('loadLibrary()');
+ assertImportPrefix(invocation.target, import.prefix);
+
+ assertMethodInvocation(
+ invocation,
+ import.importedLibrary.loadLibraryFunction,
+ 'Future<dynamic>* Function()*',
+ );
+ }
+
+ test_hasReceiver_interfaceQ_Function_call_checked() async {
+ await assertNoErrorsInCode(r'''
+void f(Function? foo) {
+ foo?.call();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('foo?.call()'),
+ element: null,
+ typeArgumentTypes: [],
+ invokeType: 'dynamic',
+ type: 'dynamic',
+ );
+ }
+
+ test_hasReceiver_interfaceQ_Function_call_unchecked() async {
+ await assertErrorsInCode(r'''
+void f(Function? foo) {
+ foo.call();
+}
+''', [
+ error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
+ 30, 4),
+ ]);
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('foo.call()'),
+ element: null,
+ typeArgumentTypes: [],
+ invokeType: 'dynamic',
+ type: 'dynamic',
+ );
+ }
+
+ test_hasReceiver_interfaceQ_nullShorting() async {
+ await assertNoErrorsInCode(r'''
+class C {
+ C foo() => throw 0;
+ C bar() => throw 0;
+}
+
+void testShort(C? c) {
+ c?.foo().bar();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('c?.foo()'),
+ element: findElement.method('foo'),
+ typeArgumentTypes: [],
+ invokeType: 'C Function()',
+ type: 'C',
+ );
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('bar();'),
+ element: findElement.method('bar'),
+ typeArgumentTypes: [],
+ invokeType: 'C Function()',
+ type: 'C?',
+ );
+ }
+
+ test_hasReceiver_interfaceQ_nullShorting_getter() async {
+ await assertNoErrorsInCode(r'''
+abstract class C {
+ void Function(C) get foo;
+}
+
+void f(C? c) {
+ c?.foo(c); // 1
+}
+''');
+
+ var invocation = findNode.functionExpressionInvocation('foo(c);');
+ assertElementNull(invocation);
+ assertInvokeType(invocation, 'void Function(C)');
+ assertType(invocation, 'void');
+
+ var foo = invocation.function as PropertyAccess;
+ assertType(foo, 'void Function(C)');
+ assertElement(foo.propertyName, findElement.getter('foo'));
+ assertType(foo.propertyName, 'void Function(C)');
+
+ assertSimpleIdentifier(
+ findNode.simple('c); // 1'),
+ element: findElement.parameter('c'),
+ type: 'C',
+ );
+ }
+
+ test_hasReceiver_interfaceType_enum() async {
+ await assertNoErrorsInCode(r'''
+enum E {
+ v;
+ void foo() {}
+}
+
+void f(E e) {
+ e.foo();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('e.foo()'),
+ element: findElement.method('foo', of: 'E'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_hasReceiver_interfaceType_enum_fromMixin() async {
+ await assertNoErrorsInCode(r'''
+mixin M on Enum {
+ void foo() {}
+}
+
+enum E with M {
+ v;
+}
+
+void f(E e) {
+ e.foo();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('e.foo()'),
+ element: findElement.method('foo', of: 'M'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_defined() async {
+ await assertErrorsInCode(r'''
+class A {
+ void foo() {}
+}
+
+void f(A? a) {
+ a.foo();
+}
+''', [
+ error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
+ 48, 3),
+ ]);
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: findElement.method('foo', of: 'A'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_defined_extension() async {
+ await assertErrorsInCode(r'''
+class A {
+ void foo() {}
+}
+
+extension E on A {
+ void foo() {}
+}
+
+void f(A? a) {
+ a.foo();
+}
+''', [
+ error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
+ 86, 3),
+ ]);
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: findElement.method('foo', of: 'A'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_defined_extensionQ() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ void foo() {}
+}
+
+extension E on A? {
+ void foo() {}
+}
+
+void f(A? a) {
+ a.foo();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: findElement.method('foo', of: 'E'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_defined_extensionQ2() async {
+ await assertNoErrorsInCode(r'''
+extension E<T> on T? {
+ T foo() => throw 0;
+}
+
+void f(int? a) {
+ a.foo();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: elementMatcher(
+ findElement.method('foo', of: 'E'),
+ substitution: {'T': 'int'},
+ ),
+ typeArgumentTypes: [],
+ invokeType: 'int Function()',
+ type: 'int',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_notDefined() async {
+ await assertErrorsInCode(r'''
+class A {}
+
+void f(A? a) {
+ a.foo();
+}
+''', [
+ error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
+ 31, 3),
+ ]);
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: null,
+ typeArgumentTypes: [],
+ invokeType: 'dynamic',
+ type: 'dynamic',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_notDefined_extension() async {
+ await assertErrorsInCode(r'''
+class A {}
+
+extension E on A {
+ void foo() {}
+}
+
+void f(A? a) {
+ a.foo();
+}
+''', [
+ error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
+ 69, 3),
+ ]);
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: null,
+ typeArgumentTypes: [],
+ invokeType: 'dynamic',
+ type: 'dynamic',
+ );
+ }
+
+ test_hasReceiver_interfaceTypeQ_notDefined_extensionQ() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+
+extension E on A? {
+ void foo() {}
+}
+
+void f(A? a) {
+ a.foo();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: findElement.method('foo', of: 'E'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_hasReceiver_typeAlias_staticMethod() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ static void foo(int _) {}
+}
+
+typedef B = A;
+
+void f() {
+ B.foo(0);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('foo(0)'),
+ findElement.method('foo'),
+ 'void Function(int)',
+ );
+
+ assertTypeAliasRef(
+ findNode.simple('B.foo'),
+ findElement.typeAlias('B'),
+ );
+ }
+
+ test_hasReceiver_typeAlias_staticMethod_generic() async {
+ await assertNoErrorsInCode(r'''
+class A<T> {
+ static void foo(int _) {}
+}
+
+typedef B<T> = A<T>;
+
+void f() {
+ B.foo(0);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('foo(0)'),
+ findElement.method('foo'),
+ 'void Function(int)',
+ );
+
+ assertTypeAliasRef(
+ findNode.simple('B.foo'),
+ findElement.typeAlias('B'),
+ );
+ }
+
+ test_hasReceiver_typeParameter_promotedToNonNullable() async {
+ await assertNoErrorsInCode('''
+void f<T>(T? t) {
+ if (t is int) {
+ t.abs();
+ }
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('t.abs()'),
+ element: intElement.getMethod('abs'),
+ typeArgumentTypes: [],
+ invokeType: 'int Function()',
+ type: 'int',
+ );
+ }
+
+ test_hasReceiver_typeParameter_promotedToOtherTypeParameter() async {
+ await assertNoErrorsInCode('''
+abstract class A {}
+
+abstract class B extends A {
+ void foo();
+}
+
+void f<T extends A, U extends B>(T a) {
+ if (a is U) {
+ a.foo();
+ }
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('a.foo()'),
+ element: findElement.method('foo'),
+ typeArgumentTypes: [],
+ invokeType: 'void Function()',
+ type: 'void',
+ );
+ }
+
+ test_namedArgument_anywhere() async {
+ await assertNoErrorsInCode('''
+class A {}
+class B {}
+class C {}
+class D {}
+
+void foo(A a, B b, {C? c, D? d}) {}
+
+T g1<T>() => throw 0;
+T g2<T>() => throw 0;
+T g3<T>() => throw 0;
+T g4<T>() => throw 0;
+
+void f() {
+ foo(g1(), c: g3(), g2(), d: g4());
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('foo(g'),
+ findElement.topFunction('foo'),
+ 'void Function(A, B, {C? c, D? d})',
+ );
+
+ var g1 = findNode.methodInvocation('g1()');
+ assertType(g1, 'A');
+ assertParameterElement(g1, findElement.parameter('a'));
+
+ var g2 = findNode.methodInvocation('g2()');
+ assertType(g2, 'B');
+ assertParameterElement(g2, findElement.parameter('b'));
+
+ var named_g3 = findNode.namedExpression('c: g3()');
+ assertType(named_g3.expression, 'C?');
+ assertParameterElement(named_g3, findElement.parameter('c'));
+ assertNamedParameterRef('c:', 'c');
+
+ var named_g4 = findNode.namedExpression('d: g4()');
+ assertType(named_g4.expression, 'D?');
+ assertParameterElement(named_g4, findElement.parameter('d'));
+ assertNamedParameterRef('d:', 'd');
+ }
+
+ test_nullShorting_cascade_firstMethodInvocation() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ int foo() => 0;
+ int bar() => 0;
+}
+
+void f(A? a) {
+ a?..foo()..bar();
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('..foo()'),
+ element: findElement.method('foo'),
+ typeArgumentTypes: [],
+ invokeType: 'int Function()',
+ type: 'int',
+ );
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('..bar()'),
+ element: findElement.method('bar'),
+ typeArgumentTypes: [],
+ invokeType: 'int Function()',
+ type: 'int',
+ );
+
+ assertType(findNode.cascade('a?'), 'A?');
+ }
+
+ test_nullShorting_cascade_firstPropertyAccess() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ int get foo => 0;
+ int bar() => 0;
+}
+
+void f(A? a) {
+ a?..foo..bar();
+}
+''');
+
+ assertPropertyAccess2(
+ findNode.propertyAccess('..foo'),
+ element: findElement.getter('foo'),
+ type: 'int',
+ );
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('..bar()'),
+ element: findElement.method('bar'),
+ typeArgumentTypes: [],
+ invokeType: 'int Function()',
+ type: 'int',
+ );
+
+ assertType(findNode.cascade('a?'), 'A?');
+ }
+
+ test_nullShorting_cascade_nullAwareInside() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ int? foo() => 0;
+}
+
+main() {
+ A a = A()..foo()?.abs();
+ a;
+}
+''');
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('..foo()'),
+ element: findElement.method('foo'),
+ typeArgumentTypes: [],
+ invokeType: 'int? Function()',
+ type: 'int?',
+ );
+
+ assertMethodInvocation2(
+ findNode.methodInvocation('.abs()'),
+ element: intElement.getMethod('abs'),
+ typeArgumentTypes: [],
+ invokeType: 'int Function()',
+ type: 'int',
+ );
+
+ assertType(findNode.cascade('A()'), 'A');
+ }
+
+ test_typeArgumentTypes_generic_inferred_leftTop_dynamic() async {
+ await assertNoErrorsInCode('''
+void foo<T extends Object>(T? value) {}
+
+void f(dynamic o) {
+ foo(o);
+}
+''');
+
+ assertTypeArgumentTypes(
+ findNode.methodInvocation('foo(o)'),
+ ['Object'],
+ );
+ }
+
+ test_typeArgumentTypes_generic_inferred_leftTop_void() async {
+ await assertNoErrorsInCode('''
+void foo<T extends Object>(List<T?> value) {}
+
+void f(List<void> o) {
+ foo(o);
+}
+''');
+
+ assertTypeArgumentTypes(
+ findNode.methodInvocation('foo(o)'),
+ ['Object'],
+ );
+ }
+}
mixin MethodInvocationResolutionTestCases on PubPackageResolutionTest {
test_clamp_double_context_double() async {
@@ -2484,592 +3071,6 @@
}
@reflectiveTest
-class MethodInvocationResolutionWithNullSafetyTest
- extends PubPackageResolutionTest with MethodInvocationResolutionTestCases {
- test_hasReceiver_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {}
-''');
-
- await assertErrorsInCode(r'''
-// @dart = 2.7
-import 'a.dart' deferred as a;
-
-main() {
- a.loadLibrary();
-}
-''', [
- error(HintCode.UNUSED_IMPORT, 22, 8),
- ]);
-
- var import = findElement.importFind('package:test/a.dart');
-
- var invocation = findNode.methodInvocation('loadLibrary()');
- assertImportPrefix(invocation.target, import.prefix);
-
- assertMethodInvocation(
- invocation,
- import.importedLibrary.loadLibraryFunction,
- 'Future<dynamic>* Function()*',
- );
- }
-
- test_hasReceiver_interfaceQ_Function_call_checked() async {
- await assertNoErrorsInCode(r'''
-void f(Function? foo) {
- foo?.call();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('foo?.call()'),
- element: null,
- typeArgumentTypes: [],
- invokeType: 'dynamic',
- type: 'dynamic',
- );
- }
-
- test_hasReceiver_interfaceQ_Function_call_unchecked() async {
- await assertErrorsInCode(r'''
-void f(Function? foo) {
- foo.call();
-}
-''', [
- error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
- 30, 4),
- ]);
-
- assertMethodInvocation2(
- findNode.methodInvocation('foo.call()'),
- element: null,
- typeArgumentTypes: [],
- invokeType: 'dynamic',
- type: 'dynamic',
- );
- }
-
- test_hasReceiver_interfaceQ_nullShorting() async {
- await assertNoErrorsInCode(r'''
-class C {
- C foo() => throw 0;
- C bar() => throw 0;
-}
-
-void testShort(C? c) {
- c?.foo().bar();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('c?.foo()'),
- element: findElement.method('foo'),
- typeArgumentTypes: [],
- invokeType: 'C Function()',
- type: 'C',
- );
-
- assertMethodInvocation2(
- findNode.methodInvocation('bar();'),
- element: findElement.method('bar'),
- typeArgumentTypes: [],
- invokeType: 'C Function()',
- type: 'C?',
- );
- }
-
- test_hasReceiver_interfaceQ_nullShorting_getter() async {
- await assertNoErrorsInCode(r'''
-abstract class C {
- void Function(C) get foo;
-}
-
-void f(C? c) {
- c?.foo(c); // 1
-}
-''');
-
- var invocation = findNode.functionExpressionInvocation('foo(c);');
- assertElementNull(invocation);
- assertInvokeType(invocation, 'void Function(C)');
- assertType(invocation, 'void');
-
- var foo = invocation.function as PropertyAccess;
- assertType(foo, 'void Function(C)');
- assertElement(foo.propertyName, findElement.getter('foo'));
- assertType(foo.propertyName, 'void Function(C)');
-
- assertSimpleIdentifier(
- findNode.simple('c); // 1'),
- element: findElement.parameter('c'),
- type: 'C',
- );
- }
-
- test_hasReceiver_interfaceType_enum() async {
- await assertNoErrorsInCode(r'''
-enum E {
- v;
- void foo() {}
-}
-
-void f(E e) {
- e.foo();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('e.foo()'),
- element: findElement.method('foo', of: 'E'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_hasReceiver_interfaceType_enum_fromMixin() async {
- await assertNoErrorsInCode(r'''
-mixin M on Enum {
- void foo() {}
-}
-
-enum E with M {
- v;
-}
-
-void f(E e) {
- e.foo();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('e.foo()'),
- element: findElement.method('foo', of: 'M'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_defined() async {
- await assertErrorsInCode(r'''
-class A {
- void foo() {}
-}
-
-void f(A? a) {
- a.foo();
-}
-''', [
- error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
- 48, 3),
- ]);
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: findElement.method('foo', of: 'A'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_defined_extension() async {
- await assertErrorsInCode(r'''
-class A {
- void foo() {}
-}
-
-extension E on A {
- void foo() {}
-}
-
-void f(A? a) {
- a.foo();
-}
-''', [
- error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
- 86, 3),
- ]);
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: findElement.method('foo', of: 'A'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_defined_extensionQ() async {
- await assertNoErrorsInCode(r'''
-class A {
- void foo() {}
-}
-
-extension E on A? {
- void foo() {}
-}
-
-void f(A? a) {
- a.foo();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: findElement.method('foo', of: 'E'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_defined_extensionQ2() async {
- await assertNoErrorsInCode(r'''
-extension E<T> on T? {
- T foo() => throw 0;
-}
-
-void f(int? a) {
- a.foo();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: elementMatcher(
- findElement.method('foo', of: 'E'),
- substitution: {'T': 'int'},
- ),
- typeArgumentTypes: [],
- invokeType: 'int Function()',
- type: 'int',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_notDefined() async {
- await assertErrorsInCode(r'''
-class A {}
-
-void f(A? a) {
- a.foo();
-}
-''', [
- error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
- 31, 3),
- ]);
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: null,
- typeArgumentTypes: [],
- invokeType: 'dynamic',
- type: 'dynamic',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_notDefined_extension() async {
- await assertErrorsInCode(r'''
-class A {}
-
-extension E on A {
- void foo() {}
-}
-
-void f(A? a) {
- a.foo();
-}
-''', [
- error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
- 69, 3),
- ]);
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: null,
- typeArgumentTypes: [],
- invokeType: 'dynamic',
- type: 'dynamic',
- );
- }
-
- test_hasReceiver_interfaceTypeQ_notDefined_extensionQ() async {
- await assertNoErrorsInCode(r'''
-class A {}
-
-extension E on A? {
- void foo() {}
-}
-
-void f(A? a) {
- a.foo();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: findElement.method('foo', of: 'E'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_hasReceiver_typeAlias_staticMethod() async {
- await assertNoErrorsInCode(r'''
-class A {
- static void foo(int _) {}
-}
-
-typedef B = A;
-
-void f() {
- B.foo(0);
-}
-''');
-
- assertMethodInvocation(
- findNode.methodInvocation('foo(0)'),
- findElement.method('foo'),
- 'void Function(int)',
- );
-
- assertTypeAliasRef(
- findNode.simple('B.foo'),
- findElement.typeAlias('B'),
- );
- }
-
- test_hasReceiver_typeAlias_staticMethod_generic() async {
- await assertNoErrorsInCode(r'''
-class A<T> {
- static void foo(int _) {}
-}
-
-typedef B<T> = A<T>;
-
-void f() {
- B.foo(0);
-}
-''');
-
- assertMethodInvocation(
- findNode.methodInvocation('foo(0)'),
- findElement.method('foo'),
- 'void Function(int)',
- );
-
- assertTypeAliasRef(
- findNode.simple('B.foo'),
- findElement.typeAlias('B'),
- );
- }
-
- test_hasReceiver_typeParameter_promotedToNonNullable() async {
- await assertNoErrorsInCode('''
-void f<T>(T? t) {
- if (t is int) {
- t.abs();
- }
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('t.abs()'),
- element: intElement.getMethod('abs'),
- typeArgumentTypes: [],
- invokeType: 'int Function()',
- type: 'int',
- );
- }
-
- test_hasReceiver_typeParameter_promotedToOtherTypeParameter() async {
- await assertNoErrorsInCode('''
-abstract class A {}
-
-abstract class B extends A {
- void foo();
-}
-
-void f<T extends A, U extends B>(T a) {
- if (a is U) {
- a.foo();
- }
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('a.foo()'),
- element: findElement.method('foo'),
- typeArgumentTypes: [],
- invokeType: 'void Function()',
- type: 'void',
- );
- }
-
- test_namedArgument_anywhere() async {
- await assertNoErrorsInCode('''
-class A {}
-class B {}
-class C {}
-class D {}
-
-void foo(A a, B b, {C? c, D? d}) {}
-
-T g1<T>() => throw 0;
-T g2<T>() => throw 0;
-T g3<T>() => throw 0;
-T g4<T>() => throw 0;
-
-void f() {
- foo(g1(), c: g3(), g2(), d: g4());
-}
-''');
-
- assertMethodInvocation(
- findNode.methodInvocation('foo(g'),
- findElement.topFunction('foo'),
- 'void Function(A, B, {C? c, D? d})',
- );
-
- var g1 = findNode.methodInvocation('g1()');
- assertType(g1, 'A');
- assertParameterElement(g1, findElement.parameter('a'));
-
- var g2 = findNode.methodInvocation('g2()');
- assertType(g2, 'B');
- assertParameterElement(g2, findElement.parameter('b'));
-
- var named_g3 = findNode.namedExpression('c: g3()');
- assertType(named_g3.expression, 'C?');
- assertParameterElement(named_g3, findElement.parameter('c'));
- assertNamedParameterRef('c:', 'c');
-
- var named_g4 = findNode.namedExpression('d: g4()');
- assertType(named_g4.expression, 'D?');
- assertParameterElement(named_g4, findElement.parameter('d'));
- assertNamedParameterRef('d:', 'd');
- }
-
- test_nullShorting_cascade_firstMethodInvocation() async {
- await assertNoErrorsInCode(r'''
-class A {
- int foo() => 0;
- int bar() => 0;
-}
-
-void f(A? a) {
- a?..foo()..bar();
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('..foo()'),
- element: findElement.method('foo'),
- typeArgumentTypes: [],
- invokeType: 'int Function()',
- type: 'int',
- );
-
- assertMethodInvocation2(
- findNode.methodInvocation('..bar()'),
- element: findElement.method('bar'),
- typeArgumentTypes: [],
- invokeType: 'int Function()',
- type: 'int',
- );
-
- assertType(findNode.cascade('a?'), 'A?');
- }
-
- test_nullShorting_cascade_firstPropertyAccess() async {
- await assertNoErrorsInCode(r'''
-class A {
- int get foo => 0;
- int bar() => 0;
-}
-
-void f(A? a) {
- a?..foo..bar();
-}
-''');
-
- assertPropertyAccess2(
- findNode.propertyAccess('..foo'),
- element: findElement.getter('foo'),
- type: 'int',
- );
-
- assertMethodInvocation2(
- findNode.methodInvocation('..bar()'),
- element: findElement.method('bar'),
- typeArgumentTypes: [],
- invokeType: 'int Function()',
- type: 'int',
- );
-
- assertType(findNode.cascade('a?'), 'A?');
- }
-
- test_nullShorting_cascade_nullAwareInside() async {
- await assertNoErrorsInCode(r'''
-class A {
- int? foo() => 0;
-}
-
-main() {
- A a = A()..foo()?.abs();
- a;
-}
-''');
-
- assertMethodInvocation2(
- findNode.methodInvocation('..foo()'),
- element: findElement.method('foo'),
- typeArgumentTypes: [],
- invokeType: 'int? Function()',
- type: 'int?',
- );
-
- assertMethodInvocation2(
- findNode.methodInvocation('.abs()'),
- element: intElement.getMethod('abs'),
- typeArgumentTypes: [],
- invokeType: 'int Function()',
- type: 'int',
- );
-
- assertType(findNode.cascade('A()'), 'A');
- }
-
- test_typeArgumentTypes_generic_inferred_leftTop_dynamic() async {
- await assertNoErrorsInCode('''
-void foo<T extends Object>(T? value) {}
-
-void f(dynamic o) {
- foo(o);
-}
-''');
-
- assertTypeArgumentTypes(
- findNode.methodInvocation('foo(o)'),
- ['Object'],
- );
- }
-
- test_typeArgumentTypes_generic_inferred_leftTop_void() async {
- await assertNoErrorsInCode('''
-void foo<T extends Object>(List<T?> value) {}
-
-void f(List<void> o) {
- foo(o);
-}
-''');
-
- assertTypeArgumentTypes(
- findNode.methodInvocation('foo(o)'),
- ['Object'],
- );
- }
-}
+class MethodInvocationResolutionWithoutNullSafetyTest
+ extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, MethodInvocationResolutionTestCases {}
diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/collection_elements_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/collection_elements_test.dart
index 45cef2a..c189677 100644
--- a/pkg/analyzer/test/src/dart/resolution/type_inference/collection_elements_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/type_inference/collection_elements_test.dart
@@ -8,14 +8,14 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(ForElementWithNullSafetyTest);
- defineReflectiveTests(IfElementWithNullSafetyTest);
- defineReflectiveTests(SpreadElementWithNullSafetyTest);
+ defineReflectiveTests(ForElementTest);
+ defineReflectiveTests(IfElementTest);
+ defineReflectiveTests(SpreadElementTest);
});
}
@reflectiveTest
-class ForElementWithNullSafetyTest extends PubPackageResolutionTest {
+class ForElementTest extends PubPackageResolutionTest {
test_list_awaitForIn_dynamic_downward() async {
await resolveTestCode('''
void f() async {
@@ -192,7 +192,7 @@
}
@reflectiveTest
-class IfElementWithNullSafetyTest extends PubPackageResolutionTest {
+class IfElementTest extends PubPackageResolutionTest {
test_list_downward() async {
await resolveTestCode('''
void f() {
@@ -228,7 +228,7 @@
}
@reflectiveTest
-class SpreadElementWithNullSafetyTest extends PubPackageResolutionTest {
+class SpreadElementTest extends PubPackageResolutionTest {
test_list_downward() async {
await resolveTestCode('''
void f() {
diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/throw_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/throw_test.dart
index 7db248a..93b026c 100644
--- a/pkg/analyzer/test/src/dart/resolution/type_inference/throw_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/type_inference/throw_test.dart
@@ -8,12 +8,12 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(ThrowWithNullSafetyTest);
+ defineReflectiveTests(ThrowTest);
});
}
@reflectiveTest
-class ThrowWithNullSafetyTest extends PubPackageResolutionTest {
+class ThrowTest extends PubPackageResolutionTest {
test_downward() async {
await resolveTestCode('''
void f() {
diff --git a/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart
index ae2f294..3cf147a 100644
--- a/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/assignment_to_final_local_test.dart
@@ -10,13 +10,40 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssignmentToFinalLocalTest);
- defineReflectiveTests(AssignmentToFinalLocalWithNullSafetyTest);
+ defineReflectiveTests(AssignmentToFinalLocalWithoutNullSafetyTest);
});
}
@reflectiveTest
-class AssignmentToFinalLocalTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
+class AssignmentToFinalLocalTest extends PubPackageResolutionTest {
+ test_localVariable_late() async {
+ await assertNoErrorsInCode('''
+void f() {
+ late final int a;
+ a = 1;
+ a;
+}
+''');
+ }
+
+ test_parameter_superFormal() async {
+ await assertErrorsInCode('''
+class A {
+ A(int a);
+}
+class B extends A {
+ var x;
+ B(super.a) : x = (() { a = 0; });
+}
+''', [
+ error(CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_LOCAL, 78, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class AssignmentToFinalLocalWithoutNullSafetyTest
+ extends PubPackageResolutionTest with WithoutNullSafetyMixin {
test_localVariable() async {
await assertErrorsInCode('''
f() {
@@ -150,31 +177,3 @@
]);
}
}
-
-@reflectiveTest
-class AssignmentToFinalLocalWithNullSafetyTest
- extends PubPackageResolutionTest {
- test_localVariable_late() async {
- await assertNoErrorsInCode('''
-void f() {
- late final int a;
- a = 1;
- a;
-}
-''');
- }
-
- test_parameter_superFormal() async {
- await assertErrorsInCode('''
-class A {
- A(int a);
-}
-class B extends A {
- var x;
- B(super.a) : x = (() { a = 0; });
-}
-''', [
- error(CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_LOCAL, 78, 1),
- ]);
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart b/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart
index 2af52ed..ecd9733 100644
--- a/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/case_expression_type_implements_equals_test.dart
@@ -10,104 +10,14 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(CaseExpressionTypeImplementsEqualsTest);
- defineReflectiveTests(CaseExpressionTypeImplementsEqualsWithNullSafetyTest);
+ defineReflectiveTests(
+ CaseExpressionTypeImplementsEqualsWithoutNullSafetyTest,
+ );
});
}
@reflectiveTest
-class CaseExpressionTypeImplementsEqualsTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
- test_declares() async {
- await assertNoErrorsInCode(r'''
-abstract class A {
- final int value;
-
- const A(this.value);
-
- bool operator==(Object other);
-}
-
-class B extends A {
- const B(int value) : super(value);
-}
-
-void f(e) {
- switch (e) {
- case const B(0):
- break;
- case const B(1):
- break;
- }
-}
-''');
- }
-
- test_implements() async {
- await assertErrorsInCode(r'''
-class A {
- final int value;
-
- const A(this.value);
-
- bool operator ==(Object other) {
- return false;
- }
-}
-
-void f(e) {
- switch (e) {
- case A(0):
- break;
- }
-}
-''', [
- error(
- CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, 128, 6),
- ]);
- }
-
- test_int() async {
- await assertNoErrorsInCode(r'''
-void f(e) {
- switch (e) {
- case 0:
- break;
- }
-}
-''');
- }
-
- test_Object() async {
- await assertNoErrorsInCode(r'''
-class A {
- final int value;
- const A(this.value);
-}
-
-void f(e) {
- switch (e) {
- case A(0):
- break;
- }
-}
-''');
- }
-
- test_String() async {
- await assertNoErrorsInCode(r'''
-void f(e) {
- switch (e) {
- case '0':
- break;
- }
-}
-''');
- }
-}
-
-@reflectiveTest
-class CaseExpressionTypeImplementsEqualsWithNullSafetyTest
- extends PubPackageResolutionTest {
+class CaseExpressionTypeImplementsEqualsTest extends PubPackageResolutionTest {
test_declares() async {
await assertNoErrorsInCode(r'''
abstract class A {
@@ -195,3 +105,94 @@
''');
}
}
+
+@reflectiveTest
+class CaseExpressionTypeImplementsEqualsWithoutNullSafetyTest
+ extends PubPackageResolutionTest with WithoutNullSafetyMixin {
+ test_declares() async {
+ await assertNoErrorsInCode(r'''
+abstract class A {
+ final int value;
+
+ const A(this.value);
+
+ bool operator==(Object other);
+}
+
+class B extends A {
+ const B(int value) : super(value);
+}
+
+void f(e) {
+ switch (e) {
+ case const B(0):
+ break;
+ case const B(1):
+ break;
+ }
+}
+''');
+ }
+
+ test_implements() async {
+ await assertErrorsInCode(r'''
+class A {
+ final int value;
+
+ const A(this.value);
+
+ bool operator ==(Object other) {
+ return false;
+ }
+}
+
+void f(e) {
+ switch (e) {
+ case A(0):
+ break;
+ }
+}
+''', [
+ error(
+ CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, 128, 6),
+ ]);
+ }
+
+ test_int() async {
+ await assertNoErrorsInCode(r'''
+void f(e) {
+ switch (e) {
+ case 0:
+ break;
+ }
+}
+''');
+ }
+
+ test_Object() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ final int value;
+ const A(this.value);
+}
+
+void f(e) {
+ switch (e) {
+ case A(0):
+ break;
+ }
+}
+''');
+ }
+
+ test_String() async {
+ await assertNoErrorsInCode(r'''
+void f(e) {
+ switch (e) {
+ case '0':
+ break;
+ }
+}
+''');
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/concrete_class_with_abstract_member_test.dart b/pkg/analyzer/test/src/diagnostics/concrete_class_with_abstract_member_test.dart
index 3faf721..d81ddad 100644
--- a/pkg/analyzer/test/src/diagnostics/concrete_class_with_abstract_member_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/concrete_class_with_abstract_member_test.dart
@@ -10,40 +10,12 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConcreteClassWithAbstractMemberTest);
- defineReflectiveTests(ConcreteClassWithAbstractMemberWithNullSafetyTest);
+ defineReflectiveTests(ConcreteClassWithAbstractMemberWithoutNullSafetyTest);
});
}
@reflectiveTest
class ConcreteClassWithAbstractMemberTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, ConcreteClassWithAbstractMemberTestCases {}
-
-mixin ConcreteClassWithAbstractMemberTestCases on PubPackageResolutionTest {
- test_direct() async {
- await assertErrorsInCode('''
-class A {
- m();
-}''', [
- error(CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, 12, 4),
- ]);
- }
-
- test_noSuchMethod_interface() async {
- await assertErrorsInCode('''
-class I {
- noSuchMethod(v) => '';
-}
-class A implements I {
- m();
-}''', [
- error(CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, 62, 4),
- ]);
- }
-}
-
-@reflectiveTest
-class ConcreteClassWithAbstractMemberWithNullSafetyTest
- extends PubPackageResolutionTest
with ConcreteClassWithAbstractMemberTestCases {
test_abstract_field() async {
await assertErrorsInCode('''
@@ -85,3 +57,31 @@
''');
}
}
+
+mixin ConcreteClassWithAbstractMemberTestCases on PubPackageResolutionTest {
+ test_direct() async {
+ await assertErrorsInCode('''
+class A {
+ m();
+}''', [
+ error(CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, 12, 4),
+ ]);
+ }
+
+ test_noSuchMethod_interface() async {
+ await assertErrorsInCode('''
+class I {
+ noSuchMethod(v) => '';
+}
+class A implements I {
+ m();
+}''', [
+ error(CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, 62, 4),
+ ]);
+ }
+}
+
+@reflectiveTest
+class ConcreteClassWithAbstractMemberWithoutNullSafetyTest
+ extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, ConcreteClassWithAbstractMemberTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart b/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart
index 3e89e8f..70ce1ae 100644
--- a/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart
@@ -10,12 +10,81 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(CouldNotInferTest);
- defineReflectiveTests(CouldNotInferWithNullSafetyTest);
+ defineReflectiveTests(CouldNotInferWithoutNullSafetyTest);
});
}
+/// TODO(https://github.com/dart-lang/sdk/issues/44078): Add tests with
+/// non-function typedefs.
@reflectiveTest
-class CouldNotInferTest extends PubPackageResolutionTest
+class CouldNotInferTest extends PubPackageResolutionTest {
+ test_constructor_nullSafe_fromLegacy() async {
+ newFile('$testPackageLibPath/a.dart', content: '''
+class C<T extends Object> {
+ C(T t);
+}
+''');
+
+ await assertNoErrorsInCode('''
+// @dart = 2.8
+import 'a.dart';
+
+void f(dynamic a) {
+ C(a);
+}
+''');
+ }
+
+ test_functionType() async {
+ await assertNoErrorsInCode('''
+void f<X>() {}
+
+main() {
+ [f];
+}
+''');
+ }
+
+ test_functionType_optOutOfGenericMetadata() async {
+ newFile('$testPackageLibPath/a.dart', content: '''
+void f<X>() {}
+''');
+ await assertErrorsInCode('''
+// @dart=2.12
+import 'a.dart';
+main() {
+ [f];
+}
+''', [
+ error(CompileTimeErrorCode.COULD_NOT_INFER, 42, 3),
+ ]);
+ }
+
+ test_instanceCreation_viaTypeAlias_notWellBounded() async {
+ await assertErrorsInCode('''
+class C<X> {
+ C();
+ factory C.foo() => C();
+ factory C.bar() = C;
+}
+typedef G<X> = X Function(X);
+typedef A<X extends G<C<X>>> = C<X>;
+
+void f() {
+ A(); // Error.
+ A.foo(); // Error.
+ A.bar(); // Error.
+}
+''', [
+ error(CompileTimeErrorCode.COULD_NOT_INFER, 152, 1),
+ error(CompileTimeErrorCode.COULD_NOT_INFER, 169, 5),
+ error(CompileTimeErrorCode.COULD_NOT_INFER, 190, 5),
+ ]);
+ }
+}
+
+@reflectiveTest
+class CouldNotInferWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_constructors_inferenceFBounded() async {
await assertErrorsInCode('''
@@ -267,72 +336,3 @@
]);
}
}
-
-/// TODO(https://github.com/dart-lang/sdk/issues/44078): Add tests with
-/// non-function typedefs.
-@reflectiveTest
-class CouldNotInferWithNullSafetyTest extends PubPackageResolutionTest {
- test_constructor_nullSafe_fromLegacy() async {
- newFile('$testPackageLibPath/a.dart', content: '''
-class C<T extends Object> {
- C(T t);
-}
-''');
-
- await assertNoErrorsInCode('''
-// @dart = 2.8
-import 'a.dart';
-
-void f(dynamic a) {
- C(a);
-}
-''');
- }
-
- test_functionType() async {
- await assertNoErrorsInCode('''
-void f<X>() {}
-
-main() {
- [f];
-}
-''');
- }
-
- test_functionType_optOutOfGenericMetadata() async {
- newFile('$testPackageLibPath/a.dart', content: '''
-void f<X>() {}
-''');
- await assertErrorsInCode('''
-// @dart=2.12
-import 'a.dart';
-main() {
- [f];
-}
-''', [
- error(CompileTimeErrorCode.COULD_NOT_INFER, 42, 3),
- ]);
- }
-
- test_instanceCreation_viaTypeAlias_notWellBounded() async {
- await assertErrorsInCode('''
-class C<X> {
- C();
- factory C.foo() => C();
- factory C.bar() = C;
-}
-typedef G<X> = X Function(X);
-typedef A<X extends G<C<X>>> = C<X>;
-
-void f() {
- A(); // Error.
- A.foo(); // Error.
- A.bar(); // Error.
-}
-''', [
- error(CompileTimeErrorCode.COULD_NOT_INFER, 152, 1),
- error(CompileTimeErrorCode.COULD_NOT_INFER, 169, 5),
- error(CompileTimeErrorCode.COULD_NOT_INFER, 190, 5),
- ]);
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart
index 4c9a2d6..0b7b7e8 100644
--- a/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart
@@ -11,7 +11,8 @@
defineReflectiveSuite(() {
defineReflectiveTests(DeprecatedMemberUse_BasicWorkspaceTest);
defineReflectiveTests(
- DeprecatedMemberUse_BasicWorkspace_WithNullSafetyTest);
+ DeprecatedMemberUse_BasicWorkspace_WithoutNullSafetyTest,
+ );
defineReflectiveTests(DeprecatedMemberUse_BazelWorkspaceTest);
defineReflectiveTests(DeprecatedMemberUse_GnWorkspaceTest);
defineReflectiveTests(DeprecatedMemberUse_PackageBuildWorkspaceTest);
@@ -29,8 +30,12 @@
}
@reflectiveTest
-class DeprecatedMemberUse_BasicWorkspace_WithNullSafetyTest
+class DeprecatedMemberUse_BasicWorkspace_WithoutNullSafetyTest
extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, DeprecatedMemberUse_BasicWorkspaceTestCases {}
+
+@reflectiveTest
+class DeprecatedMemberUse_BasicWorkspaceTest extends PubPackageResolutionTest
with DeprecatedMemberUse_BasicWorkspaceTestCases {
test_instanceCreation_namedParameter_fromLegacy() async {
newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
@@ -107,10 +112,6 @@
}
}
-@reflectiveTest
-class DeprecatedMemberUse_BasicWorkspaceTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, DeprecatedMemberUse_BasicWorkspaceTestCases {}
-
mixin DeprecatedMemberUse_BasicWorkspaceTestCases on PubPackageResolutionTest {
@override
void setUp() {
diff --git a/pkg/analyzer/test/src/diagnostics/extension_override_argument_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/extension_override_argument_not_assignable_test.dart
index c669f19..87e39b2 100644
--- a/pkg/analyzer/test/src/diagnostics/extension_override_argument_not_assignable_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/extension_override_argument_not_assignable_test.dart
@@ -11,12 +11,42 @@
defineReflectiveSuite(() {
defineReflectiveTests(ExtensionOverrideArgumentNotAssignableTest);
defineReflectiveTests(
- ExtensionOverrideArgumentNotAssignableWithNullSafetyTest);
+ ExtensionOverrideArgumentNotAssignableWithoutNullSafetyTest,
+ );
});
}
@reflectiveTest
class ExtensionOverrideArgumentNotAssignableTest
+ extends PubPackageResolutionTest {
+ test_override_onNonNullable() async {
+ await assertErrorsInCode(r'''
+extension E on String {
+ void m() {}
+}
+f() {
+ E(null).m();
+}
+''', [
+ error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ARGUMENT_NOT_ASSIGNABLE, 50,
+ 4),
+ ]);
+ }
+
+ test_override_onNullable() async {
+ await assertNoErrorsInCode(r'''
+extension E on String? {
+ void m() {}
+}
+f() {
+ E(null).m();
+}
+''');
+ }
+}
+
+@reflectiveTest
+class ExtensionOverrideArgumentNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest with WithoutNullSafetyMixin {
test_subtype() async {
await assertNoErrorsInCode('''
@@ -61,32 +91,3 @@
]);
}
}
-
-@reflectiveTest
-class ExtensionOverrideArgumentNotAssignableWithNullSafetyTest
- extends PubPackageResolutionTest {
- test_override_onNonNullable() async {
- await assertErrorsInCode(r'''
-extension E on String {
- void m() {}
-}
-f() {
- E(null).m();
-}
-''', [
- error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ARGUMENT_NOT_ASSIGNABLE, 50,
- 4),
- ]);
- }
-
- test_override_onNullable() async {
- await assertNoErrorsInCode(r'''
-extension E on String? {
- void m() {}
-}
-f() {
- E(null).m();
-}
-''');
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/final_not_initialized_test.dart b/pkg/analyzer/test/src/diagnostics/final_not_initialized_test.dart
index d5bb2f6..f24221e 100644
--- a/pkg/analyzer/test/src/diagnostics/final_not_initialized_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/final_not_initialized_test.dart
@@ -10,88 +10,12 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(FinalNotInitializedTest);
- defineReflectiveTests(FinalNotInitializedWithNullSafetyTest);
+ defineReflectiveTests(FinalNotInitializedWithoutNullSafetyTest);
});
}
@reflectiveTest
-class FinalNotInitializedTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
- test_class_instanceField_final_factoryConstructor_only() async {
- await assertNoErrorsInCode('''
-class A {
- final int x;
-
- factory A() => throw 0;
-}''');
- }
-
- test_extension_static() async {
- await assertErrorsInCode('''
-extension E on String {
- static final F;
-}''', [
- error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 39, 1),
- ]);
- }
-
- test_instanceField_final() async {
- await assertErrorsInCode('''
-class A {
- final F;
-}''', [
- error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 18, 1),
- ]);
- }
-
- test_instanceField_final_static() async {
- await assertErrorsInCode('''
-class A {
- static final F;
-}''', [
- error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 25, 1),
- ]);
- }
-
- test_library_final() async {
- await assertErrorsInCode('''
-final F;
-''', [
- error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 6, 1),
- ]);
- }
-
- test_local_final() async {
- await assertErrorsInCode('''
-f() {
- final int x;
-}''', [
- error(HintCode.UNUSED_LOCAL_VARIABLE, 18, 1),
- error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 18, 1),
- ]);
- }
-
- test_mixin() async {
- await assertErrorsInCode('''
-mixin M {
- final int x;
-}
-''', [
- error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 22, 1),
- ]);
- }
-
- test_mixin_OK() async {
- await assertNoErrorsInCode(r'''
-mixin M {
- final int f = 0;
-}
-''');
- }
-}
-
-@reflectiveTest
-class FinalNotInitializedWithNullSafetyTest extends PubPackageResolutionTest {
+class FinalNotInitializedTest extends PubPackageResolutionTest {
test_class_field_abstract() async {
await assertNoErrorsInCode('''
abstract class A {
@@ -262,3 +186,79 @@
''');
}
}
+
+@reflectiveTest
+class FinalNotInitializedWithoutNullSafetyTest extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin {
+ test_class_instanceField_final_factoryConstructor_only() async {
+ await assertNoErrorsInCode('''
+class A {
+ final int x;
+
+ factory A() => throw 0;
+}''');
+ }
+
+ test_extension_static() async {
+ await assertErrorsInCode('''
+extension E on String {
+ static final F;
+}''', [
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 39, 1),
+ ]);
+ }
+
+ test_instanceField_final() async {
+ await assertErrorsInCode('''
+class A {
+ final F;
+}''', [
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 18, 1),
+ ]);
+ }
+
+ test_instanceField_final_static() async {
+ await assertErrorsInCode('''
+class A {
+ static final F;
+}''', [
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 25, 1),
+ ]);
+ }
+
+ test_library_final() async {
+ await assertErrorsInCode('''
+final F;
+''', [
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 6, 1),
+ ]);
+ }
+
+ test_local_final() async {
+ await assertErrorsInCode('''
+f() {
+ final int x;
+}''', [
+ error(HintCode.UNUSED_LOCAL_VARIABLE, 18, 1),
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 18, 1),
+ ]);
+ }
+
+ test_mixin() async {
+ await assertErrorsInCode('''
+mixin M {
+ final int x;
+}
+''', [
+ error(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, 22, 1),
+ ]);
+ }
+
+ test_mixin_OK() async {
+ await assertNoErrorsInCode(r'''
+mixin M {
+ final int f = 0;
+}
+''');
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/inconsistent_case_expression_types_test.dart b/pkg/analyzer/test/src/diagnostics/inconsistent_case_expression_types_test.dart
index e26ef2b..8045084 100644
--- a/pkg/analyzer/test/src/diagnostics/inconsistent_case_expression_types_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/inconsistent_case_expression_types_test.dart
@@ -10,13 +10,36 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(InconsistentCaseExpressionTypesTest);
- defineReflectiveTests(InconsistentCaseExpressionTypesWithNullSafetyTest);
+ defineReflectiveTests(InconsistentCaseExpressionTypesWithoutNullSafetyTest);
});
}
@reflectiveTest
-class InconsistentCaseExpressionTypesTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
+class InconsistentCaseExpressionTypesTest extends PubPackageResolutionTest {
+ test_int_none_legacy() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+const a = 0;
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.8
+import 'a.dart';
+
+void f(int e) {
+ switch (e) {
+ case a:
+ break;
+ case 1:
+ break;
+ }
+}
+''');
+ }
+}
+
+@reflectiveTest
+class InconsistentCaseExpressionTypesWithoutNullSafetyTest
+ extends PubPackageResolutionTest with WithoutNullSafetyMixin {
test_dynamic() async {
// Even though A.S and S have a static type of "dynamic", we should see
// that they match 'abc', because they are constant strings.
@@ -112,27 +135,3 @@
]);
}
}
-
-@reflectiveTest
-class InconsistentCaseExpressionTypesWithNullSafetyTest
- extends PubPackageResolutionTest {
- test_int_none_legacy() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-const a = 0;
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.8
-import 'a.dart';
-
-void f(int e) {
- switch (e) {
- case a:
- break;
- case 1:
- break;
- }
-}
-''');
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart
index 016d36b..c44810c 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart
@@ -11,13 +11,53 @@
defineReflectiveSuite(() {
defineReflectiveTests(InvalidOverrideDifferentDefaultValuesNamedTest);
defineReflectiveTests(
- InvalidOverrideDifferentDefaultValuesNamedWithNullSafetyTest,
+ InvalidOverrideDifferentDefaultValuesNamedWithoutNullSafetyTest,
);
});
}
@reflectiveTest
class InvalidOverrideDifferentDefaultValuesNamedTest
+ extends InvalidOverrideDifferentDefaultValuesNamedWithoutNullSafetyTest {
+ test_concrete_equal_optIn_extends_optOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.7
+class A {
+ void foo({int a = 0}) {}
+}
+''');
+
+ await assertErrorsInCode(r'''
+import 'a.dart';
+
+class B extends A {
+ void foo({int a = 0}) {}
+}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
+ }
+
+ test_concrete_equal_optOut_extends_optIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ void foo({int a = 0}) {}
+}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.7
+import 'a.dart';
+
+class B extends A {
+ void foo({int a = 0}) {}
+}
+''');
+ }
+}
+
+@reflectiveTest
+class InvalidOverrideDifferentDefaultValuesNamedWithoutNullSafetyTest
extends PubPackageResolutionTest {
test_abstract_different_base_value() async {
await assertErrorsInCode(
@@ -304,43 +344,3 @@
);
}
}
-
-@reflectiveTest
-class InvalidOverrideDifferentDefaultValuesNamedWithNullSafetyTest
- extends InvalidOverrideDifferentDefaultValuesNamedTest {
- test_concrete_equal_optIn_extends_optOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-// @dart = 2.7
-class A {
- void foo({int a = 0}) {}
-}
-''');
-
- await assertErrorsInCode(r'''
-import 'a.dart';
-
-class B extends A {
- void foo({int a = 0}) {}
-}
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
- ]);
- }
-
- test_concrete_equal_optOut_extends_optIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- void foo({int a = 0}) {}
-}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.7
-import 'a.dart';
-
-class B extends A {
- void foo({int a = 0}) {}
-}
-''');
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart
index fb62381..9c9fe63 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart
@@ -9,15 +9,57 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(InvalidOverrideDifferentDefaultValuesPositionalTest);
defineReflectiveTests(
- InvalidOverrideDifferentDefaultValuesPositionalWithNullSafetyTest,
+ InvalidOverrideDifferentDefaultValuesPositionalTest,
+ );
+ defineReflectiveTests(
+ InvalidOverrideDifferentDefaultValuesPositionalWithoutNullSafetyTest,
);
});
}
@reflectiveTest
class InvalidOverrideDifferentDefaultValuesPositionalTest
+ extends InvalidOverrideDifferentDefaultValuesPositionalWithoutNullSafetyTest {
+ test_concrete_equal_optIn_extends_optOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.7
+class A {
+ void foo([int a = 0]) {}
+}
+''');
+
+ await assertErrorsInCode(r'''
+import 'a.dart';
+
+class B extends A {
+ void foo([int a = 0]) {}
+}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
+ }
+
+ test_concrete_equal_optOut_extends_optIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ void foo([int a = 0]) {}
+}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart = 2.7
+import 'a.dart';
+
+class B extends A {
+ void foo([int a = 0]) {}
+}
+''');
+ }
+}
+
+@reflectiveTest
+class InvalidOverrideDifferentDefaultValuesPositionalWithoutNullSafetyTest
extends PubPackageResolutionTest {
test_abstract_different_base_value() async {
await assertErrorsInCode(
@@ -319,43 +361,3 @@
);
}
}
-
-@reflectiveTest
-class InvalidOverrideDifferentDefaultValuesPositionalWithNullSafetyTest
- extends InvalidOverrideDifferentDefaultValuesPositionalTest {
- test_concrete_equal_optIn_extends_optOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-// @dart = 2.7
-class A {
- void foo([int a = 0]) {}
-}
-''');
-
- await assertErrorsInCode(r'''
-import 'a.dart';
-
-class B extends A {
- void foo([int a = 0]) {}
-}
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
- ]);
- }
-
- test_concrete_equal_optOut_extends_optIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- void foo([int a = 0]) {}
-}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart = 2.7
-import 'a.dart';
-
-class B extends A {
- void foo([int a = 0]) {}
-}
-''');
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart
index 2b5c527..96157cc 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart
@@ -10,12 +10,480 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(InvalidOverrideTest);
- defineReflectiveTests(InvalidOverrideWithNullSafetyTest);
+ defineReflectiveTests(InvalidOverrideWithoutNullSafetyTest);
});
}
@reflectiveTest
-class InvalidOverrideTest extends PubPackageResolutionTest
+class InvalidOverrideTest extends PubPackageResolutionTest {
+ test_abstract_field_covariant_inheritance() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract covariant num x;
+}
+abstract class B implements A {
+ void set x(Object value); // Implicitly covariant
+}
+abstract class C implements B {
+ int get x;
+ void set x(int value); // Ok because covariant
+}
+''');
+ }
+
+ test_external_field_covariant_inheritance() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ external covariant num x;
+}
+abstract class B implements A {
+ void set x(Object value); // Implicitly covariant
+}
+abstract class C implements B {
+ int get x;
+ void set x(int value); // Ok because covariant
+}
+''');
+ }
+
+ test_getter_overrides_abstract_field_covariant_invalid() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract covariant int x;
+}
+abstract class B implements A {
+ num get x;
+ void set x(num value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 91, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 44, 1)]),
+ ]);
+ }
+
+ test_getter_overrides_abstract_field_covariant_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract covariant num x;
+}
+abstract class B implements A {
+ int get x;
+}
+''');
+ }
+
+ test_getter_overrides_abstract_field_final_invalid() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract final int x;
+}
+abstract class B implements A {
+ num get x;
+ void set x(num value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 87, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 40, 1)]),
+ ]);
+ }
+
+ test_getter_overrides_abstract_field_final_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract final num x;
+}
+abstract class B implements A {
+ int get x;
+}
+''');
+ }
+
+ test_getter_overrides_abstract_field_invalid() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+abstract class B implements A {
+ num get x;
+ void set x(num value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 81, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 34, 1)]),
+ ]);
+ }
+
+ test_getter_overrides_abstract_field_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract num x;
+}
+abstract class B implements A {
+ int get x;
+}
+''');
+ }
+
+ test_getter_overrides_external_field_covariant_invalid() async {
+ await assertErrorsInCode('''
+class A {
+ external covariant int x;
+}
+abstract class B implements A {
+ num get x;
+ void set x(num value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 82, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 35, 1)]),
+ ]);
+ }
+
+ test_getter_overrides_external_field_covariant_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external covariant num x;
+}
+abstract class B implements A {
+ int get x;
+}
+''');
+ }
+
+ test_getter_overrides_external_field_final_invalid() async {
+ await assertErrorsInCode('''
+class A {
+ external final int x;
+}
+abstract class B implements A {
+ num get x;
+ void set x(num value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 78, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 31, 1)]),
+ ]);
+ }
+
+ test_getter_overrides_external_field_final_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external final num x;
+}
+abstract class B implements A {
+ int get x;
+}
+''');
+ }
+
+ test_getter_overrides_external_field_invalid() async {
+ await assertErrorsInCode('''
+class A {
+ external int x;
+}
+abstract class B implements A {
+ num get x;
+ void set x(num value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 72, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 25, 1)]),
+ ]);
+ }
+
+ test_getter_overrides_external_field_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external num x;
+}
+abstract class B implements A {
+ int get x;
+}
+''');
+ }
+
+ test_method_parameter_functionTyped_optOut_extends_optIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+abstract class A {
+ A catchError(void Function(Object) a);
+}
+''');
+
+ await assertNoErrorsInCode('''
+// @dart=2.6
+import 'a.dart';
+
+class B implements A {
+ A catchError(void Function(dynamic) a) => this;
+}
+''');
+ }
+
+ test_method_parameter_interfaceOptOut_concreteOptIn() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {
+ void foo(Object a) {}
+}
+''');
+
+ await assertNoErrorsInCode('''
+// @dart=2.6
+import 'a.dart';
+
+class B extends A {
+ void foo(dynamic a);
+}
+''');
+ }
+
+ test_mixedInheritance_1() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class B {
+ List<int Function(int)> get a => [];
+ set a(List<int Function(int)> _) {}
+ int Function(int) m(int Function(int) x) => x;
+}
+
+class Bq {
+ List<int? Function(int?)> get a => [];
+ set a(List<int? Function(int?)> _) {}
+ int? Function(int?) m(int? Function(int?) x) => x;
+}
+''');
+
+ newFile('$testPackageLibPath/b.dart', content: r'''
+// @dart = 2.7
+import 'a.dart';
+
+class C with B {}
+''');
+
+ await assertErrorsInCode(r'''
+import 'a.dart';
+import 'b.dart';
+
+class D extends C implements Bq {}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
+ }
+
+ test_mixedInheritance_2() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class B {
+ List<int Function(int)> get a => [];
+ set a(List<int Function(int)> _) {}
+ int Function(int) m(int Function(int) x) => x;
+}
+
+class Bq {
+ List<int? Function(int?)> get a => [];
+ set a(List<int? Function(int?)> _) {}
+ int? Function(int?) m(int? Function(int?) x) => x;
+}
+''');
+
+ newFile('$testPackageLibPath/b.dart', content: r'''
+// @dart = 2.7
+import 'a.dart';
+
+class C extends B with Bq {}
+''');
+
+ await assertErrorsInCode(r'''
+import 'b.dart';
+
+class D extends C {
+ List<int Function(int)> get a => [];
+ set a(List<int Function(int)> _) {}
+ int Function(int) m(int Function(int) x) => x;
+}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
+ }
+
+ test_setter_overrides_abstract_field_covariant_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract covariant num x;
+}
+abstract class B implements A {
+ int get x;
+ void set x(int value);
+}
+''');
+ }
+
+ test_setter_overrides_abstract_field_final_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract final num x;
+}
+abstract class B implements A {
+ int get x;
+ void set x(int value);
+}
+''');
+ }
+
+ test_setter_overrides_abstract_field_invalid() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract num x;
+}
+abstract class B implements A {
+ int get x;
+ void set x(int value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 95, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 34, 1)]),
+ ]);
+ }
+
+ test_setter_overrides_abstract_field_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+abstract class B implements A {
+ void set x(num value);
+}
+''');
+ }
+
+ test_setter_overrides_external_field_covariant_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external covariant num x;
+}
+abstract class B implements A {
+ int get x;
+ void set x(int value);
+}
+''');
+ }
+
+ test_setter_overrides_external_field_final_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external final num x;
+}
+abstract class B implements A {
+ int get x;
+ void set x(int value);
+}
+''');
+ }
+
+ test_setter_overrides_external_field_invalid() async {
+ await assertErrorsInCode('''
+class A {
+ external num x;
+}
+abstract class B implements A {
+ int get x;
+ void set x(int value);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_OVERRIDE, 86, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 25, 1)]),
+ ]);
+ }
+
+ test_setter_overrides_external_field_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external int x;
+}
+abstract class B implements A {
+ void set x(num value);
+}
+''');
+ }
+
+ test_viaLegacy_class() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A1 {
+ int m() => 0;
+ int get g => 0;
+ set s(int? _) {}
+}
+
+class A2 {
+ int? m() => 0;
+ int? get g => 0;
+ set s(int _) {}
+}
+''');
+
+ newFile('$testPackageLibPath/b.dart', content: r'''
+// @dart=2.6
+import 'a.dart';
+
+class L extends A2 implements A1 {}
+''');
+
+ await assertErrorsInCode('''
+import 'a.dart';
+import 'b.dart';
+
+class X1 extends L implements A1 {}
+class X2 extends L implements A2 {}
+
+class Y extends L {
+ int? get g => 0;
+ int? m() => 0;
+ set s(int _) {}
+}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
+ }
+
+ test_viaLegacy_mixin() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A1 {
+ int m() => 0;
+ int get g => 0;
+ set s(int? _) {}
+}
+
+mixin A2 {
+ int? m() => 0;
+ int? get g => 0;
+ set s(int _) {}
+}
+''');
+
+ newFile('$testPackageLibPath/b.dart', content: r'''
+// @dart=2.6
+import 'a.dart';
+
+class L extends Object with A2 implements A1 {}
+''');
+
+ await assertErrorsInCode('''
+import 'a.dart';
+import 'b.dart';
+
+class X1 extends L implements A1 {}
+class X2 extends L implements A2 {}
+
+class Y extends L {
+ int? get g => 0;
+ int? m() => 0;
+ set s(int _) {}
+}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
+ }
+}
+
+@reflectiveTest
+class InvalidOverrideWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_getter_returnType() async {
await assertErrorsInCode('''
@@ -630,471 +1098,3 @@
]);
}
}
-
-@reflectiveTest
-class InvalidOverrideWithNullSafetyTest extends PubPackageResolutionTest {
- test_abstract_field_covariant_inheritance() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract covariant num x;
-}
-abstract class B implements A {
- void set x(Object value); // Implicitly covariant
-}
-abstract class C implements B {
- int get x;
- void set x(int value); // Ok because covariant
-}
-''');
- }
-
- test_external_field_covariant_inheritance() async {
- await assertNoErrorsInCode('''
-abstract class A {
- external covariant num x;
-}
-abstract class B implements A {
- void set x(Object value); // Implicitly covariant
-}
-abstract class C implements B {
- int get x;
- void set x(int value); // Ok because covariant
-}
-''');
- }
-
- test_getter_overrides_abstract_field_covariant_invalid() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract covariant int x;
-}
-abstract class B implements A {
- num get x;
- void set x(num value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 91, 1,
- contextMessages: [message('/home/test/lib/test.dart', 44, 1)]),
- ]);
- }
-
- test_getter_overrides_abstract_field_covariant_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract covariant num x;
-}
-abstract class B implements A {
- int get x;
-}
-''');
- }
-
- test_getter_overrides_abstract_field_final_invalid() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract final int x;
-}
-abstract class B implements A {
- num get x;
- void set x(num value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 87, 1,
- contextMessages: [message('/home/test/lib/test.dart', 40, 1)]),
- ]);
- }
-
- test_getter_overrides_abstract_field_final_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract final num x;
-}
-abstract class B implements A {
- int get x;
-}
-''');
- }
-
- test_getter_overrides_abstract_field_invalid() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-abstract class B implements A {
- num get x;
- void set x(num value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 81, 1,
- contextMessages: [message('/home/test/lib/test.dart', 34, 1)]),
- ]);
- }
-
- test_getter_overrides_abstract_field_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract num x;
-}
-abstract class B implements A {
- int get x;
-}
-''');
- }
-
- test_getter_overrides_external_field_covariant_invalid() async {
- await assertErrorsInCode('''
-class A {
- external covariant int x;
-}
-abstract class B implements A {
- num get x;
- void set x(num value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 82, 1,
- contextMessages: [message('/home/test/lib/test.dart', 35, 1)]),
- ]);
- }
-
- test_getter_overrides_external_field_covariant_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external covariant num x;
-}
-abstract class B implements A {
- int get x;
-}
-''');
- }
-
- test_getter_overrides_external_field_final_invalid() async {
- await assertErrorsInCode('''
-class A {
- external final int x;
-}
-abstract class B implements A {
- num get x;
- void set x(num value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 78, 1,
- contextMessages: [message('/home/test/lib/test.dart', 31, 1)]),
- ]);
- }
-
- test_getter_overrides_external_field_final_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external final num x;
-}
-abstract class B implements A {
- int get x;
-}
-''');
- }
-
- test_getter_overrides_external_field_invalid() async {
- await assertErrorsInCode('''
-class A {
- external int x;
-}
-abstract class B implements A {
- num get x;
- void set x(num value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 72, 1,
- contextMessages: [message('/home/test/lib/test.dart', 25, 1)]),
- ]);
- }
-
- test_getter_overrides_external_field_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external num x;
-}
-abstract class B implements A {
- int get x;
-}
-''');
- }
-
- test_method_parameter_functionTyped_optOut_extends_optIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-abstract class A {
- A catchError(void Function(Object) a);
-}
-''');
-
- await assertNoErrorsInCode('''
-// @dart=2.6
-import 'a.dart';
-
-class B implements A {
- A catchError(void Function(dynamic) a) => this;
-}
-''');
- }
-
- test_method_parameter_interfaceOptOut_concreteOptIn() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A {
- void foo(Object a) {}
-}
-''');
-
- await assertNoErrorsInCode('''
-// @dart=2.6
-import 'a.dart';
-
-class B extends A {
- void foo(dynamic a);
-}
-''');
- }
-
- test_mixedInheritance_1() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class B {
- List<int Function(int)> get a => [];
- set a(List<int Function(int)> _) {}
- int Function(int) m(int Function(int) x) => x;
-}
-
-class Bq {
- List<int? Function(int?)> get a => [];
- set a(List<int? Function(int?)> _) {}
- int? Function(int?) m(int? Function(int?) x) => x;
-}
-''');
-
- newFile('$testPackageLibPath/b.dart', content: r'''
-// @dart = 2.7
-import 'a.dart';
-
-class C with B {}
-''');
-
- await assertErrorsInCode(r'''
-import 'a.dart';
-import 'b.dart';
-
-class D extends C implements Bq {}
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
- ]);
- }
-
- test_mixedInheritance_2() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class B {
- List<int Function(int)> get a => [];
- set a(List<int Function(int)> _) {}
- int Function(int) m(int Function(int) x) => x;
-}
-
-class Bq {
- List<int? Function(int?)> get a => [];
- set a(List<int? Function(int?)> _) {}
- int? Function(int?) m(int? Function(int?) x) => x;
-}
-''');
-
- newFile('$testPackageLibPath/b.dart', content: r'''
-// @dart = 2.7
-import 'a.dart';
-
-class C extends B with Bq {}
-''');
-
- await assertErrorsInCode(r'''
-import 'b.dart';
-
-class D extends C {
- List<int Function(int)> get a => [];
- set a(List<int Function(int)> _) {}
- int Function(int) m(int Function(int) x) => x;
-}
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
- ]);
- }
-
- test_setter_overrides_abstract_field_covariant_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract covariant num x;
-}
-abstract class B implements A {
- int get x;
- void set x(int value);
-}
-''');
- }
-
- test_setter_overrides_abstract_field_final_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract final num x;
-}
-abstract class B implements A {
- int get x;
- void set x(int value);
-}
-''');
- }
-
- test_setter_overrides_abstract_field_invalid() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract num x;
-}
-abstract class B implements A {
- int get x;
- void set x(int value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 95, 1,
- contextMessages: [message('/home/test/lib/test.dart', 34, 1)]),
- ]);
- }
-
- test_setter_overrides_abstract_field_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-abstract class B implements A {
- void set x(num value);
-}
-''');
- }
-
- test_setter_overrides_external_field_covariant_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external covariant num x;
-}
-abstract class B implements A {
- int get x;
- void set x(int value);
-}
-''');
- }
-
- test_setter_overrides_external_field_final_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external final num x;
-}
-abstract class B implements A {
- int get x;
- void set x(int value);
-}
-''');
- }
-
- test_setter_overrides_external_field_invalid() async {
- await assertErrorsInCode('''
-class A {
- external num x;
-}
-abstract class B implements A {
- int get x;
- void set x(int value);
-}
-''', [
- error(CompileTimeErrorCode.INVALID_OVERRIDE, 86, 1,
- contextMessages: [message('/home/test/lib/test.dart', 25, 1)]),
- ]);
- }
-
- test_setter_overrides_external_field_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external int x;
-}
-abstract class B implements A {
- void set x(num value);
-}
-''');
- }
-
- test_viaLegacy_class() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A1 {
- int m() => 0;
- int get g => 0;
- set s(int? _) {}
-}
-
-class A2 {
- int? m() => 0;
- int? get g => 0;
- set s(int _) {}
-}
-''');
-
- newFile('$testPackageLibPath/b.dart', content: r'''
-// @dart=2.6
-import 'a.dart';
-
-class L extends A2 implements A1 {}
-''');
-
- await assertErrorsInCode('''
-import 'a.dart';
-import 'b.dart';
-
-class X1 extends L implements A1 {}
-class X2 extends L implements A2 {}
-
-class Y extends L {
- int? get g => 0;
- int? m() => 0;
- set s(int _) {}
-}
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
- ]);
- }
-
- test_viaLegacy_mixin() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A1 {
- int m() => 0;
- int get g => 0;
- set s(int? _) {}
-}
-
-mixin A2 {
- int? m() => 0;
- int? get g => 0;
- set s(int _) {}
-}
-''');
-
- newFile('$testPackageLibPath/b.dart', content: r'''
-// @dart=2.6
-import 'a.dart';
-
-class L extends Object with A2 implements A1 {}
-''');
-
- await assertErrorsInCode('''
-import 'a.dart';
-import 'b.dart';
-
-class X1 extends L implements A1 {}
-class X2 extends L implements A2 {}
-
-class Y extends L {
- int? get g => 0;
- int? m() => 0;
- set s(int _) {}
-}
-''', [
- error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
- ]);
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart b/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart
index a8e490c..1c09427 100644
--- a/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/main_first_positional_parameter_type_test.dart
@@ -10,13 +10,31 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MainFirstPositionalParameterTest);
- defineReflectiveTests(MainFirstPositionalParameterWithNullSafetyTest);
+ defineReflectiveTests(MainFirstPositionalParameterWithoutNullSafetyTest);
});
}
@reflectiveTest
class MainFirstPositionalParameterTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, MainFirstPositionalParameterTestCases {}
+ with MainFirstPositionalParameterTestCases {
+ test_positionalRequired_listOfStringQuestion() async {
+ await assertNoErrorsInCode('''
+void main(List<String?> args) {}
+''');
+ }
+
+ test_positionalRequired_listQuestionOfString() async {
+ await assertNoErrorsInCode('''
+void main(List<String>? args) {}
+''');
+ }
+
+ test_positionalRequired_objectQuestion() async {
+ await assertNoErrorsInCode('''
+void main(Object? args) {}
+''');
+ }
+}
mixin MainFirstPositionalParameterTestCases on PubPackageResolutionTest {
test_positionalOptional_listOfInt() async {
@@ -72,24 +90,6 @@
}
@reflectiveTest
-class MainFirstPositionalParameterWithNullSafetyTest
+class MainFirstPositionalParameterWithoutNullSafetyTest
extends PubPackageResolutionTest
- with MainFirstPositionalParameterTestCases {
- test_positionalRequired_listOfStringQuestion() async {
- await assertNoErrorsInCode('''
-void main(List<String?> args) {}
-''');
- }
-
- test_positionalRequired_listQuestionOfString() async {
- await assertNoErrorsInCode('''
-void main(List<String>? args) {}
-''');
- }
-
- test_positionalRequired_objectQuestion() async {
- await assertNoErrorsInCode('''
-void main(Object? args) {}
-''');
- }
-}
+ with WithoutNullSafetyMixin, MainFirstPositionalParameterTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart b/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart
index 46a8f2f..65e103e 100644
--- a/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/main_has_required_named_parameters_test.dart
@@ -10,13 +10,21 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MainHasRequiredNamedParametersTest);
- defineReflectiveTests(MainHasRequiredNamedParametersWithNullSafetyTest);
+ defineReflectiveTests(MainHasRequiredNamedParametersWithoutNullSafetyTest);
});
}
@reflectiveTest
class MainHasRequiredNamedParametersTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, MainHasRequiredNamedParametersTestCases {}
+ with MainHasRequiredNamedParametersTestCases {
+ test_namedRequired() async {
+ await assertErrorsInCode('''
+void main({required List<String> a}) {}
+''', [
+ error(CompileTimeErrorCode.MAIN_HAS_REQUIRED_NAMED_PARAMETERS, 5, 4),
+ ]);
+ }
+}
mixin MainHasRequiredNamedParametersTestCases on PubPackageResolutionTest {
test_namedOptional() async {
@@ -28,14 +36,6 @@
}
@reflectiveTest
-class MainHasRequiredNamedParametersWithNullSafetyTest
+class MainHasRequiredNamedParametersWithoutNullSafetyTest
extends PubPackageResolutionTest
- with MainHasRequiredNamedParametersTestCases {
- test_namedRequired() async {
- await assertErrorsInCode('''
-void main({required List<String> a}) {}
-''', [
- error(CompileTimeErrorCode.MAIN_HAS_REQUIRED_NAMED_PARAMETERS, 5, 4),
- ]);
- }
-}
+ with WithoutNullSafetyMixin, MainHasRequiredNamedParametersTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart b/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart
index b08a039..e1061f8 100644
--- a/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/main_has_too_many_required_positional_parameters_test.dart
@@ -9,9 +9,11 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(MainHasTooManyRequiredPositionalParametersTest);
defineReflectiveTests(
- MainHasTooManyRequiredPositionalParametersWithNullSafetyTest,
+ MainHasTooManyRequiredPositionalParametersTest,
+ );
+ defineReflectiveTests(
+ MainHasTooManyRequiredPositionalParametersWithoutNullSafetyTest,
);
});
}
@@ -19,9 +21,20 @@
@reflectiveTest
class MainHasTooManyRequiredPositionalParametersTest
extends PubPackageResolutionTest
- with
- WithoutNullSafetyMixin,
- MainHasTooManyRequiredPositionalParametersTestCases {}
+ with MainHasTooManyRequiredPositionalParametersTestCases {
+ test_positionalRequired_3_namedRequired_1() async {
+ await resolveTestCode('''
+void main(args, int a, int b, {required int c}) {}
+''');
+ assertErrorsInResult(expectedErrorsByNullability(nullable: [
+ error(CompileTimeErrorCode.MAIN_HAS_REQUIRED_NAMED_PARAMETERS, 5, 4),
+ error(
+ CompileTimeErrorCode.MAIN_HAS_TOO_MANY_REQUIRED_POSITIONAL_PARAMETERS,
+ 5,
+ 4),
+ ], legacy: []));
+ }
+}
mixin MainHasTooManyRequiredPositionalParametersTestCases
on PubPackageResolutionTest {
@@ -93,19 +106,8 @@
}
@reflectiveTest
-class MainHasTooManyRequiredPositionalParametersWithNullSafetyTest
+class MainHasTooManyRequiredPositionalParametersWithoutNullSafetyTest
extends PubPackageResolutionTest
- with MainHasTooManyRequiredPositionalParametersTestCases {
- test_positionalRequired_3_namedRequired_1() async {
- await resolveTestCode('''
-void main(args, int a, int b, {required int c}) {}
-''');
- assertErrorsInResult(expectedErrorsByNullability(nullable: [
- error(CompileTimeErrorCode.MAIN_HAS_REQUIRED_NAMED_PARAMETERS, 5, 4),
- error(
- CompileTimeErrorCode.MAIN_HAS_TOO_MANY_REQUIRED_POSITIONAL_PARAMETERS,
- 5,
- 4),
- ], legacy: []));
- }
-}
+ with
+ WithoutNullSafetyMixin,
+ MainHasTooManyRequiredPositionalParametersTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart b/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart
index 93d3d37..2cf8747 100644
--- a/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/main_is_not_function_test.dart
@@ -10,13 +10,13 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MainIsNotFunctionTest);
- defineReflectiveTests(MainIsNotFunctionWithNullSafetyTest);
+ defineReflectiveTests(MainIsNotFunctionWithoutNullSafetyTest);
});
}
@reflectiveTest
class MainIsNotFunctionTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, MainIsNotFunctionTestCases {}
+ with MainIsNotFunctionTestCases {}
mixin MainIsNotFunctionTestCases on PubPackageResolutionTest {
test_class() async {
@@ -104,5 +104,5 @@
}
@reflectiveTest
-class MainIsNotFunctionWithNullSafetyTest extends PubPackageResolutionTest
- with MainIsNotFunctionTestCases {}
+class MainIsNotFunctionWithoutNullSafetyTest extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, MainIsNotFunctionTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart b/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart
index 456f6d0..c70450c 100644
--- a/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart
@@ -11,239 +11,12 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MissingRequiredParamTest);
- defineReflectiveTests(MissingRequiredParamWithNullSafetyTest);
+ defineReflectiveTests(MissingRequiredParamWithoutNullSafetyTest);
});
}
@reflectiveTest
-class MissingRequiredParamTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
- @override
- void setUp() {
- super.setUp();
- writeTestPackageConfigWithMeta();
- }
-
- test_constructor_argumentGiven() async {
- await assertNoErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class C {
- C({@required int a}) {}
-}
-
-main() {
- new C(a: 2);
-}
-''');
- }
-
- test_constructor_fieldFormalParameter() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class C {
- final int a;
- C({@required this.a});
-}
-
-main() {
- new C();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM, 102, 1),
- ]);
- }
-
- test_constructor_hasReason() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-class C {
- C({@Required('must specify an `a`') int a}) {}
-}
-main() {
- new C();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 109, 1),
- ]);
- }
-
- test_constructor_noReason() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class C {
- C({@required int a}) {}
-}
-
-main() {
- new C();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM, 88, 1),
- ]);
- }
-
- test_constructor_noReason_generic() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class C<T> {
- C({@required int a}) {}
-}
-
-main() {
- new C();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM, 91, 1),
- ]);
- }
-
- test_constructor_nullReason() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class C {
- C({@Required(null) int a}) {}
-}
-
-main() {
- new C();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM, 94, 1),
- ]);
- }
-
- test_constructor_redirectingConstructorCall() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-class C {
- C({@required int x});
- C.named() : this();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM, 81, 6),
- ]);
- }
-
- test_constructor_superCall() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class C {
- C({@Required('must specify an `a`') int a}) {}
-}
-
-class D extends C {
- D() : super();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 124, 7),
- ]);
- }
-
- test_function() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-void f({@Required('must specify an `a`') int a}) {}
-
-main() {
- f();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 98, 1),
- ]);
- }
-
- test_method() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-class A {
- void m({@Required('must specify an `a`') int a}) {}
-}
-f() {
- new A().m();
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 115, 1),
- ]);
- }
-
- test_method_generic() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-class A<T> {
- void m<U>(U a, {@Required('must specify an `b`') int b}) {}
-}
-f() {
- new A<double>().m(true);
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 135, 1),
- ]);
- }
-
- test_method_inOtherLib() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-import 'package:meta/meta.dart';
-class A {
- void m({@Required('must specify an `a`') int a}) {}
-}
-''');
- newFile('$testPackageLibPath/test.dart', content: r'''
-import 'a.dart';
-f() {
- new A().m();
-}
-''');
-
- await _resolveFile('$testPackageLibPath/a.dart');
- await _resolveFile('$testPackageLibPath/test.dart', [
- error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 33, 1),
- ]);
- }
-
- @FailingTest(reason: r'''
-MISSING_REQUIRED_PARAM cannot be reported here with summary2, because
-the return type of `C.m` is a structural FunctionType, which does
-not know its elements, and does not know that there was a parameter
-marked `@required`. There is exactly one such typedef in Flutter.
-''')
- test_typedef_function() async {
- await assertErrorsInCode(r'''
-import 'package:meta/meta.dart';
-
-String test(C c) => c.m()();
-
-typedef String F({@required String x});
-
-class C {
- F m() => ({@required String x}) => null;
-}
-''', [
- error(HintCode.MISSING_REQUIRED_PARAM, 54, 7),
- ]);
- }
-
- /// Resolve the file with the given [path].
- ///
- /// Similar to ResolutionTest.resolveTestFile, but a custom path is supported.
- Future<void> _resolveFile(
- String path, [
- List<ExpectedError> expectedErrors = const [],
- ]) async {
- result = await resolveFile(convertPath(path));
- assertErrorsInResolvedUnit(result, expectedErrors);
- }
-}
-
-@reflectiveTest
-class MissingRequiredParamWithNullSafetyTest extends PubPackageResolutionTest {
+class MissingRequiredParamTest extends PubPackageResolutionTest {
test_constructor_legacy_argumentGiven() async {
newFile('$testPackageLibPath/a.dart', content: r'''
class A {
@@ -492,3 +265,230 @@
]);
}
}
+
+@reflectiveTest
+class MissingRequiredParamWithoutNullSafetyTest extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin {
+ @override
+ void setUp() {
+ super.setUp();
+ writeTestPackageConfigWithMeta();
+ }
+
+ test_constructor_argumentGiven() async {
+ await assertNoErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class C {
+ C({@required int a}) {}
+}
+
+main() {
+ new C(a: 2);
+}
+''');
+ }
+
+ test_constructor_fieldFormalParameter() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class C {
+ final int a;
+ C({@required this.a});
+}
+
+main() {
+ new C();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM, 102, 1),
+ ]);
+ }
+
+ test_constructor_hasReason() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+class C {
+ C({@Required('must specify an `a`') int a}) {}
+}
+main() {
+ new C();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 109, 1),
+ ]);
+ }
+
+ test_constructor_noReason() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class C {
+ C({@required int a}) {}
+}
+
+main() {
+ new C();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM, 88, 1),
+ ]);
+ }
+
+ test_constructor_noReason_generic() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class C<T> {
+ C({@required int a}) {}
+}
+
+main() {
+ new C();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM, 91, 1),
+ ]);
+ }
+
+ test_constructor_nullReason() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class C {
+ C({@Required(null) int a}) {}
+}
+
+main() {
+ new C();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM, 94, 1),
+ ]);
+ }
+
+ test_constructor_redirectingConstructorCall() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+class C {
+ C({@required int x});
+ C.named() : this();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM, 81, 6),
+ ]);
+ }
+
+ test_constructor_superCall() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class C {
+ C({@Required('must specify an `a`') int a}) {}
+}
+
+class D extends C {
+ D() : super();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 124, 7),
+ ]);
+ }
+
+ test_function() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+void f({@Required('must specify an `a`') int a}) {}
+
+main() {
+ f();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 98, 1),
+ ]);
+ }
+
+ test_method() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+class A {
+ void m({@Required('must specify an `a`') int a}) {}
+}
+f() {
+ new A().m();
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 115, 1),
+ ]);
+ }
+
+ test_method_generic() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+class A<T> {
+ void m<U>(U a, {@Required('must specify an `b`') int b}) {}
+}
+f() {
+ new A<double>().m(true);
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 135, 1),
+ ]);
+ }
+
+ test_method_inOtherLib() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+import 'package:meta/meta.dart';
+class A {
+ void m({@Required('must specify an `a`') int a}) {}
+}
+''');
+ newFile('$testPackageLibPath/test.dart', content: r'''
+import 'a.dart';
+f() {
+ new A().m();
+}
+''');
+
+ await _resolveFile('$testPackageLibPath/a.dart');
+ await _resolveFile('$testPackageLibPath/test.dart', [
+ error(HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS, 33, 1),
+ ]);
+ }
+
+ @FailingTest(reason: r'''
+MISSING_REQUIRED_PARAM cannot be reported here with summary2, because
+the return type of `C.m` is a structural FunctionType, which does
+not know its elements, and does not know that there was a parameter
+marked `@required`. There is exactly one such typedef in Flutter.
+''')
+ test_typedef_function() async {
+ await assertErrorsInCode(r'''
+import 'package:meta/meta.dart';
+
+String test(C c) => c.m()();
+
+typedef String F({@required String x});
+
+class C {
+ F m() => ({@required String x}) => null;
+}
+''', [
+ error(HintCode.MISSING_REQUIRED_PARAM, 54, 7),
+ ]);
+ }
+
+ /// Resolve the file with the given [path].
+ ///
+ /// Similar to ResolutionTest.resolveTestFile, but a custom path is supported.
+ Future<void> _resolveFile(
+ String path, [
+ List<ExpectedError> expectedErrors = const [],
+ ]) async {
+ result = await resolveFile(convertPath(path));
+ assertErrorsInResolvedUnit(result, expectedErrors);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/missing_return_test.dart b/pkg/analyzer/test/src/diagnostics/missing_return_test.dart
index 9f75275..4c1104b 100644
--- a/pkg/analyzer/test/src/diagnostics/missing_return_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/missing_return_test.dart
@@ -10,12 +10,62 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MissingReturnTest);
- defineReflectiveTests(MissingReturnWithNullSafetyTest);
+ defineReflectiveTests(MissingReturnWithoutNullSafetyTest);
});
}
@reflectiveTest
-class MissingReturnTest extends PubPackageResolutionTest
+class MissingReturnTest extends PubPackageResolutionTest {
+ test_function_async_block_futureOrVoid() async {
+ await assertNoErrorsInCode('''
+import 'dart:async';
+FutureOr<void> f() async {}
+''');
+ }
+
+ test_function_async_block_void() async {
+ await assertNoErrorsInCode('''
+void f() async {}
+''');
+ }
+
+ test_function_sync_block_dynamic() async {
+ await assertNoErrorsInCode('''
+dynamic f() {}
+''');
+ }
+
+ test_function_sync_block_Never() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+Never foo() {
+ throw 0;
+}
+''');
+ await assertNoErrorsInCode(r'''
+// @dart = 2.8
+import 'a.dart';
+
+int f() {
+ foo();
+}
+''');
+ }
+
+ test_function_sync_block_Null() async {
+ await assertNoErrorsInCode('''
+Null f() {}
+''');
+ }
+
+ test_function_sync_block_void() async {
+ await assertNoErrorsInCode('''
+void f() {}
+''');
+ }
+}
+
+@reflectiveTest
+class MissingReturnWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_alwaysThrows() async {
writeTestPackageConfigWithMeta();
@@ -214,53 +264,3 @@
]);
}
}
-
-@reflectiveTest
-class MissingReturnWithNullSafetyTest extends PubPackageResolutionTest {
- test_function_async_block_futureOrVoid() async {
- await assertNoErrorsInCode('''
-import 'dart:async';
-FutureOr<void> f() async {}
-''');
- }
-
- test_function_async_block_void() async {
- await assertNoErrorsInCode('''
-void f() async {}
-''');
- }
-
- test_function_sync_block_dynamic() async {
- await assertNoErrorsInCode('''
-dynamic f() {}
-''');
- }
-
- test_function_sync_block_Never() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-Never foo() {
- throw 0;
-}
-''');
- await assertNoErrorsInCode(r'''
-// @dart = 2.8
-import 'a.dart';
-
-int f() {
- foo();
-}
-''');
- }
-
- test_function_sync_block_Null() async {
- await assertNoErrorsInCode('''
-Null f() {}
-''');
- }
-
- test_function_sync_block_void() async {
- await assertNoErrorsInCode('''
-void f() {}
-''');
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart
index 6dc76c1..2ba1557 100644
--- a/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/mixin_inference_no_possible_substitution_test.dart
@@ -9,36 +9,17 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(MixinInferenceNoPossibleSubstitutionTest);
defineReflectiveTests(
- MixinInferenceNoPossibleSubstitutionWithNullSafetyTest,
+ MixinInferenceNoPossibleSubstitutionTest,
+ );
+ defineReflectiveTests(
+ MixinInferenceNoPossibleSubstitutionWithoutNullSafetyTest,
);
});
}
@reflectiveTest
class MixinInferenceNoPossibleSubstitutionTest extends PubPackageResolutionTest
- with
- WithoutNullSafetyMixin,
- MixinInferenceNoPossibleSubstitutionTestCases {}
-
-mixin MixinInferenceNoPossibleSubstitutionTestCases on ResolutionTest {
- test_valid_single() async {
- await assertNoErrorsInCode(r'''
-class A<T> {}
-
-mixin M<T> on A<T> {}
-
-class X extends A<int> with M {}
-''');
-
- assertType(findNode.namedType('M {}'), 'M<int>');
- }
-}
-
-@reflectiveTest
-class MixinInferenceNoPossibleSubstitutionWithNullSafetyTest
- extends PubPackageResolutionTest
with MixinInferenceNoPossibleSubstitutionTestCases {
test_valid_nonNullableMixins_legacyApplication() async {
newFile('$testPackageLibPath/a.dart', content: r'''
@@ -59,3 +40,24 @@
assertType(findNode.namedType('C {}'), 'C<int*>*');
}
}
+
+mixin MixinInferenceNoPossibleSubstitutionTestCases on ResolutionTest {
+ test_valid_single() async {
+ await assertNoErrorsInCode(r'''
+class A<T> {}
+
+mixin M<T> on A<T> {}
+
+class X extends A<int> with M {}
+''');
+
+ assertType(findNode.namedType('M {}'), 'M<int>');
+ }
+}
+
+@reflectiveTest
+class MixinInferenceNoPossibleSubstitutionWithoutNullSafetyTest
+ extends PubPackageResolutionTest
+ with
+ WithoutNullSafetyMixin,
+ MixinInferenceNoPossibleSubstitutionTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart
index 0d92e85..1d80a8d 100644
--- a/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/no_default_super_constructor_test.dart
@@ -10,95 +10,13 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NoDefaultSuperConstructorTest);
- defineReflectiveTests(NoDefaultSuperConstructorWithNullSafetyTest);
+ defineReflectiveTests(NoDefaultSuperConstructorWithoutNullSafetyTest);
});
}
@reflectiveTest
class NoDefaultSuperConstructorTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, NoDefaultSuperConstructorTestCases {
- test_super_requiredPositional_subclass_explicit() async {
- await assertErrorsInCode(r'''
-class A {
- A(p);
-}
-class B extends A {
- B();
-}
-''', [
- error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, 42, 1),
- ]);
- }
-}
-
-mixin NoDefaultSuperConstructorTestCases on PubPackageResolutionTest {
- test_super_implicit_subclass_explicit() async {
- await assertNoErrorsInCode(r'''
-class A {}
-class B extends A {
- B();
-}
-''');
- }
-
- test_super_implicit_subclass_implicit() async {
- await assertNoErrorsInCode(r'''
-class A {}
-class B extends A {}
-''');
- }
-
- test_super_noParameters() async {
- await assertNoErrorsInCode(r'''
-class A {
- A();
-}
-class B extends A {
- B();
-}
-''');
- }
-
- test_super_requiredPositional_subclass_explicit_language214() async {
- await assertErrorsInCode(r'''
-// @dart = 2.14
-class A {
- A(p);
-}
-class B extends A {
- B();
-}
-''', [
- error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, 58, 1),
- ]);
- }
-
- test_super_requiredPositional_subclass_external() async {
- await assertNoErrorsInCode(r'''
-class A {
- A(p);
-}
-class B extends A {
- external B();
-}
-''');
- }
-
- test_super_requiredPositional_subclass_implicit() async {
- await assertErrorsInCode(r'''
-class A {
- A(p);
-}
-class B extends A {}
-''', [
- error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, 26, 1),
- ]);
- }
-}
-
-@reflectiveTest
-class NoDefaultSuperConstructorWithNullSafetyTest
- extends PubPackageResolutionTest with NoDefaultSuperConstructorTestCases {
+ with NoDefaultSuperConstructorTestCases {
test_super_optionalNamed_subclass_explicit() async {
await assertNoErrorsInCode(r'''
class A {
@@ -310,3 +228,86 @@
''');
}
}
+
+mixin NoDefaultSuperConstructorTestCases on PubPackageResolutionTest {
+ test_super_implicit_subclass_explicit() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+class B extends A {
+ B();
+}
+''');
+ }
+
+ test_super_implicit_subclass_implicit() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+class B extends A {}
+''');
+ }
+
+ test_super_noParameters() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ A();
+}
+class B extends A {
+ B();
+}
+''');
+ }
+
+ test_super_requiredPositional_subclass_explicit_language214() async {
+ await assertErrorsInCode(r'''
+// @dart = 2.14
+class A {
+ A(p);
+}
+class B extends A {
+ B();
+}
+''', [
+ error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, 58, 1),
+ ]);
+ }
+
+ test_super_requiredPositional_subclass_external() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ A(p);
+}
+class B extends A {
+ external B();
+}
+''');
+ }
+
+ test_super_requiredPositional_subclass_implicit() async {
+ await assertErrorsInCode(r'''
+class A {
+ A(p);
+}
+class B extends A {}
+''', [
+ error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, 26, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class NoDefaultSuperConstructorWithoutNullSafetyTest
+ extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, NoDefaultSuperConstructorTestCases {
+ test_super_requiredPositional_subclass_explicit() async {
+ await assertErrorsInCode(r'''
+class A {
+ A(p);
+}
+class B extends A {
+ B();
+}
+''', [
+ error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, 42, 1),
+ ]);
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart b/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart
index 5976ffd..028a5c4 100644
--- a/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/non_abstract_class_inherits_abstract_member_test.dart
@@ -9,18 +9,287 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(NonAbstractClassInheritsAbstractMemberTest);
defineReflectiveTests(
- NonAbstractClassInheritsAbstractMemberWithNullSafetyTest);
+ NonAbstractClassInheritsAbstractMemberTest,
+ );
+ defineReflectiveTests(
+ NonAbstractClassInheritsAbstractMemberWithoutNullSafetyTest,
+ );
});
}
@reflectiveTest
class NonAbstractClassInheritsAbstractMemberTest
extends PubPackageResolutionTest
- with
- WithoutNullSafetyMixin,
- NonAbstractClassInheritsAbstractMemberTestCases {}
+ with NonAbstractClassInheritsAbstractMemberTestCases {
+ test_abstract_field_final_implement_getter() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract final int x;
+}
+class B implements A {
+ int get x => 0;
+}
+''');
+ }
+
+ test_abstract_field_final_implement_none() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract final int x;
+}
+class B implements A {}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 51,
+ 1),
+ ]);
+ }
+
+ test_abstract_field_implement_getter() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+class B implements A {
+ int get x => 0;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 45,
+ 1),
+ ]);
+ }
+
+ test_abstract_field_implement_getter_and_setter() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+class B implements A {
+ int get x => 0;
+ void set x(int value) {}
+}
+''');
+ }
+
+ test_abstract_field_implement_none() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+class B implements A {}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO,
+ 45,
+ 1),
+ ]);
+ }
+
+ test_abstract_field_implement_setter() async {
+ await assertErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+class B implements A {
+ void set x(int value) {}
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 45,
+ 1),
+ ]);
+ }
+
+ test_enum_getter_fromInterface() async {
+ await assertErrorsInCode('''
+class A {
+ int get foo => 0;
+}
+
+enum E implements A {
+ v;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 38,
+ 1),
+ ]);
+ }
+
+ test_enum_getter_fromMixin() async {
+ await assertErrorsInCode('''
+mixin M {
+ int get foo;
+}
+
+enum E with M {
+ v;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 33,
+ 1),
+ ]);
+ }
+
+ test_enum_method_fromInterface() async {
+ await assertErrorsInCode('''
+class A {
+ void foo() {}
+}
+
+enum E implements A {
+ v;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 34,
+ 1),
+ ]);
+ }
+
+ test_enum_method_fromMixin() async {
+ await assertErrorsInCode('''
+mixin M {
+ void foo();
+}
+
+enum E with M {
+ v;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 32,
+ 1),
+ ]);
+ }
+
+ test_enum_setter_fromInterface() async {
+ await assertErrorsInCode('''
+class A {
+ set foo(int _) {}
+}
+
+enum E implements A {
+ v;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 38,
+ 1),
+ ]);
+ }
+
+ test_enum_setter_fromMixin() async {
+ await assertErrorsInCode('''
+mixin M {
+ set foo(int _);
+}
+
+enum E with M {
+ v;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 36,
+ 1),
+ ]);
+ }
+
+ test_external_field_final_implement_getter() async {
+ await assertNoErrorsInCode('''
+class A {
+ external final int x;
+}
+class B implements A {
+ int get x => 0;
+}
+''');
+ }
+
+ test_external_field_final_implement_none() async {
+ await assertErrorsInCode('''
+class A {
+ external final int x;
+}
+class B implements A {}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 42,
+ 1),
+ ]);
+ }
+
+ test_external_field_implement_getter() async {
+ await assertErrorsInCode('''
+class A {
+ external int x;
+}
+class B implements A {
+ int get x => 0;
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 36,
+ 1),
+ ]);
+ }
+
+ test_external_field_implement_getter_and_setter() async {
+ await assertNoErrorsInCode('''
+class A {
+ external int x;
+}
+class B implements A {
+ int get x => 0;
+ void set x(int value) {}
+}
+''');
+ }
+
+ test_external_field_implement_none() async {
+ await assertErrorsInCode('''
+class A {
+ external int x;
+}
+class B implements A {}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO,
+ 36,
+ 1),
+ ]);
+ }
+
+ test_external_field_implement_setter() async {
+ await assertErrorsInCode('''
+class A {
+ external int x;
+}
+class B implements A {
+ void set x(int value) {}
+}
+''', [
+ error(
+ CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ 36,
+ 1),
+ ]);
+ }
+}
mixin NonAbstractClassInheritsAbstractMemberTestCases
on PubPackageResolutionTest {
@@ -616,274 +885,8 @@
}
@reflectiveTest
-class NonAbstractClassInheritsAbstractMemberWithNullSafetyTest
+class NonAbstractClassInheritsAbstractMemberWithoutNullSafetyTest
extends PubPackageResolutionTest
- with NonAbstractClassInheritsAbstractMemberTestCases {
- test_abstract_field_final_implement_getter() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract final int x;
-}
-class B implements A {
- int get x => 0;
-}
-''');
- }
-
- test_abstract_field_final_implement_none() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract final int x;
-}
-class B implements A {}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 51,
- 1),
- ]);
- }
-
- test_abstract_field_implement_getter() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-class B implements A {
- int get x => 0;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 45,
- 1),
- ]);
- }
-
- test_abstract_field_implement_getter_and_setter() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-class B implements A {
- int get x => 0;
- void set x(int value) {}
-}
-''');
- }
-
- test_abstract_field_implement_none() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-class B implements A {}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO,
- 45,
- 1),
- ]);
- }
-
- test_abstract_field_implement_setter() async {
- await assertErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-class B implements A {
- void set x(int value) {}
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 45,
- 1),
- ]);
- }
-
- test_enum_getter_fromInterface() async {
- await assertErrorsInCode('''
-class A {
- int get foo => 0;
-}
-
-enum E implements A {
- v;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 38,
- 1),
- ]);
- }
-
- test_enum_getter_fromMixin() async {
- await assertErrorsInCode('''
-mixin M {
- int get foo;
-}
-
-enum E with M {
- v;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 33,
- 1),
- ]);
- }
-
- test_enum_method_fromInterface() async {
- await assertErrorsInCode('''
-class A {
- void foo() {}
-}
-
-enum E implements A {
- v;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 34,
- 1),
- ]);
- }
-
- test_enum_method_fromMixin() async {
- await assertErrorsInCode('''
-mixin M {
- void foo();
-}
-
-enum E with M {
- v;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 32,
- 1),
- ]);
- }
-
- test_enum_setter_fromInterface() async {
- await assertErrorsInCode('''
-class A {
- set foo(int _) {}
-}
-
-enum E implements A {
- v;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 38,
- 1),
- ]);
- }
-
- test_enum_setter_fromMixin() async {
- await assertErrorsInCode('''
-mixin M {
- set foo(int _);
-}
-
-enum E with M {
- v;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 36,
- 1),
- ]);
- }
-
- test_external_field_final_implement_getter() async {
- await assertNoErrorsInCode('''
-class A {
- external final int x;
-}
-class B implements A {
- int get x => 0;
-}
-''');
- }
-
- test_external_field_final_implement_none() async {
- await assertErrorsInCode('''
-class A {
- external final int x;
-}
-class B implements A {}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 42,
- 1),
- ]);
- }
-
- test_external_field_implement_getter() async {
- await assertErrorsInCode('''
-class A {
- external int x;
-}
-class B implements A {
- int get x => 0;
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 36,
- 1),
- ]);
- }
-
- test_external_field_implement_getter_and_setter() async {
- await assertNoErrorsInCode('''
-class A {
- external int x;
-}
-class B implements A {
- int get x => 0;
- void set x(int value) {}
-}
-''');
- }
-
- test_external_field_implement_none() async {
- await assertErrorsInCode('''
-class A {
- external int x;
-}
-class B implements A {}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO,
- 36,
- 1),
- ]);
- }
-
- test_external_field_implement_setter() async {
- await assertErrorsInCode('''
-class A {
- external int x;
-}
-class B implements A {
- void set x(int value) {}
-}
-''', [
- error(
- CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- 36,
- 1),
- ]);
- }
-}
+ with
+ WithoutNullSafetyMixin,
+ NonAbstractClassInheritsAbstractMemberTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart
index 3f99747..03a7c93 100644
--- a/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart
@@ -9,16 +9,84 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(NonBoolConditionTest);
+ defineReflectiveTests(NonBoolConditionWithoutNullSafetyTest);
defineReflectiveTests(
NonBoolConditionWithoutNullSafetyAndNoImplicitCastsTest);
- defineReflectiveTests(NonBoolConditionWithNullSafetyTest);
+ defineReflectiveTests(NonBoolConditionTest);
defineReflectiveTests(NonBoolConditionWithStrictCastsTest);
});
}
@reflectiveTest
-class NonBoolConditionTest extends PubPackageResolutionTest
+class NonBoolConditionTest extends PubPackageResolutionTest {
+ test_if_null() async {
+ await assertErrorsInCode(r'''
+void f(Null a) {
+ if (a) {}
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 23, 1),
+ ]);
+ }
+
+ test_ternary_condition_null() async {
+ await assertErrorsInCode(r'''
+void f(Null a) {
+ a ? 0 : 1;
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 19, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class NonBoolConditionWithoutNullSafetyAndNoImplicitCastsTest
+ extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
+ test_map_ifElement_condition_dynamic() async {
+ await assertErrorsWithNoImplicitCasts(r'''
+void f(dynamic c) {
+ <int, int>{if (c) 0: 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 37, 1),
+ ]);
+ }
+
+ test_map_ifElement_condition_object() async {
+ await assertErrorsWithNoImplicitCasts(r'''
+void f(Object c) {
+ <int, int>{if (c) 0: 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 36, 1),
+ ]);
+ }
+
+ test_set_ifElement_condition_dynamic() async {
+ await assertErrorsWithNoImplicitCasts(r'''
+void f(dynamic c) {
+ <int>{if (c) 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 32, 1),
+ ]);
+ }
+
+ test_set_ifElement_condition_object() async {
+ await assertErrorsWithNoImplicitCasts(r'''
+void f(Object c) {
+ <int>{if (c) 0};
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_CONDITION, 31, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class NonBoolConditionWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_conditional() async {
await assertErrorsInCode('''
@@ -216,74 +284,6 @@
}
@reflectiveTest
-class NonBoolConditionWithNullSafetyTest extends PubPackageResolutionTest {
- test_if_null() async {
- await assertErrorsInCode(r'''
-void f(Null a) {
- if (a) {}
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_CONDITION, 23, 1),
- ]);
- }
-
- test_ternary_condition_null() async {
- await assertErrorsInCode(r'''
-void f(Null a) {
- a ? 0 : 1;
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_CONDITION, 19, 1),
- ]);
- }
-}
-
-@reflectiveTest
-class NonBoolConditionWithoutNullSafetyAndNoImplicitCastsTest
- extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
- test_map_ifElement_condition_dynamic() async {
- await assertErrorsWithNoImplicitCasts(r'''
-void f(dynamic c) {
- <int, int>{if (c) 0: 0};
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_CONDITION, 37, 1),
- ]);
- }
-
- test_map_ifElement_condition_object() async {
- await assertErrorsWithNoImplicitCasts(r'''
-void f(Object c) {
- <int, int>{if (c) 0: 0};
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_CONDITION, 36, 1),
- ]);
- }
-
- test_set_ifElement_condition_dynamic() async {
- await assertErrorsWithNoImplicitCasts(r'''
-void f(dynamic c) {
- <int>{if (c) 0};
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_CONDITION, 32, 1),
- ]);
- }
-
- test_set_ifElement_condition_object() async {
- await assertErrorsWithNoImplicitCasts(r'''
-void f(Object c) {
- <int>{if (c) 0};
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_CONDITION, 31, 1),
- ]);
- }
-}
-
-@reflectiveTest
class NonBoolConditionWithStrictCastsTest extends PubPackageResolutionTest
with WithStrictCastsMixin {
test_map_ifElement_condition() async {
diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart
index f0578ad..6b7c2c2 100644
--- a/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart
@@ -10,14 +10,27 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NonBoolNegationExpressionTest);
- defineReflectiveTests(NonBoolNegationExpressionWithNullSafetyTest);
+ defineReflectiveTests(NonBoolNegationExpressionWithoutNullSafetyTest);
defineReflectiveTests(NonBoolNegationExpressionWithStrictCastsTest);
});
}
@reflectiveTest
-class NonBoolNegationExpressionTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin {
+class NonBoolNegationExpressionTest extends PubPackageResolutionTest {
+ test_null() async {
+ await assertErrorsInCode('''
+void m(Null x) {
+ !x;
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_NEGATION_EXPRESSION, 20, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class NonBoolNegationExpressionWithoutNullSafetyTest
+ extends PubPackageResolutionTest with WithoutNullSafetyMixin {
test_nonBool() async {
await assertErrorsInCode(r'''
f() {
@@ -48,20 +61,6 @@
}
@reflectiveTest
-class NonBoolNegationExpressionWithNullSafetyTest
- extends PubPackageResolutionTest {
- test_null() async {
- await assertErrorsInCode('''
-void m(Null x) {
- !x;
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_NEGATION_EXPRESSION, 20, 1),
- ]);
- }
-}
-
-@reflectiveTest
class NonBoolNegationExpressionWithStrictCastsTest
extends PubPackageResolutionTest with WithStrictCastsMixin {
test_negation() async {
diff --git a/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart b/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart
index 1b25120..027813b 100644
--- a/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart
@@ -10,13 +10,38 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NonBoolOperandTest);
- defineReflectiveTests(NonBoolOperandWithNullSafetyTest);
+ defineReflectiveTests(NonBoolOperandWithoutNullSafetyTest);
defineReflectiveTests(NonBoolOperandWithStrictCastsTest);
});
}
@reflectiveTest
-class NonBoolOperandTest extends PubPackageResolutionTest
+class NonBoolOperandTest extends PubPackageResolutionTest {
+ test_and_null() async {
+ await assertErrorsInCode(r'''
+m() {
+ Null x;
+ if(x && true) {}
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_OPERAND, 21, 1),
+ ]);
+ }
+
+ test_or_null() async {
+ await assertErrorsInCode(r'''
+m() {
+ Null x;
+ if(x || false) {}
+}
+''', [
+ error(CompileTimeErrorCode.NON_BOOL_OPERAND, 21, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class NonBoolOperandWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_and_left() async {
await assertErrorsInCode(r'''
@@ -88,31 +113,6 @@
}
@reflectiveTest
-class NonBoolOperandWithNullSafetyTest extends PubPackageResolutionTest {
- test_and_null() async {
- await assertErrorsInCode(r'''
-m() {
- Null x;
- if(x && true) {}
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_OPERAND, 21, 1),
- ]);
- }
-
- test_or_null() async {
- await assertErrorsInCode(r'''
-m() {
- Null x;
- if(x || false) {}
-}
-''', [
- error(CompileTimeErrorCode.NON_BOOL_OPERAND, 21, 1),
- ]);
- }
-}
-
-@reflectiveTest
class NonBoolOperandWithStrictCastsTest extends PubPackageResolutionTest
with WithStrictCastsMixin {
test_and() async {
diff --git a/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart b/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart
index ef2d1d9..b4dece1 100644
--- a/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart
@@ -10,12 +10,12 @@
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(ReadWriteWithNullSafetyTest);
+ defineReflectiveTests(ReadWriteTest);
});
}
@reflectiveTest
-class ReadWriteWithNullSafetyTest extends PubPackageResolutionTest {
+class ReadWriteTest extends PubPackageResolutionTest {
@override
bool get retainDataForTesting => true;
diff --git a/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart b/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart
index 2aea194..3540ebc 100644
--- a/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart
@@ -11,15 +11,278 @@
defineReflectiveSuite(() {
defineReflectiveTests(TypeArgumentNotMatchingBoundsTest);
defineReflectiveTests(
- TypeArgumentNotMatchingBoundsWithNullSafetyTest,
+ TypeArgumentNotMatchingBoundsWithoutNullSafetyTest,
);
});
}
@reflectiveTest
class TypeArgumentNotMatchingBoundsTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, TypeArgumentNotMatchingBoundsTestCases {
- test_regression_42196_Null() async {
+ with TypeArgumentNotMatchingBoundsTestCases {
+ test_enum_inferred() async {
+ await assertErrorsInCode('''
+enum E<T extends int> {
+ v('');
+ const E(T t);
+}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 26, 1),
+ ]);
+ }
+
+ test_enum_superBounded() async {
+ await assertNoErrorsInCode('''
+enum E<T extends E<T>> {
+ v<Never>()
+}
+''');
+ }
+
+ test_enum_withTypeArguments() async {
+ await assertErrorsInCode('''
+enum E<T extends int> {
+ v<String>()
+}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 28, 6),
+ ]);
+ }
+
+ test_extends_optIn_fromOptOut_Null() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A<X extends int> {}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart=2.6
+import 'a.dart';
+
+class A1<T extends Null> extends A<T> {}
+''');
+ }
+
+ test_extends_optIn_fromOptOut_otherTypeParameter() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+void foo<T extends U, U>() {
+}
+''');
+
+ await assertNoErrorsInCode(r'''
+// @dart=2.6
+import 'a.dart';
+
+class A {}
+class B extends A {}
+
+main() {
+ foo<B, A>();
+}
+''');
+ }
+
+ test_functionReference() async {
+ await assertErrorsInCode('''
+void foo<T extends num>(T a) {}
+void bar() {
+ foo<String>;
+}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 51, 6),
+ ]);
+ }
+
+ test_functionReference_matching() async {
+ await assertNoErrorsInCode('''
+void foo<T extends num>(T a) {}
+void bar() {
+ foo<int>;
+}
+''');
+ }
+
+ test_functionReference_regularBounded() async {
+ await assertNoErrorsInCode('''
+void foo<T>(T a) {}
+void bar() {
+ foo<String>;
+}
+''');
+ }
+
+ test_genericFunctionTypeArgument_invariant() async {
+ await assertErrorsInCode(r'''
+typedef F = T Function<T>(T);
+typedef FB<T extends F> = S Function<S extends T>(S);
+class CB<T extends F> {}
+void f(CB<FB<F>> a) {}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 119, 5,
+ contextMessages: [message('/home/test/lib/test.dart', 116, 9)]),
+ ]);
+ }
+
+ test_genericFunctionTypeArgument_regularBounded() async {
+ await assertNoErrorsInCode(r'''
+typedef F1 = T Function<T>(T);
+typedef F2 = S Function<S>(S);
+class CB<T extends F1> {}
+void f(CB<F2> a) {}
+''');
+ }
+
+ test_metadata_matching() async {
+ await assertNoErrorsInCode(r'''
+class A<T extends num> {
+ const A();
+}
+
+@A<int>()
+void f() {}
+''');
+ }
+
+ test_metadata_notMatching() async {
+ await assertErrorsInCode(r'''
+class A<T extends num> {
+ const A();
+}
+
+@A<String>()
+void f() {}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 44, 6),
+ ]);
+ }
+
+ test_metadata_notMatching_viaTypeAlias() async {
+ await assertErrorsInCode(r'''
+class A<T> {
+ const A();
+}
+
+typedef B<T extends num> = A<T>;
+
+@B<String>()
+void f() {}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 66, 6),
+ ]);
+ }
+
+ test_methodInvocation_genericFunctionTypeArgument_match() async {
+ await assertNoErrorsInCode(r'''
+typedef F = void Function<T extends num>();
+void f<T extends void Function<X extends num>()>() {}
+void g() {
+ f<F>();
+}
+''');
+ }
+
+ test_methodInvocation_genericFunctionTypeArgument_mismatch() async {
+ await assertErrorsInCode(r'''
+class A {}
+class B {}
+typedef F = void Function<T extends A>();
+void f<T extends void Function<U extends B>()>() {}
+void g() {
+ f<F>();
+}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 131, 1),
+ ]);
+ }
+
+ test_nonFunctionTypeAlias_body_typeArgument_mismatch() async {
+ await assertErrorsInCode(r'''
+class A {}
+class B {}
+class G<T extends A> {}
+typedef X = G<B>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1),
+ ]);
+ }
+
+ test_nonFunctionTypeAlias_body_typeArgument_regularBounded() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+class B extends A {}
+class G<T extends A> {}
+typedef X = G<B>;
+''');
+ }
+
+ test_nonFunctionTypeAlias_body_typeArgument_superBounded() async {
+ await assertNoErrorsInCode(r'''
+class A<T extends A<T>> {}
+typedef X = List<A>;
+''');
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_body_mismatch() async {
+ await assertErrorsInCode(r'''
+class A {}
+class B {}
+class G<T extends A> {}
+typedef X = G<B>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1),
+ ]);
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_body_regularBounded() async {
+ await assertNoErrorsInCode(r'''
+class A<T> {}
+typedef X<T> = A;
+''');
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_body_superBounded() async {
+ await assertErrorsInCode(r'''
+class A<T extends A<T>> {}
+typedef X<T> = A;
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 42, 1,
+ contextMessages: [message('/home/test/lib/test.dart', 42, 1)]),
+ ]);
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_parameter() async {
+ await assertErrorsInCode(r'''
+class A {}
+typedef X<T extends A> = Map<int, T>;
+void f(X<String> a) {}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 58, 6,
+ contextMessages: [message('/home/test/lib/test.dart', 56, 9)]),
+ ]);
+ }
+
+ test_nonFunctionTypeAlias_interfaceType_parameter_regularBounded() async {
+ await assertNoErrorsInCode(r'''
+class A {}
+class B extends A {}
+typedef X<T extends A> = Map<int, T>;
+void f(X<B> a) {}
+''');
+ }
+
+ test_notRegularBounded_notSuperBounded_parameter_invariant() async {
+ await assertErrorsInCode(r'''
+typedef A<X> = X Function(X);
+typedef G<X extends A<X>> = void Function<Y extends X>();
+foo(G g) {}
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 92, 1,
+ contextMessages: [
+ message('/home/test/lib/test.dart', 92, 1),
+ message('/home/test/lib/test.dart', 92, 1)
+ ]),
+ ]);
+ }
+
+ test_regression_42196() async {
await assertNoErrorsInCode(r'''
typedef G<X> = Function(X);
class A<X extends G<A<X,Y>>, Y extends X> {}
@@ -27,10 +290,75 @@
test<X>() { print("OK"); }
main() {
- test<A<G<A<Null, Null>>, dynamic>>();
+ test<A<G<A<Never, Never>>, dynamic>>();
}
''');
}
+
+ test_regression_42196_object() async {
+ await assertNoErrorsInCode(r'''
+typedef G<X> = Function(X);
+class A<X extends G<A<X, Y>>, Y extends Never> {}
+
+test<X>() { print("OK"); }
+
+main() {
+ test<A<G<A<Never, Never>>, Object?>>();
+}
+''');
+ }
+
+ test_regression_42196_void() async {
+ await assertNoErrorsInCode(r'''
+typedef G<X> = Function(X);
+class A<X extends G<A<X, Y>>, Y extends Never> {}
+
+test<X>() { print("OK"); }
+
+main() {
+ test<A<G<A<Never, Never>>, void>>();
+}
+''');
+ }
+
+ test_superBounded() async {
+ await assertNoErrorsInCode(r'''
+class A<X extends A<X>> {}
+
+A get foo => throw 0;
+''');
+ }
+
+ test_typeLiteral_class() async {
+ await assertErrorsInCode('''
+class C<T extends int> {}
+var t = C<String>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 36, 6,
+ contextMessages: [message('/home/test/lib/test.dart', 34, 9)]),
+ ]);
+ }
+
+ test_typeLiteral_functionTypeAlias() async {
+ await assertErrorsInCode('''
+typedef Cb<T extends int> = void Function();
+var t = Cb<String>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 6,
+ contextMessages: [message('/home/test/lib/test.dart', 53, 10)]),
+ ]);
+ }
+
+ test_typeLiteral_typeAlias() async {
+ await assertErrorsInCode('''
+class C {}
+typedef D<T extends int> = C;
+var t = D<String>;
+''', [
+ error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 51, 6,
+ contextMessages: [message('/home/test/lib/test.dart', 49, 9)]),
+ ]);
+ }
}
mixin TypeArgumentNotMatchingBoundsTestCases on PubPackageResolutionTest {
@@ -428,273 +756,10 @@
}
@reflectiveTest
-class TypeArgumentNotMatchingBoundsWithNullSafetyTest
+class TypeArgumentNotMatchingBoundsWithoutNullSafetyTest
extends PubPackageResolutionTest
- with TypeArgumentNotMatchingBoundsTestCases {
- test_enum_inferred() async {
- await assertErrorsInCode('''
-enum E<T extends int> {
- v('');
- const E(T t);
-}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 26, 1),
- ]);
- }
-
- test_enum_superBounded() async {
- await assertNoErrorsInCode('''
-enum E<T extends E<T>> {
- v<Never>()
-}
-''');
- }
-
- test_enum_withTypeArguments() async {
- await assertErrorsInCode('''
-enum E<T extends int> {
- v<String>()
-}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 28, 6),
- ]);
- }
-
- test_extends_optIn_fromOptOut_Null() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class A<X extends int> {}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart=2.6
-import 'a.dart';
-
-class A1<T extends Null> extends A<T> {}
-''');
- }
-
- test_extends_optIn_fromOptOut_otherTypeParameter() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-void foo<T extends U, U>() {
-}
-''');
-
- await assertNoErrorsInCode(r'''
-// @dart=2.6
-import 'a.dart';
-
-class A {}
-class B extends A {}
-
-main() {
- foo<B, A>();
-}
-''');
- }
-
- test_functionReference() async {
- await assertErrorsInCode('''
-void foo<T extends num>(T a) {}
-void bar() {
- foo<String>;
-}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 51, 6),
- ]);
- }
-
- test_functionReference_matching() async {
- await assertNoErrorsInCode('''
-void foo<T extends num>(T a) {}
-void bar() {
- foo<int>;
-}
-''');
- }
-
- test_functionReference_regularBounded() async {
- await assertNoErrorsInCode('''
-void foo<T>(T a) {}
-void bar() {
- foo<String>;
-}
-''');
- }
-
- test_genericFunctionTypeArgument_invariant() async {
- await assertErrorsInCode(r'''
-typedef F = T Function<T>(T);
-typedef FB<T extends F> = S Function<S extends T>(S);
-class CB<T extends F> {}
-void f(CB<FB<F>> a) {}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 119, 5,
- contextMessages: [message('/home/test/lib/test.dart', 116, 9)]),
- ]);
- }
-
- test_genericFunctionTypeArgument_regularBounded() async {
- await assertNoErrorsInCode(r'''
-typedef F1 = T Function<T>(T);
-typedef F2 = S Function<S>(S);
-class CB<T extends F1> {}
-void f(CB<F2> a) {}
-''');
- }
-
- test_metadata_matching() async {
- await assertNoErrorsInCode(r'''
-class A<T extends num> {
- const A();
-}
-
-@A<int>()
-void f() {}
-''');
- }
-
- test_metadata_notMatching() async {
- await assertErrorsInCode(r'''
-class A<T extends num> {
- const A();
-}
-
-@A<String>()
-void f() {}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 44, 6),
- ]);
- }
-
- test_metadata_notMatching_viaTypeAlias() async {
- await assertErrorsInCode(r'''
-class A<T> {
- const A();
-}
-
-typedef B<T extends num> = A<T>;
-
-@B<String>()
-void f() {}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 66, 6),
- ]);
- }
-
- test_methodInvocation_genericFunctionTypeArgument_match() async {
- await assertNoErrorsInCode(r'''
-typedef F = void Function<T extends num>();
-void f<T extends void Function<X extends num>()>() {}
-void g() {
- f<F>();
-}
-''');
- }
-
- test_methodInvocation_genericFunctionTypeArgument_mismatch() async {
- await assertErrorsInCode(r'''
-class A {}
-class B {}
-typedef F = void Function<T extends A>();
-void f<T extends void Function<U extends B>()>() {}
-void g() {
- f<F>();
-}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 131, 1),
- ]);
- }
-
- test_nonFunctionTypeAlias_body_typeArgument_mismatch() async {
- await assertErrorsInCode(r'''
-class A {}
-class B {}
-class G<T extends A> {}
-typedef X = G<B>;
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1),
- ]);
- }
-
- test_nonFunctionTypeAlias_body_typeArgument_regularBounded() async {
- await assertNoErrorsInCode(r'''
-class A {}
-class B extends A {}
-class G<T extends A> {}
-typedef X = G<B>;
-''');
- }
-
- test_nonFunctionTypeAlias_body_typeArgument_superBounded() async {
- await assertNoErrorsInCode(r'''
-class A<T extends A<T>> {}
-typedef X = List<A>;
-''');
- }
-
- test_nonFunctionTypeAlias_interfaceType_body_mismatch() async {
- await assertErrorsInCode(r'''
-class A {}
-class B {}
-class G<T extends A> {}
-typedef X = G<B>;
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1),
- ]);
- }
-
- test_nonFunctionTypeAlias_interfaceType_body_regularBounded() async {
- await assertNoErrorsInCode(r'''
-class A<T> {}
-typedef X<T> = A;
-''');
- }
-
- test_nonFunctionTypeAlias_interfaceType_body_superBounded() async {
- await assertErrorsInCode(r'''
-class A<T extends A<T>> {}
-typedef X<T> = A;
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 42, 1,
- contextMessages: [message('/home/test/lib/test.dart', 42, 1)]),
- ]);
- }
-
- test_nonFunctionTypeAlias_interfaceType_parameter() async {
- await assertErrorsInCode(r'''
-class A {}
-typedef X<T extends A> = Map<int, T>;
-void f(X<String> a) {}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 58, 6,
- contextMessages: [message('/home/test/lib/test.dart', 56, 9)]),
- ]);
- }
-
- test_nonFunctionTypeAlias_interfaceType_parameter_regularBounded() async {
- await assertNoErrorsInCode(r'''
-class A {}
-class B extends A {}
-typedef X<T extends A> = Map<int, T>;
-void f(X<B> a) {}
-''');
- }
-
- test_notRegularBounded_notSuperBounded_parameter_invariant() async {
- await assertErrorsInCode(r'''
-typedef A<X> = X Function(X);
-typedef G<X extends A<X>> = void Function<Y extends X>();
-foo(G g) {}
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 92, 1,
- contextMessages: [
- message('/home/test/lib/test.dart', 92, 1),
- message('/home/test/lib/test.dart', 92, 1)
- ]),
- ]);
- }
-
- test_regression_42196() async {
+ with WithoutNullSafetyMixin, TypeArgumentNotMatchingBoundsTestCases {
+ test_regression_42196_Null() async {
await assertNoErrorsInCode(r'''
typedef G<X> = Function(X);
class A<X extends G<A<X,Y>>, Y extends X> {}
@@ -702,73 +767,8 @@
test<X>() { print("OK"); }
main() {
- test<A<G<A<Never, Never>>, dynamic>>();
+ test<A<G<A<Null, Null>>, dynamic>>();
}
''');
}
-
- test_regression_42196_object() async {
- await assertNoErrorsInCode(r'''
-typedef G<X> = Function(X);
-class A<X extends G<A<X, Y>>, Y extends Never> {}
-
-test<X>() { print("OK"); }
-
-main() {
- test<A<G<A<Never, Never>>, Object?>>();
-}
-''');
- }
-
- test_regression_42196_void() async {
- await assertNoErrorsInCode(r'''
-typedef G<X> = Function(X);
-class A<X extends G<A<X, Y>>, Y extends Never> {}
-
-test<X>() { print("OK"); }
-
-main() {
- test<A<G<A<Never, Never>>, void>>();
-}
-''');
- }
-
- test_superBounded() async {
- await assertNoErrorsInCode(r'''
-class A<X extends A<X>> {}
-
-A get foo => throw 0;
-''');
- }
-
- test_typeLiteral_class() async {
- await assertErrorsInCode('''
-class C<T extends int> {}
-var t = C<String>;
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 36, 6,
- contextMessages: [message('/home/test/lib/test.dart', 34, 9)]),
- ]);
- }
-
- test_typeLiteral_functionTypeAlias() async {
- await assertErrorsInCode('''
-typedef Cb<T extends int> = void Function();
-var t = Cb<String>;
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 6,
- contextMessages: [message('/home/test/lib/test.dart', 53, 10)]),
- ]);
- }
-
- test_typeLiteral_typeAlias() async {
- await assertErrorsInCode('''
-class C {}
-typedef D<T extends int> = C;
-var t = D<String>;
-''', [
- error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 51, 6,
- contextMessages: [message('/home/test/lib/test.dart', 49, 9)]),
- ]);
- }
}
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
index ae2410c..2f1bacb 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
@@ -11,13 +11,181 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UndefinedGetterTest);
- defineReflectiveTests(UndefinedGetterWithNullSafetyTest);
+ defineReflectiveTests(UndefinedGetterWithoutNullSafetyTest);
});
}
@reflectiveTest
class UndefinedGetterTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, UndefinedGetterTestCases {}
+ with UndefinedGetterTestCases {
+ test_functionAlias_typeInstantiated_getter() async {
+ await assertErrorsInCode('''
+typedef Fn<T> = void Function(T);
+
+void bar() {
+ Fn<int>.foo;
+}
+
+extension E on Type {
+ int get foo => 1;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER_ON_FUNCTION_TYPE, 58, 3),
+ ]);
+ }
+
+ test_functionAlias_typeInstantiated_getter_parenthesized() async {
+ await assertNoErrorsInCode('''
+typedef Fn<T> = void Function(T);
+
+void bar() {
+ (Fn<int>).foo;
+}
+
+extension E on Type {
+ int get foo => 1;
+}
+''');
+ }
+
+ test_get_from_abstract_field_final_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract final int x;
+}
+int f(A a) => a.x;
+''');
+ }
+
+ test_get_from_abstract_field_valid() async {
+ await assertNoErrorsInCode('''
+abstract class A {
+ abstract int x;
+}
+int f(A a) => a.x;
+''');
+ }
+
+ test_get_from_external_field_final_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external final int x;
+}
+int f(A a) => a.x;
+''');
+ }
+
+ test_get_from_external_field_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external int x;
+}
+int f(A a) => a.x;
+''');
+ }
+
+ test_get_from_external_static_field_final_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external static final int x;
+}
+int f() => A.x;
+''');
+ }
+
+ test_get_from_external_static_field_valid() async {
+ await assertNoErrorsInCode('''
+class A {
+ external static int x;
+}
+int f() => A.x;
+''');
+ }
+
+ test_new_cascade() async {
+ await assertErrorsInCode('''
+class C {}
+
+f(C? c) {
+ c..new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 27, 3),
+ ]);
+ }
+
+ test_new_dynamic() async {
+ await assertErrorsInCode('''
+f(dynamic d) {
+ d.new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 19, 3),
+ ]);
+ }
+
+ test_new_expression() async {
+ await assertErrorsInCode('''
+class C {}
+
+f(C? c1, C c2) {
+ (c1 ?? c2).new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 42, 3),
+ ]);
+ }
+
+ test_new_nullAware() async {
+ await assertErrorsInCode('''
+class C {}
+
+f(C? c) {
+ c?.new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 27, 3),
+ ]);
+ }
+
+ test_new_prefixedIdentifier() async {
+ await assertErrorsInCode('''
+class C {}
+
+abstract class D {
+ C get c;
+}
+
+f(D d) {
+ d.c.new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 60, 3),
+ ]);
+ }
+
+ test_new_simpleIdentifier() async {
+ await assertErrorsInCode('''
+class C {}
+
+f(C c) {
+ c.new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 25, 3),
+ ]);
+ }
+
+ test_new_typeVariable() async {
+ await assertErrorsInCode('''
+f<T>(T t) {
+ t.new;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_GETTER, 16, 3),
+ ]);
+ }
+}
mixin UndefinedGetterTestCases on PubPackageResolutionTest {
test_compoundAssignment_hasSetter_instance() async {
@@ -386,173 +554,5 @@
}
@reflectiveTest
-class UndefinedGetterWithNullSafetyTest extends PubPackageResolutionTest
- with UndefinedGetterTestCases {
- test_functionAlias_typeInstantiated_getter() async {
- await assertErrorsInCode('''
-typedef Fn<T> = void Function(T);
-
-void bar() {
- Fn<int>.foo;
-}
-
-extension E on Type {
- int get foo => 1;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER_ON_FUNCTION_TYPE, 58, 3),
- ]);
- }
-
- test_functionAlias_typeInstantiated_getter_parenthesized() async {
- await assertNoErrorsInCode('''
-typedef Fn<T> = void Function(T);
-
-void bar() {
- (Fn<int>).foo;
-}
-
-extension E on Type {
- int get foo => 1;
-}
-''');
- }
-
- test_get_from_abstract_field_final_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract final int x;
-}
-int f(A a) => a.x;
-''');
- }
-
- test_get_from_abstract_field_valid() async {
- await assertNoErrorsInCode('''
-abstract class A {
- abstract int x;
-}
-int f(A a) => a.x;
-''');
- }
-
- test_get_from_external_field_final_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external final int x;
-}
-int f(A a) => a.x;
-''');
- }
-
- test_get_from_external_field_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external int x;
-}
-int f(A a) => a.x;
-''');
- }
-
- test_get_from_external_static_field_final_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external static final int x;
-}
-int f() => A.x;
-''');
- }
-
- test_get_from_external_static_field_valid() async {
- await assertNoErrorsInCode('''
-class A {
- external static int x;
-}
-int f() => A.x;
-''');
- }
-
- test_new_cascade() async {
- await assertErrorsInCode('''
-class C {}
-
-f(C? c) {
- c..new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 27, 3),
- ]);
- }
-
- test_new_dynamic() async {
- await assertErrorsInCode('''
-f(dynamic d) {
- d.new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 19, 3),
- ]);
- }
-
- test_new_expression() async {
- await assertErrorsInCode('''
-class C {}
-
-f(C? c1, C c2) {
- (c1 ?? c2).new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 42, 3),
- ]);
- }
-
- test_new_nullAware() async {
- await assertErrorsInCode('''
-class C {}
-
-f(C? c) {
- c?.new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 27, 3),
- ]);
- }
-
- test_new_prefixedIdentifier() async {
- await assertErrorsInCode('''
-class C {}
-
-abstract class D {
- C get c;
-}
-
-f(D d) {
- d.c.new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 60, 3),
- ]);
- }
-
- test_new_simpleIdentifier() async {
- await assertErrorsInCode('''
-class C {}
-
-f(C c) {
- c.new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 25, 3),
- ]);
- }
-
- test_new_typeVariable() async {
- await assertErrorsInCode('''
-f<T>(T t) {
- t.new;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_GETTER, 16, 3),
- ]);
- }
-}
+class UndefinedGetterWithoutNullSafetyTest extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, UndefinedGetterTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart
index a577c7f..df6bcf4 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart
@@ -10,140 +10,12 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UndefinedSetterTest);
- defineReflectiveTests(UndefinedSetterWithNullSafetyTest);
+ defineReflectiveTests(UndefinedSetterWithoutNullSafetyTest);
});
}
@reflectiveTest
class UndefinedSetterTest extends PubPackageResolutionTest
- with WithoutNullSafetyMixin, UndefinedSetterTestCases {}
-
-mixin UndefinedSetterTestCases on PubPackageResolutionTest {
- test_importWithPrefix_defined() async {
- newFile('$testPackageLibPath/lib.dart', content: r'''
-library lib;
-set y(int value) {}''');
- await assertNoErrorsInCode(r'''
-import 'lib.dart' as x;
-main() {
- x.y = 0;
-}
-''');
- }
-
- test_instance_undefined() async {
- await assertErrorsInCode(r'''
-class T {}
-f(T e1) { e1.m = 0; }
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 24, 1,
- messageContains: ["the type 'T'"]),
- ]);
- }
-
- test_instance_undefined_mixin() async {
- await assertErrorsInCode(r'''
-mixin M {
- f() { this.m = 0; }
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 23, 1),
- ]);
- }
-
- test_inSubtype() async {
- await assertErrorsInCode(r'''
-class A {}
-class B extends A {
- set b(x) {}
-}
-f(var a) {
- if (a is A) {
- a.b = 0;
- }
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 80, 1),
- ]);
- }
-
- test_inType() async {
- await assertErrorsInCode(r'''
-class A {}
-f(var a) {
- if(a is A) {
- a.m = 0;
- }
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 43, 1),
- ]);
- }
-
- test_static_conditionalAccess_defined() async {
- // The conditional access operator '?.' can be used to access static
- // fields.
- await assertNoErrorsInCode('''
-class A {
- static var x;
-}
-f() { A?.x = 1; }
-''');
- }
-
- test_static_definedInSuperclass() async {
- await assertErrorsInCode('''
-class S {
- static set s(int i) {}
-}
-class C extends S {}
-f(var p) {
- f(C.s = 1);
-}''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 75, 1,
- messageContains: ["type 'C'"]),
- ]);
- }
-
- test_static_undefined() async {
- await assertErrorsInCode(r'''
-class A {}
-f() { A.B = 0;}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 19, 1),
- ]);
- }
-
- test_typeLiteral_cascadeTarget() async {
- await assertErrorsInCode(r'''
-class T {
- static void set foo(_) {}
-}
-main() {
- T..foo = 42;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 54, 3),
- ]);
- }
-
- test_withExtension() async {
- await assertErrorsInCode(r'''
-class C {}
-
-extension E on C {}
-
-f(C c) {
- c.a = 1;
-}
-''', [
- error(CompileTimeErrorCode.UNDEFINED_SETTER, 46, 1),
- ]);
- }
-}
-
-@reflectiveTest
-class UndefinedSetterWithNullSafetyTest extends PubPackageResolutionTest
with UndefinedSetterTestCases {
test_functionAlias_typeInstantiated() async {
await assertErrorsInCode('''
@@ -276,3 +148,131 @@
''');
}
}
+
+mixin UndefinedSetterTestCases on PubPackageResolutionTest {
+ test_importWithPrefix_defined() async {
+ newFile('$testPackageLibPath/lib.dart', content: r'''
+library lib;
+set y(int value) {}''');
+ await assertNoErrorsInCode(r'''
+import 'lib.dart' as x;
+main() {
+ x.y = 0;
+}
+''');
+ }
+
+ test_instance_undefined() async {
+ await assertErrorsInCode(r'''
+class T {}
+f(T e1) { e1.m = 0; }
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 24, 1,
+ messageContains: ["the type 'T'"]),
+ ]);
+ }
+
+ test_instance_undefined_mixin() async {
+ await assertErrorsInCode(r'''
+mixin M {
+ f() { this.m = 0; }
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 23, 1),
+ ]);
+ }
+
+ test_inSubtype() async {
+ await assertErrorsInCode(r'''
+class A {}
+class B extends A {
+ set b(x) {}
+}
+f(var a) {
+ if (a is A) {
+ a.b = 0;
+ }
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 80, 1),
+ ]);
+ }
+
+ test_inType() async {
+ await assertErrorsInCode(r'''
+class A {}
+f(var a) {
+ if(a is A) {
+ a.m = 0;
+ }
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 43, 1),
+ ]);
+ }
+
+ test_static_conditionalAccess_defined() async {
+ // The conditional access operator '?.' can be used to access static
+ // fields.
+ await assertNoErrorsInCode('''
+class A {
+ static var x;
+}
+f() { A?.x = 1; }
+''');
+ }
+
+ test_static_definedInSuperclass() async {
+ await assertErrorsInCode('''
+class S {
+ static set s(int i) {}
+}
+class C extends S {}
+f(var p) {
+ f(C.s = 1);
+}''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 75, 1,
+ messageContains: ["type 'C'"]),
+ ]);
+ }
+
+ test_static_undefined() async {
+ await assertErrorsInCode(r'''
+class A {}
+f() { A.B = 0;}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 19, 1),
+ ]);
+ }
+
+ test_typeLiteral_cascadeTarget() async {
+ await assertErrorsInCode(r'''
+class T {
+ static void set foo(_) {}
+}
+main() {
+ T..foo = 42;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 54, 3),
+ ]);
+ }
+
+ test_withExtension() async {
+ await assertErrorsInCode(r'''
+class C {}
+
+extension E on C {}
+
+f(C c) {
+ c.a = 1;
+}
+''', [
+ error(CompileTimeErrorCode.UNDEFINED_SETTER, 46, 1),
+ ]);
+ }
+}
+
+@reflectiveTest
+class UndefinedSetterWithoutNullSafetyTest extends PubPackageResolutionTest
+ with WithoutNullSafetyMixin, UndefinedSetterTestCases {}
diff --git a/pkg/analyzer/test/src/diagnostics/unused_element_test.dart b/pkg/analyzer/test/src/diagnostics/unused_element_test.dart
index fb070cc..b1d7f0a 100644
--- a/pkg/analyzer/test/src/diagnostics/unused_element_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/unused_element_test.dart
@@ -11,12 +11,301 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UnusedElementTest);
- defineReflectiveTests(UnusedElementWithNullSafetyTest);
+ defineReflectiveTests(UnusedElementWithoutNullSafetyTest);
});
}
@reflectiveTest
-class UnusedElementTest extends PubPackageResolutionTest
+class UnusedElementTest extends PubPackageResolutionTest {
+ test_class_isUsed_isExpression_expression() async {
+ await assertNoErrorsInCode('''
+class _A {}
+void f(Object p) {
+ if (_A() is int) {
+ }
+}
+''');
+ }
+
+ test_class_notUsed_isExpression_typeArgument() async {
+ await assertErrorsInCode(r'''
+class _A {}
+void f(Object p) {
+ if (p is List<_A>) {
+ }
+}
+''', [
+ error(HintCode.UNUSED_ELEMENT, 6, 2),
+ ]);
+ }
+
+ test_class_notUsed_isExpression_typeInFunctionType() async {
+ await assertErrorsInCode(r'''
+class _A {}
+void f(Object p) {
+ if (p is void Function(_A)) {
+ }
+}
+''', [
+ error(HintCode.UNUSED_ELEMENT, 6, 2),
+ ]);
+ }
+
+ test_class_notUsed_isExpression_typeInTypeParameter() async {
+ await assertErrorsInCode(r'''
+class _A {}
+void f(Object p) {
+ if (p is void Function<T extends _A>()) {
+ }
+}
+''', [
+ error(HintCode.UNUSED_ELEMENT, 6, 2),
+ ]);
+ }
+
+ test_class_notUsed_variableDeclaration() async {
+ await assertErrorsInCode('''
+class _A {}
+void f() {
+ _A? v;
+ print(v);
+}
+print(x) {}
+''', [
+ error(HintCode.UNUSED_ELEMENT, 6, 2),
+ ]);
+ }
+
+ test_class_notUsed_variableDeclaration_typeArgument() async {
+ await assertErrorsInCode('''
+class _A {}
+main() {
+ List<_A>? v;
+ print(v);
+}
+print(x) {}
+''', [
+ error(HintCode.UNUSED_ELEMENT, 6, 2),
+ ]);
+ }
+
+ test_optionalParameter_isUsed_genericConstructor() async {
+ await assertNoErrorsInCode('''
+class C<T> {
+ C._([int? x]);
+}
+void foo() {
+ C._(7);
+}
+''');
+ }
+
+ test_optionalParameter_isUsed_genericFunction() async {
+ await assertNoErrorsInCode('''
+void _f<T>([int? x]) {}
+void foo() {
+ _f(7);
+}
+''');
+ }
+
+ test_optionalParameter_isUsed_genericMethod() async {
+ await assertNoErrorsInCode('''
+class C {
+ void _m<T>([int? x]) {}
+}
+void foo() {
+ C()._m(7);
+}
+''');
+ }
+
+ test_optionalParameter_isUsed_overrideRequiredNamed() async {
+ await assertNoErrorsInCode(r'''
+class A {
+ void _m({required int a}) {}
+}
+class B implements A {
+ void _m({int a = 0}) {}
+}
+f() => A()._m(a: 0);
+''');
+ }
+
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47839')
+ test_optionalParameter_notUsed_genericConstructor() async {
+ // TODO(srawlins): Change to assertErrorsInCode when this is fixed.
+ addTestFile('''
+class C<T> {
+ C._([int? x]);
+}
+void foo() {
+ C._();
+}
+''');
+ await resolveTestFile();
+ expect(result.errors, isNotEmpty);
+ }
+
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47839')
+ test_optionalParameter_notUsed_genericFunction() async {
+ // TODO(srawlins): Change to assertErrorsInCode when this is fixed.
+ addTestFile('''
+void _f<T>([int? x]) {}
+void foo() {
+ _f();
+}
+''');
+ await resolveTestFile();
+ expect(result.errors, isNotEmpty);
+ }
+
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47839')
+ test_optionalParameter_notUsed_genericMethod() async {
+ // TODO(srawlins): Change to assertErrorsInCode when this is fixed.
+ addTestFile('''
+class C {
+ void _m<T>([int? x]) {}
+}
+void foo() {
+ C()._m();
+}
+''');
+ await resolveTestFile();
+ expect(result.errors, isNotEmpty);
+ }
+
+ test_parameter_optionalNamed_fieldFormal_isUsed_constructorInvocation() async {
+ await assertNoErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A({this.f});
+}
+f() => _A(f: 0);
+''');
+ }
+
+ test_parameter_optionalNamed_fieldFormal_isUsed_factoryRedirect() async {
+ await assertNoErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A({this.f});
+ factory _A.named({int? f}) = _A;
+}
+f() => _A.named(f: 0);
+''');
+ }
+
+ test_parameter_optionalNamed_fieldFormal_notUsed() async {
+ await assertErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A({this.f});
+}
+f() => _A();
+''', [
+ error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
+ ]);
+ }
+
+ test_parameter_optionalNamed_fieldFormal_notUsed_factoryRedirect() async {
+ await assertErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A({this.f});
+ factory _A.named() = _A;
+}
+f() => _A.named();
+''', [
+ error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
+ ]);
+ }
+
+ test_parameter_optionalPositional_fieldFormal_isUsed_constructorInvocation() async {
+ await assertNoErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A([this.f]);
+}
+f() => _A(0);
+''');
+ }
+
+ test_parameter_optionalPositional_fieldFormal_isUsed_factoryRedirect() async {
+ await assertNoErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A([this.f]);
+ factory _A.named([int a]) = _A;
+}
+f() => _A.named(0);
+''');
+ }
+
+ test_parameter_optionalPositional_fieldFormal_notUsed() async {
+ await assertErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A([this.f]);
+}
+f() => _A();
+''', [
+ error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
+ ]);
+ }
+
+ test_parameter_optionalPositional_fieldFormal_notUsed_factoryRedirect() async {
+ await assertErrorsInCode(r'''
+class _A {
+ final int? f;
+ _A([this.f]);
+ factory _A.named() = _A;
+}
+f() => _A.named();
+''', [
+ error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
+ ]);
+ }
+
+ test_typeAlias_interfaceType_isUsed_typeName_isExpression() async {
+ await assertNoErrorsInCode(r'''
+typedef _A = List<int>;
+
+void f(a) {
+ a is _A;
+}
+''');
+ }
+
+ test_typeAlias_interfaceType_isUsed_typeName_parameter() async {
+ await assertNoErrorsInCode(r'''
+typedef _A = List<int>;
+
+void f(_A a) {}
+''');
+ }
+
+ test_typeAlias_interfaceType_isUsed_typeName_typeArgument() async {
+ await assertNoErrorsInCode(r'''
+typedef _A = List<int>;
+
+void f() {
+ Map<_A, int>();
+}
+''');
+ }
+
+ test_typeAlias_interfaceType_notUsed() async {
+ await assertErrorsInCode(r'''
+typedef _A = List<int>;
+''', [
+ error(HintCode.UNUSED_ELEMENT, 8, 2),
+ ]);
+ }
+}
+
+@reflectiveTest
+class UnusedElementWithoutNullSafetyTest extends PubPackageResolutionTest
with WithoutNullSafetyMixin {
test_class_isUsed_extends() async {
await assertNoErrorsInCode(r'''
@@ -1697,292 +1986,3 @@
]);
}
}
-
-@reflectiveTest
-class UnusedElementWithNullSafetyTest extends PubPackageResolutionTest {
- test_class_isUsed_isExpression_expression() async {
- await assertNoErrorsInCode('''
-class _A {}
-void f(Object p) {
- if (_A() is int) {
- }
-}
-''');
- }
-
- test_class_notUsed_isExpression_typeArgument() async {
- await assertErrorsInCode(r'''
-class _A {}
-void f(Object p) {
- if (p is List<_A>) {
- }
-}
-''', [
- error(HintCode.UNUSED_ELEMENT, 6, 2),
- ]);
- }
-
- test_class_notUsed_isExpression_typeInFunctionType() async {
- await assertErrorsInCode(r'''
-class _A {}
-void f(Object p) {
- if (p is void Function(_A)) {
- }
-}
-''', [
- error(HintCode.UNUSED_ELEMENT, 6, 2),
- ]);
- }
-
- test_class_notUsed_isExpression_typeInTypeParameter() async {
- await assertErrorsInCode(r'''
-class _A {}
-void f(Object p) {
- if (p is void Function<T extends _A>()) {
- }
-}
-''', [
- error(HintCode.UNUSED_ELEMENT, 6, 2),
- ]);
- }
-
- test_class_notUsed_variableDeclaration() async {
- await assertErrorsInCode('''
-class _A {}
-void f() {
- _A? v;
- print(v);
-}
-print(x) {}
-''', [
- error(HintCode.UNUSED_ELEMENT, 6, 2),
- ]);
- }
-
- test_class_notUsed_variableDeclaration_typeArgument() async {
- await assertErrorsInCode('''
-class _A {}
-main() {
- List<_A>? v;
- print(v);
-}
-print(x) {}
-''', [
- error(HintCode.UNUSED_ELEMENT, 6, 2),
- ]);
- }
-
- test_optionalParameter_isUsed_genericConstructor() async {
- await assertNoErrorsInCode('''
-class C<T> {
- C._([int? x]);
-}
-void foo() {
- C._(7);
-}
-''');
- }
-
- test_optionalParameter_isUsed_genericFunction() async {
- await assertNoErrorsInCode('''
-void _f<T>([int? x]) {}
-void foo() {
- _f(7);
-}
-''');
- }
-
- test_optionalParameter_isUsed_genericMethod() async {
- await assertNoErrorsInCode('''
-class C {
- void _m<T>([int? x]) {}
-}
-void foo() {
- C()._m(7);
-}
-''');
- }
-
- test_optionalParameter_isUsed_overrideRequiredNamed() async {
- await assertNoErrorsInCode(r'''
-class A {
- void _m({required int a}) {}
-}
-class B implements A {
- void _m({int a = 0}) {}
-}
-f() => A()._m(a: 0);
-''');
- }
-
- @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47839')
- test_optionalParameter_notUsed_genericConstructor() async {
- // TODO(srawlins): Change to assertErrorsInCode when this is fixed.
- addTestFile('''
-class C<T> {
- C._([int? x]);
-}
-void foo() {
- C._();
-}
-''');
- await resolveTestFile();
- expect(result.errors, isNotEmpty);
- }
-
- @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47839')
- test_optionalParameter_notUsed_genericFunction() async {
- // TODO(srawlins): Change to assertErrorsInCode when this is fixed.
- addTestFile('''
-void _f<T>([int? x]) {}
-void foo() {
- _f();
-}
-''');
- await resolveTestFile();
- expect(result.errors, isNotEmpty);
- }
-
- @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47839')
- test_optionalParameter_notUsed_genericMethod() async {
- // TODO(srawlins): Change to assertErrorsInCode when this is fixed.
- addTestFile('''
-class C {
- void _m<T>([int? x]) {}
-}
-void foo() {
- C()._m();
-}
-''');
- await resolveTestFile();
- expect(result.errors, isNotEmpty);
- }
-
- test_parameter_optionalNamed_fieldFormal_isUsed_constructorInvocation() async {
- await assertNoErrorsInCode(r'''
-class _A {
- final int? f;
- _A({this.f});
-}
-f() => _A(f: 0);
-''');
- }
-
- test_parameter_optionalNamed_fieldFormal_isUsed_factoryRedirect() async {
- await assertNoErrorsInCode(r'''
-class _A {
- final int? f;
- _A({this.f});
- factory _A.named({int? f}) = _A;
-}
-f() => _A.named(f: 0);
-''');
- }
-
- test_parameter_optionalNamed_fieldFormal_notUsed() async {
- await assertErrorsInCode(r'''
-class _A {
- final int? f;
- _A({this.f});
-}
-f() => _A();
-''', [
- error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
- ]);
- }
-
- test_parameter_optionalNamed_fieldFormal_notUsed_factoryRedirect() async {
- await assertErrorsInCode(r'''
-class _A {
- final int? f;
- _A({this.f});
- factory _A.named() = _A;
-}
-f() => _A.named();
-''', [
- error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
- ]);
- }
-
- test_parameter_optionalPositional_fieldFormal_isUsed_constructorInvocation() async {
- await assertNoErrorsInCode(r'''
-class _A {
- final int? f;
- _A([this.f]);
-}
-f() => _A(0);
-''');
- }
-
- test_parameter_optionalPositional_fieldFormal_isUsed_factoryRedirect() async {
- await assertNoErrorsInCode(r'''
-class _A {
- final int? f;
- _A([this.f]);
- factory _A.named([int a]) = _A;
-}
-f() => _A.named(0);
-''');
- }
-
- test_parameter_optionalPositional_fieldFormal_notUsed() async {
- await assertErrorsInCode(r'''
-class _A {
- final int? f;
- _A([this.f]);
-}
-f() => _A();
-''', [
- error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
- ]);
- }
-
- test_parameter_optionalPositional_fieldFormal_notUsed_factoryRedirect() async {
- await assertErrorsInCode(r'''
-class _A {
- final int? f;
- _A([this.f]);
- factory _A.named() = _A;
-}
-f() => _A.named();
-''', [
- error(HintCode.UNUSED_ELEMENT_PARAMETER, 38, 1),
- ]);
- }
-
- test_typeAlias_interfaceType_isUsed_typeName_isExpression() async {
- await assertNoErrorsInCode(r'''
-typedef _A = List<int>;
-
-void f(a) {
- a is _A;
-}
-''');
- }
-
- test_typeAlias_interfaceType_isUsed_typeName_parameter() async {
- await assertNoErrorsInCode(r'''
-typedef _A = List<int>;
-
-void f(_A a) {}
-''');
- }
-
- test_typeAlias_interfaceType_isUsed_typeName_typeArgument() async {
- await assertNoErrorsInCode(r'''
-typedef _A = List<int>;
-
-void f() {
- Map<_A, int>();
-}
-''');
- }
-
- test_typeAlias_interfaceType_notUsed() async {
- await assertErrorsInCode(r'''
-typedef _A = List<int>;
-''', [
- error(HintCode.UNUSED_ELEMENT, 8, 2),
- ]);
- }
-}
diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart
index 09f2671..4fda1a5 100644
--- a/pkg/analyzer/test/src/summary/element_text.dart
+++ b/pkg/analyzer/test/src/summary/element_text.dart
@@ -508,6 +508,8 @@
}
void _writeFunctionElement(FunctionElement e) {
+ expect(e.isStatic, isTrue);
+
_writeIndentedLine(() {
_writeIf(e.isExternal, 'external ');
_writeName(e);
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 7ca0145..7b09082 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -22411,7 +22411,7 @@
synthetic static foo @-1
type: Future<int>
accessors
- get foo @16 async
+ static get foo @16 async
returnType: Future<int>
''');
}
@@ -22430,7 +22430,7 @@
synthetic static foo @-1
type: Stream<int>
accessors
- get foo @37 async*
+ static get foo @37 async*
returnType: Stream<int>
''');
}
@@ -22449,7 +22449,7 @@
synthetic static x @-1
type: dynamic
accessors
- get x @64
+ static get x @64
documentationComment: /**\n * Docs\n */
returnType: dynamic
''');
@@ -22464,7 +22464,7 @@
synthetic static x @-1
type: int
accessors
- external get x @17
+ static external get x @17
returnType: int
''');
}
@@ -22510,7 +22510,7 @@
synthetic static foo @-1
type: Iterator<int>
accessors
- get foo @18 sync*
+ static get foo @18 sync*
returnType: Iterator<int>
''');
}
@@ -22526,9 +22526,9 @@
synthetic static y @-1
type: dynamic
accessors
- get x @8
+ static get x @8
returnType: int
- get y @23
+ static get y @23
returnType: dynamic
''');
}
@@ -22659,9 +22659,9 @@
synthetic static x @-1
type: int
accessors
- get x @8
+ static get x @8
returnType: int
- set x @25
+ static set x @25
parameters
requiredPositional value @31
type: int
@@ -22679,12 +22679,12 @@
synthetic static x @-1
type: int
accessors
- set x @9
+ static set x @9
parameters
requiredPositional value @15
type: int
returnType: void
- get x @33
+ static get x @33
returnType: int
''');
}
@@ -25701,7 +25701,7 @@
synthetic static g @-1
type: dynamic
accessors
- get g @4
+ static get g @4
returnType: dynamic
''');
}
@@ -25845,7 +25845,7 @@
synthetic static main @-1
type: dynamic
accessors
- get main @4
+ static get main @4
returnType: dynamic
''');
}
@@ -27709,7 +27709,7 @@
accessors
synthetic static get a @-1
returnType: dynamic
- get f @23
+ static get f @23
metadata
Annotation
atSign: @ @16
@@ -27739,7 +27739,7 @@
accessors
synthetic static get a @-1
returnType: dynamic
- set f @23
+ static set f @23
metadata
Annotation
atSign: @ @16
@@ -29441,7 +29441,7 @@
accessors
synthetic static get foo @-1
returnType: int
- get getter @29
+ static get getter @29
metadata
Annotation
atSign: @ @16
@@ -29476,7 +29476,7 @@
accessors
synthetic static get foo @-1
returnType: int
- set setter @25
+ static set setter @25
metadata
Annotation
atSign: @ @16
@@ -29737,7 +29737,7 @@
accessors
synthetic static get a @-1
returnType: dynamic
- set foo @21
+ static set foo @21
parameters
requiredPositional x @32
type: int
@@ -31285,7 +31285,7 @@
synthetic static foo @-1
type: int
accessors
- get foo @8
+ static get foo @8
returnType: int
''');
}
@@ -31890,7 +31890,7 @@
type: int
nonSynthetic: self::@getter::foo
accessors
- get foo @8
+ static get foo @8
returnType: int
nonSynthetic: self::@getter::foo
''',
@@ -31912,10 +31912,10 @@
type: int
nonSynthetic: self::@getter::foo
accessors
- get foo @8
+ static get foo @8
returnType: int
nonSynthetic: self::@getter::foo
- set foo @22
+ static set foo @22
parameters
requiredPositional value @30
type: int
@@ -31940,7 +31940,7 @@
type: int
nonSynthetic: self::@setter::foo
accessors
- set foo @4
+ static set foo @4
parameters
requiredPositional value @12
type: int
@@ -32508,7 +32508,7 @@
synthetic static x @-1
type: dynamic
accessors
- set x @69
+ static set x @69
documentationComment: /**\n * Docs\n */
parameters
requiredPositional value @71
@@ -32526,7 +32526,7 @@
synthetic static x @-1
type: int
accessors
- external set x @18
+ static external set x @18
parameters
requiredPositional value @24
type: int
@@ -32543,7 +32543,7 @@
synthetic static f @-1
type: int
accessors
- set f @4
+ static set f @4
parameters
requiredPositional value @10
type: int
@@ -32563,12 +32563,12 @@
synthetic static y @-1
type: dynamic
accessors
- set x @9
+ static set x @9
parameters
requiredPositional value @15
type: int
returnType: void
- set y @29
+ static set y @29
parameters
requiredPositional value @31
type: dynamic
@@ -36957,9 +36957,9 @@
synthetic static x @-1
type: int
accessors
- get x @8
+ static get x @8
returnType: int
- set x @25
+ static set x @25
parameters
requiredPositional value @31
type: int
@@ -36979,12 +36979,12 @@
synthetic static x @-1
type: int
accessors
- set x @9
+ static set x @9
parameters
requiredPositional value @15
type: int
returnType: void
- get x @33
+ static get x @33
returnType: int
''');
}
@@ -37003,7 +37003,7 @@
accessors
synthetic static get foo @-1
returnType: int
- set foo @23
+ static set foo @23
parameters
requiredPositional newValue @31
type: int
@@ -37660,7 +37660,7 @@
synthetic static x @-1
type: int
accessors
- get x @39
+ static get x @39
returnType: int
parts
a.dart
@@ -37668,7 +37668,7 @@
synthetic static x @-1
type: int
accessors
- set x @25
+ static set x @25
parameters
requiredPositional _ @31
type: int
@@ -37695,7 +37695,7 @@
synthetic static x @-1
type: int
accessors
- set x @40
+ static set x @40
parameters
requiredPositional _ @46
type: int
@@ -37706,7 +37706,7 @@
synthetic static x @-1
type: int
accessors
- get x @24
+ static get x @24
returnType: int
''');
}
@@ -37727,14 +37727,14 @@
synthetic static x @-1
type: int
accessors
- get x @24
+ static get x @24
returnType: int
b.dart
topLevelVariables
synthetic static x @-1
type: int
accessors
- set x @25
+ static set x @25
parameters
requiredPositional _ @31
type: int
@@ -38058,7 +38058,7 @@
synthetic static x @-1
type: int
accessors
- set x @25
+ static set x @25
parameters
requiredPositional _ @31
type: int
@@ -38068,7 +38068,7 @@
synthetic static x @-1
type: int
accessors
- get x @24
+ static get x @24
returnType: int
''');
}
diff --git a/pkg/analyzer/test/src/summary/top_level_inference_test.dart b/pkg/analyzer/test/src/summary/top_level_inference_test.dart
index f2133b0..3974511 100644
--- a/pkg/analyzer/test/src/summary/top_level_inference_test.dart
+++ b/pkg/analyzer/test/src/summary/top_level_inference_test.dart
@@ -1999,7 +1999,7 @@
requiredPositional _r_instanceClassMethod @-1
type: String Function(int)
returnType: void
- get topLevelGetter @74
+ static get topLevelGetter @74
returnType: int
functions
topLevelFunction @7
diff --git a/tools/VERSION b/tools/VERSION
index 867df85..37044ab 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 17
PATCH 0
-PRERELEASE 94
+PRERELEASE 95
PRERELEASE_PATCH 0
\ No newline at end of file