[analyzer] Remove all support for strong-mode

This looks pretty beefy; it is more-or-less 3 parts:

* Removing the `implicit-casts: false`, `implicit-dynamic: false`
  modes:
  * Remove `AnalysisOptionsFileConfig.implicitCasts|implicitDynamic`
  * Remove `AnalysisOptionsImpl.implicitCasts|implicitDynamic`
  * Remove `TypeSystemImpl.implicitCasts`
  * Remove all behavioral tests of the modes
  * Remove Analysis Options-parsing code that handled `strong-mode`
* Remove ability to fix deprecated modes (introduced before Dart 3).
* Move some non-generated AnalysisOptionsHintCodes and
  AnalysisOptionsWarningCodes to be generated. As
  `AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED` was the
  last `AnalysisOptionsHintCode` code, there were problems with the
  code-generator, unless I moved these non-generated codes.
  * `DEPRECATED_LINT_HINT`, `DEPRECATED_LINT_HINT_WITH_REPLACEMENT`,
    `DUPLICATE_RULE_HINT`, `INCOMPATIBLE_LINT`, `UNDEFINED_LINT`.
  * Those codes are then added to error_fix_status.yaml.

Change-Id: Ic165b60ca85f08f92886433eac5f5da5b7dd5021
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316483
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Sam Rawlins 2023-08-17 17:07:37 +00:00 committed by Commit Queue
parent 0a717608ca
commit 7ee87f8601
53 changed files with 158 additions and 2235 deletions

View file

@ -34,11 +34,6 @@ class AnalysisOptionsGenerator extends YamlCompletionGenerator {
}),
AnalyzerOptions.plugins: EmptyProducer(),
AnalyzerOptions.propagateLinterExceptions: EmptyProducer(),
AnalyzerOptions.strongMode: MapProducer({
AnalyzerOptions.declarationCasts: EmptyProducer(),
AnalyzerOptions.implicitCasts: EmptyProducer(),
AnalyzerOptions.implicitDynamic: EmptyProducer(),
}),
}),
AnalyzerOptions.codeStyle: MapProducer({
AnalyzerOptions.format: BooleanProducer(),

View file

@ -44,9 +44,9 @@
# issue created for it.
#
# Stats:
# - 19 "needsEvaluation"
# - 372 "needsFix"
# - 359 "hasFix"
# - 18 "needsEvaluation"
# - 362 "needsFix"
# - 366 "hasFix"
# - 490 "noFix"
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR:
@ -58,9 +58,18 @@ AnalysisOptionsErrorCode.PARSE_ERROR:
notes: |-
Because of the way the YAML parser works, there isn't enough information to
be able to provide a fix.
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED:
AnalysisOptionsHintCode.DEPRECATED_LINT:
status: needsFix
notes: Fixed.
notes: |-
We should be able to remove the lint rule.
AnalysisOptionsHintCode.DEPRECATED_LINT_WITH_REPLACEMENT:
status: needsFix
notes: |-
We should be able to replace the deprecated lint rule with its replacement.
AnalysisOptionsHintCode.DUPLICATE_RULE:
status: needsFix
notes: |-
We could offer to remove the duplicate rule.
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED:
status: needsFix
notes: |-
@ -82,6 +91,11 @@ AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING:
status: noFix
notes: |-
The fix needs to be made in the included file.
AnalysisOptionsWarningCode.INCOMPATIBLE_LINT:
status: noFix
notes: |-
Without knowing which rule the user would prefer to use, we cannot remove
the reported one.
AnalysisOptionsWarningCode.INVALID_OPTION:
status: needsFix
notes: |-
@ -106,16 +120,13 @@ AnalysisOptionsWarningCode.RECURSIVE_INCLUDE_FILE:
AnalysisOptionsWarningCode.REMOVED_LINT:
status: needsFix
notes: |-
The fix is to remove the name of the removed lint.
The fix is to remove the name of the removed lint rule.
AnalysisOptionsWarningCode.REPLACED_LINT:
status: needsFix
notes: |-
The fix is to replace the replaced lint name with the name of the replacing
lint.
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED:
AnalysisOptionsWarningCode.UNDEFINED_LINT:
status: needsFix
notes: |-
Provide a fix to remove the deprecated setting.
The fix is to remove the name of the lint rule.
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE:
status: needsFix
notes: |-
@ -1823,56 +1834,6 @@ HintCode.UNUSED_ELEMENT:
status: hasFix
HintCode.UNUSED_ELEMENT_PARAMETER:
status: hasFix
LanguageCode.IMPLICIT_DYNAMIC_FIELD:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_INVOKE:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_METHOD:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_PARAMETER:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_RETURN:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_TYPE:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_VARIABLE:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LintCode.always_declare_return_types:
status: hasFix
LintCode.always_put_control_body_on_new_line:

View file

@ -14,7 +14,6 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/analysis_options/error/option_codes.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/lint/options_rule_validator.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_yaml.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
@ -65,9 +64,7 @@ class AnalysisOptionsFixGenerator {
// if (errorCode == AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR) {
// } else if (errorCode == AnalysisOptionsErrorCode.PARSE_ERROR) {
// } else
if (errorCode == AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED) {
await _addFix_removeSetting(coveringNodePath);
} else if (errorCode ==
if (errorCode ==
AnalysisOptionsWarningCode
.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT) {
var analyzerMap = options['analyzer'];
@ -86,13 +83,12 @@ class AnalysisOptionsFixGenerator {
await _addFix_replaceWithStrictRawTypes(
coveringNodePath, analyzerMap, strongModeMap);
}
} else if (errorCode == DEPRECATED_LINT_HINT) {
} else if (errorCode == AnalysisOptionsHintCode.DEPRECATED_LINT) {
await _addFix_removeLint(coveringNodePath);
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING) {
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND) {
// } else if (errorCode == AnalysisOptionsWarningCode.INVALID_OPTION) {
// } else if (errorCode == AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT) {
// } else if (errorCode == AnalysisOptionsWarningCode.SPEC_MODE_REMOVED) {
// } else if (errorCode ==
// AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE) {
} else if (errorCode ==

View file

@ -681,8 +681,6 @@ class ContextsPage extends DiagnosticPageWithNav {
String describe(AnalysisOptionsImpl options) {
var b = StringBuffer();
b.write(writeOption('Implicit dynamic', options.implicitDynamic));
b.write(writeOption('Implicit casts', options.implicitCasts));
b.write(writeOption('Feature set', options.contextFeatures.toString()));
b.write('<br>');

View file

@ -124,12 +124,11 @@ class AbstractContextTest with ResourceProviderMixin {
void createAnalysisOptionsFile({
List<String>? experiments,
List<String>? cannotIgnore,
bool? implicitCasts,
List<String>? lints,
}) {
var buffer = StringBuffer();
if (experiments != null || implicitCasts != null || cannotIgnore != null) {
if (experiments != null || cannotIgnore != null) {
buffer.writeln('analyzer:');
}
@ -140,11 +139,6 @@ class AbstractContextTest with ResourceProviderMixin {
}
}
if (implicitCasts != null) {
buffer.writeln(' strong-mode:');
buffer.writeln(' implicit-casts: $implicitCasts');
}
if (cannotIgnore != null) {
buffer.writeln(' cannot-ignore:');
for (var unignorable in cannotIgnore) {

View file

@ -28,7 +28,7 @@ class AnalysisOptionsFileNotificationTest extends PubPackageAnalysisServerTest {
final testSource = '''
void f() {
var x = '';
int y = x; // Not assignable in strong-mode
int y = x; // Not assignable.
print(y);
}''';

View file

@ -29,8 +29,6 @@ import 'src/utilities/mock_packages.dart';
/// TODO(scheglov) this is duplicate
class AnalysisOptionsFileConfig {
final List<String> experiments;
final bool implicitCasts;
final bool implicitDynamic;
final List<String> lints;
final bool strictCasts;
final bool strictInference;
@ -38,8 +36,6 @@ class AnalysisOptionsFileConfig {
AnalysisOptionsFileConfig({
this.experiments = const [],
this.implicitCasts = true,
this.implicitDynamic = true,
this.lints = const [],
this.strictCasts = false,
this.strictInference = false,
@ -60,15 +56,6 @@ class AnalysisOptionsFileConfig {
buffer.writeln(' strict-casts: $strictCasts');
buffer.writeln(' strict-inference: $strictInference');
buffer.writeln(' strict-raw-types: $strictRawTypes');
if (!implicitCasts || !implicitDynamic) {
buffer.writeln(' strong-mode:');
if (!implicitCasts) {
buffer.writeln(' implicit-casts: $implicitCasts');
}
if (!implicitDynamic) {
buffer.writeln(' implicit-dynamic: $implicitDynamic');
}
}
buffer.writeln('linter:');
buffer.writeln(' rules:');

View file

@ -99,7 +99,7 @@ linter:
final initialDiagnostics = await firstDiagnosticsUpdate;
expect(initialDiagnostics, hasLength(1));
expect(initialDiagnostics!.first.severity, DiagnosticSeverity.Warning);
expect(initialDiagnostics.first.code, 'undefined_lint_warning');
expect(initialDiagnostics.first.code, 'undefined_lint');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/43926')

View file

@ -5,6 +5,7 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
import 'package:analyzer/src/analysis_options/error/option_codes.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/lint/options_rule_validator.dart';
import 'package:linter/src/rules.dart';
@ -68,7 +69,7 @@ linter:
linter:
rules:
- undefined
''', [UNDEFINED_LINT_WARNING]);
''', [AnalysisOptionsWarningCode.UNDEFINED_LINT]);
}
void validate(String source, List<ErrorCode> expected) {

View file

@ -377,13 +377,12 @@ class AnalyticsManagerTest with ResourceProviderMixin {
String? path,
Map<String, String>? errors,
List<String>? experiments,
bool? implicitCasts,
List<String>? lints,
}) {
path ??= '$testPackageRootPath/analysis_options.yaml';
var buffer = StringBuffer();
if (errors != null || experiments != null || implicitCasts != null) {
if (errors != null || experiments != null) {
buffer.writeln('analyzer:');
}
@ -401,11 +400,6 @@ class AnalyticsManagerTest with ResourceProviderMixin {
}
}
if (implicitCasts != null) {
buffer.writeln(' strong-mode:');
buffer.writeln(' implicit-casts: $implicitCasts');
}
if (lints != null) {
buffer.writeln('linter:');
buffer.writeln(' rules:');

View file

@ -48,11 +48,4 @@ analyzer:
''', '''
''');
}
Future<void> test_strong_mode_settings_deprecated() async {
await assertHasFix('''
analyzer:
strong-mode: true
''', '');
}
}

View file

@ -1,163 +0,0 @@
// 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:test_reflective_loader/test_reflective_loader.dart';
import 'test_support.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(ReplaceWithStrictCastsTest);
});
}
@reflectiveTest
class ReplaceWithStrictCastsTest extends AnalysisOptionsFixTest {
Future<void> test_hasLanguage() async {
await assertHasFix('''
analyzer:
language:
strict-inference: true
strong-mode:
implicit-casts: false
''', '''
analyzer:
language:
strict-casts: true
strict-inference: true
''');
}
Future<void> test_hasLanguage_isAfter() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-casts: false
language:
strict-inference: true
''', '''
analyzer:
language:
strict-casts: true
strict-inference: true
''');
}
Future<void> test_hasStrictCastsFalse() async {
await assertHasFix('''
analyzer:
language:
strict-casts: false
strong-mode:
implicit-casts: false
''', '''
analyzer:
language:
strict-casts: true
''');
}
Future<void> test_hasStrictCastsTrue() async {
await assertHasFix('''
analyzer:
language:
strict-casts: true
strong-mode:
implicit-casts: false
''', '''
analyzer:
language:
strict-casts: true
''');
}
Future<void> test_noLanguage() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-casts: false
''', '''
analyzer:
language:
strict-casts: true
''');
}
Future<void> test_noLanguage_analyzerHasOtherEntries() async {
await assertHasFix('''
analyzer:
errors:
unused_import: ignore
strong-mode:
implicit-casts: false
''', '''
analyzer:
errors:
unused_import: ignore
language:
strict-casts: true
''');
}
Future<void> test_noLanguage_analyzerHasOtherEntriesAfter() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-casts: false
errors:
unused_import: ignore
''', '''
analyzer:
errors:
unused_import: ignore
language:
strict-casts: true
''');
}
Future<void> test_noLanguage_hasOtherStrongModeEntry() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
''', '''
analyzer:
language:
strict-casts: true
strong-mode:
implicit-dynamic: false
''', errorFilter: (error) => error.message.contains('implicit-casts'));
}
Future<void> test_noLanguage_implicitCastsHasComment() async {
await assertHasFix('''
analyzer:
strong-mode:
# No implicit casts
implicit-casts: false
''', '''
analyzer:
language:
strict-casts: true
''');
}
Future<void> test_noLanguage_strongModeHasComment() async {
// TODO(srawlins): This is unfortunate; it would be better to remove the
// comment. But we leave this assertion as is to show at least the file is
// not corrupted.
await assertHasFix('''
analyzer:
# Strong mode
strong-mode:
implicit-casts: false
''', '''
analyzer:
# Strong mode
language:
strict-casts: true
''');
}
}

View file

@ -1,163 +0,0 @@
// 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:test_reflective_loader/test_reflective_loader.dart';
import 'test_support.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(ReplaceWithStrictRawTypesTest);
});
}
@reflectiveTest
class ReplaceWithStrictRawTypesTest extends AnalysisOptionsFixTest {
Future<void> test_hasLanguage() async {
await assertHasFix('''
analyzer:
language:
strict-inference: true
strong-mode:
implicit-dynamic: false
''', '''
analyzer:
language:
strict-inference: true
strict-raw-types: true
''');
}
Future<void> test_hasLanguage_isAfter() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-dynamic: false
language:
strict-inference: true
''', '''
analyzer:
language:
strict-inference: true
strict-raw-types: true
''');
}
Future<void> test_hasStrictRawTypesFalse() async {
await assertHasFix('''
analyzer:
language:
strict-raw-types: false
strong-mode:
implicit-dynamic: false
''', '''
analyzer:
language:
strict-raw-types: true
''');
}
Future<void> test_hasStrictRawTypesTrue() async {
await assertHasFix('''
analyzer:
language:
strict-raw-types: true
strong-mode:
implicit-dynamic: false
''', '''
analyzer:
language:
strict-raw-types: true
''');
}
Future<void> test_noLanguage() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-dynamic: false
''', '''
analyzer:
language:
strict-raw-types: true
''');
}
Future<void> test_noLanguage_analyzerHasOtherEntries() async {
await assertHasFix('''
analyzer:
errors:
unused_import: ignore
strong-mode:
implicit-dynamic: false
''', '''
analyzer:
errors:
unused_import: ignore
language:
strict-raw-types: true
''');
}
Future<void> test_noLanguage_analyzerHasOtherEntriesAfter() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-dynamic: false
errors:
unused_import: ignore
''', '''
analyzer:
errors:
unused_import: ignore
language:
strict-raw-types: true
''');
}
Future<void> test_noLanguage_hasOtherStrongModeEntry() async {
await assertHasFix('''
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
''', '''
analyzer:
language:
strict-raw-types: true
strong-mode:
implicit-casts: false
''', errorFilter: (error) => error.message.contains('implicit-dynamic'));
}
Future<void> test_noLanguage_implicitDynamicHasComment() async {
await assertHasFix('''
analyzer:
strong-mode:
# No implicit dynamic
implicit-dynamic: false
''', '''
analyzer:
language:
strict-raw-types: true
''');
}
Future<void> test_noLanguage_strongModeHasComment() async {
// TODO(srawlins): This is unfortunate; it would be better to remove the
// comment. But we leave this assertion as is to show at least the file is
// not corrupted.
await assertHasFix('''
analyzer:
# Strong mode
strong-mode:
implicit-dynamic: false
''', '''
analyzer:
# Strong mode
language:
strict-raw-types: true
''');
}
}

View file

@ -6,15 +6,10 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'remove_lint_test.dart' as remove_lint;
import 'remove_setting_test.dart' as remove_setting;
import 'replace_with_strict_casts_test.dart' as replace_with_strict_casts;
import 'replace_with_strict_raw_types_test.dart'
as replace_with_strict_raw_types;
void main() {
defineReflectiveSuite(() {
remove_lint.main();
remove_setting.main();
replace_with_strict_casts.main();
replace_with_strict_raw_types.main();
});
}

View file

@ -120,29 +120,6 @@ extension on AnalysisOptionsImpl {
}
}
void applyStrongOptions(YamlNode? config) {
if (config is! YamlMap) {
return;
}
config.nodes.forEach((k, v) {
if (k is YamlScalar && v is YamlScalar) {
var feature = k.value?.toString();
var boolValue = v.boolValue;
if (boolValue == null) {
return;
}
if (feature == AnalyzerOptions.implicitCasts) {
implicitCasts = boolValue;
} else if (feature == AnalyzerOptions.implicitDynamic) {
implicitDynamic = boolValue;
} else if (feature == AnalyzerOptions.propagateLinterExceptions) {
propagateLinterExceptions = boolValue;
}
}
});
}
void applyUnignorables(YamlNode? cannotIgnore) {
if (cannotIgnore is! YamlList) {
return;
@ -200,10 +177,6 @@ extension AnalysisOptionsImplExtensions on AnalysisOptionsImpl {
}
var analyzer = optionMap.valueAt(AnalyzerOptions.analyzer);
if (analyzer is YamlMap) {
// Process strong mode option.
var strongMode = analyzer.valueAt(AnalyzerOptions.strongMode);
applyStrongOptions(strongMode);
// Process filters.
var filters = analyzer.valueAt(AnalyzerOptions.errors);
errorProcessors = ErrorConfig(filters).processors;

View file

@ -63,13 +63,37 @@ class AnalysisOptionsErrorCode extends ErrorCode {
}
class AnalysisOptionsHintCode extends ErrorCode {
/// An error code indicating that strong-mode: true is deprecated.
static const AnalysisOptionsHintCode STRONG_MODE_SETTING_DEPRECATED =
/// A hint code indicating reference to a deprecated lint.
///
/// Parameters:
/// 0: the rule name
static const AnalysisOptionsHintCode DEPRECATED_LINT =
AnalysisOptionsHintCode(
'STRONG_MODE_SETTING_DEPRECATED',
"The 'strong-mode: true' setting is deprecated.",
correctionMessage:
"It is no longer necessary to explicitly enable strong mode.",
'DEPRECATED_LINT',
"'{0}' is a deprecated lint rule and should not be used.",
correctionMessage: "Try removing '{0}'.",
);
/// A hint code indicating reference to a deprecated lint.
///
/// Parameters:
/// 0: the deprecated lint name
/// 1: the replacing rule name
static const AnalysisOptionsHintCode DEPRECATED_LINT_WITH_REPLACEMENT =
AnalysisOptionsHintCode(
'DEPRECATED_LINT_WITH_REPLACEMENT',
"'{0}' is deprecated and should be replaced by '{1}'.",
correctionMessage: "Try replacing '{0}' with '{1}'.",
);
/// Duplicate rules.
///
/// Parameters:
/// 0: the rule name
static const AnalysisOptionsHintCode DUPLICATE_RULE = AnalysisOptionsHintCode(
'DUPLICATE_RULE',
"The rule {0} is already specified and doesn't need to be specified again.",
correctionMessage: "Try removing all but one specification of the rule.",
);
/// Initialize a newly created error code to have the given [name].
@ -143,6 +167,18 @@ class AnalysisOptionsWarningCode extends ErrorCode {
"The include file '{0}' in '{1}' can't be found when analyzing '{2}'.",
);
/// An error code indicating an incompatible rule.
///
/// Parameters:
/// 0: the rule name
/// 1: the incompatible rule
static const AnalysisOptionsWarningCode INCOMPATIBLE_LINT =
AnalysisOptionsWarningCode(
'INCOMPATIBLE_LINT',
"The rule '{0}' is incompatible with the rule '{1}'.",
correctionMessage: "Try removing one of the incompatible rules.",
);
/// An error code indicating that a plugin is being configured with an invalid
/// value for an option and a detail message is provided.
///
@ -214,14 +250,15 @@ class AnalysisOptionsWarningCode extends ErrorCode {
correctionMessage: "Replace '{0}' with '{1}'.",
);
/// An error code indicating that strong-mode: false is has been removed.
static const AnalysisOptionsWarningCode SPEC_MODE_REMOVED =
/// An error code indicating an undefined lint rule.
///
/// Parameters:
/// 0: the rule name
static const AnalysisOptionsWarningCode UNDEFINED_LINT =
AnalysisOptionsWarningCode(
'SPEC_MODE_REMOVED',
"The option 'strong-mode: false' is no longer supported.",
correctionMessage:
"It's recommended to remove the 'strong-mode:' setting (and make your "
"code Dart 2 compliant).",
'UNDEFINED_LINT',
"'{0}' is not a recognized lint rule.",
correctionMessage: "Try using the name of a recognized lint rule.",
);
/// An error code indicating that an unrecognized error code is being used to

View file

@ -41,13 +41,11 @@ class AnalysisContextImpl implements AnalysisContext {
// TODO() remove this method as well
_typeSystemLegacy?.updateOptions(
implicitCasts: analysisOptions.implicitCasts,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
);
_typeSystemNonNullableByDefault?.updateOptions(
implicitCasts: analysisOptions.implicitCasts,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
);
@ -91,7 +89,6 @@ class AnalysisContextImpl implements AnalysisContext {
}
_typeSystemLegacy = TypeSystemImpl(
implicitCasts: analysisOptions.implicitCasts,
isNonNullableByDefault: false,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
@ -99,7 +96,6 @@ class AnalysisContextImpl implements AnalysisContext {
);
_typeSystemNonNullableByDefault = TypeSystemImpl(
implicitCasts: analysisOptions.implicitCasts,
isNonNullableByDefault: true,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,

View file

@ -575,7 +575,6 @@ class DartObjectImpl implements DartObject, Constant {
DartObjectImpl isIdentical(
TypeProvider typeProvider, DartObjectImpl rightOperand) {
var typeSystem = TypeSystemImpl(
implicitCasts: false,
isNonNullableByDefault: false,
strictCasts: false,
strictInference: false,

View file

@ -57,11 +57,6 @@ class TypeSystemImpl implements TypeSystem {
/// The provider of types for the system.
final TypeProviderImpl typeProvider;
/// False if implicit casts should always be disallowed.
///
/// This affects the behavior of [isAssignableTo].
bool implicitCasts;
/// True if "strict casts" should be enforced.
///
/// This affects the behavior of [isAssignableTo].
@ -91,7 +86,6 @@ class TypeSystemImpl implements TypeSystem {
late final SubtypeHelper _subtypeHelper;
TypeSystemImpl({
required this.implicitCasts,
required this.isNonNullableByDefault,
required this.strictCasts,
required this.strictInference,
@ -924,10 +918,9 @@ class TypeSystemImpl implements TypeSystem {
}
}
// First make sure that the static analysis options, `implicit-casts: false`
// and `strict-casts: true` disable all downcasts, including casts from
// `dynamic`.
if (!implicitCasts || strictCasts) {
// First make sure that the static analysis option, `strict-casts: true`
// disables all downcasts, including casts from `dynamic`.
if (strictCasts) {
return false;
}
@ -1935,11 +1928,9 @@ class TypeSystemImpl implements TypeSystem {
}
void updateOptions({
required bool implicitCasts,
required bool strictCasts,
required bool strictInference,
}) {
this.implicitCasts = implicitCasts;
this.strictCasts = strictCasts;
this.strictInference = strictInference;
}

View file

@ -715,7 +715,6 @@ class FileResolver {
}
var analysisOptions = AnalysisOptionsImpl()
..implicitCasts = fileAnalysisOptions.implicitCasts
..strictInference = fileAnalysisOptions.strictInference;
if (fsState == null) {

View file

@ -5756,126 +5756,6 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
}
class LanguageCode extends ErrorCode {
/// Parameters:
/// 0: the name of the field
static const LanguageCode IMPLICIT_DYNAMIC_FIELD = LanguageCode(
'IMPLICIT_DYNAMIC_FIELD',
"Missing field type for '{0}'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of the function
/// 1: the names of the type arguments
static const LanguageCode IMPLICIT_DYNAMIC_FUNCTION = LanguageCode(
'IMPLICIT_DYNAMIC_FUNCTION',
"Missing type arguments for generic function '{0}<{1}>'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of type
static const LanguageCode IMPLICIT_DYNAMIC_INVOKE = LanguageCode(
'IMPLICIT_DYNAMIC_INVOKE',
"Missing type arguments for calling generic function type '{0}'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
static const LanguageCode IMPLICIT_DYNAMIC_LIST_LITERAL = LanguageCode(
'IMPLICIT_DYNAMIC_LIST_LITERAL',
"Missing type argument for list literal.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
static const LanguageCode IMPLICIT_DYNAMIC_MAP_LITERAL = LanguageCode(
'IMPLICIT_DYNAMIC_MAP_LITERAL',
"Missing type arguments for map literal.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of the function
/// 1: the names of the type arguments
static const LanguageCode IMPLICIT_DYNAMIC_METHOD = LanguageCode(
'IMPLICIT_DYNAMIC_METHOD',
"Missing type arguments for generic method '{0}<{1}>'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of the parameter
static const LanguageCode IMPLICIT_DYNAMIC_PARAMETER = LanguageCode(
'IMPLICIT_DYNAMIC_PARAMETER',
"Missing parameter type for '{0}'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of the function or method
static const LanguageCode IMPLICIT_DYNAMIC_RETURN = LanguageCode(
'IMPLICIT_DYNAMIC_RETURN',
"Missing return type for '{0}'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of the type
static const LanguageCode IMPLICIT_DYNAMIC_TYPE = LanguageCode(
'IMPLICIT_DYNAMIC_TYPE',
"Missing type arguments for generic type '{0}'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Parameters:
/// 0: the name of the variable
static const LanguageCode IMPLICIT_DYNAMIC_VARIABLE = LanguageCode(
'IMPLICIT_DYNAMIC_VARIABLE',
"Missing variable type for '{0}'.",
correctionMessage:
"Try adding an explicit type, or remove implicit-dynamic from your "
"analysis options file.",
);
/// Initialize a newly created error code to have the given [name].
const LanguageCode(
String name,
String problemMessage, {
super.correctionMessage,
super.hasPublishedDocs = false,
super.isUnresolvedIdentifier = false,
String? uniqueName,
}) : super(
name: name,
problemMessage: problemMessage,
uniqueName: 'LanguageCode.${uniqueName ?? name}',
);
@override
ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity;
@override
ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
}
class StaticWarningCode extends AnalyzerErrorCode {
/// No parameters.
static const StaticWarningCode DEAD_NULL_AWARE_EXPRESSION = StaticWarningCode(

View file

@ -26,18 +26,21 @@ import 'package:analyzer/src/pubspec/pubspec_warning_code.dart';
const List<ErrorCode> errorCodeValues = [
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
AnalysisOptionsErrorCode.PARSE_ERROR,
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED,
AnalysisOptionsHintCode.DEPRECATED_LINT,
AnalysisOptionsHintCode.DEPRECATED_LINT_WITH_REPLACEMENT,
AnalysisOptionsHintCode.DUPLICATE_RULE,
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED,
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT,
AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING,
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
AnalysisOptionsWarningCode.INCOMPATIBLE_LINT,
AnalysisOptionsWarningCode.INVALID_OPTION,
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
AnalysisOptionsWarningCode.MULTIPLE_PLUGINS,
AnalysisOptionsWarningCode.RECURSIVE_INCLUDE_FILE,
AnalysisOptionsWarningCode.REMOVED_LINT,
AnalysisOptionsWarningCode.REPLACED_LINT,
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED,
AnalysisOptionsWarningCode.UNDEFINED_LINT,
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITHOUT_VALUES,
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE,
@ -619,16 +622,6 @@ const List<ErrorCode> errorCodeValues = [
HintCode.UNREACHABLE_SWITCH_CASE,
HintCode.UNUSED_ELEMENT,
HintCode.UNUSED_ELEMENT_PARAMETER,
LanguageCode.IMPLICIT_DYNAMIC_FIELD,
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION,
LanguageCode.IMPLICIT_DYNAMIC_INVOKE,
LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL,
LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL,
LanguageCode.IMPLICIT_DYNAMIC_METHOD,
LanguageCode.IMPLICIT_DYNAMIC_PARAMETER,
LanguageCode.IMPLICIT_DYNAMIC_RETURN,
LanguageCode.IMPLICIT_DYNAMIC_TYPE,
LanguageCode.IMPLICIT_DYNAMIC_VARIABLE,
ManifestWarningCode.CAMERA_PERMISSIONS_INCOMPATIBLE,
ManifestWarningCode.NON_RESIZABLE_ACTIVITY,
ManifestWarningCode.NO_TOUCHSCREEN_FEATURE,

View file

@ -148,7 +148,6 @@ class TypeArgumentsVerifier {
node.function.staticType,
node.staticInvokeType,
);
_checkForImplicitDynamicInvoke(node);
}
void checkFunctionReference(FunctionReference node) {
@ -171,7 +170,6 @@ class TypeArgumentsVerifier {
_checkTypeArgumentCount(typeArguments, 1,
CompileTimeErrorCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS);
}
_checkForImplicitDynamicTypedLiteral(node);
}
void checkMapLiteral(SetOrMapLiteral node) {
@ -186,7 +184,6 @@ class TypeArgumentsVerifier {
_checkTypeArgumentCount(typeArguments, 2,
CompileTimeErrorCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS);
}
_checkForImplicitDynamicTypedLiteral(node);
}
void checkMethodInvocation(MethodInvocation node) {
@ -195,7 +192,6 @@ class TypeArgumentsVerifier {
node.function.staticType,
node.staticInvokeType,
);
_checkForImplicitDynamicInvoke(node);
}
void checkNamedType(NamedType node) {
@ -219,63 +215,6 @@ class TypeArgumentsVerifier {
_checkTypeArgumentCount(typeArguments, 1,
CompileTimeErrorCode.EXPECTED_ONE_SET_TYPE_ARGUMENTS);
}
_checkForImplicitDynamicTypedLiteral(node);
}
void _checkForImplicitDynamicInvoke(InvocationExpression node) {
if (_options.implicitDynamic || node.typeArguments != null) {
return;
}
var invokeType = node.staticInvokeType;
var declaredType = node.function.staticType;
if (invokeType is FunctionType &&
declaredType is FunctionType &&
declaredType.typeFormals.isNotEmpty) {
List<DartType> typeArgs = node.typeArgumentTypes!;
if (typeArgs.any((t) => t is DynamicType)) {
// Issue an error depending on what we're trying to call.
Expression function = node.function;
if (function is Identifier) {
var element = function.staticElement;
if (element is MethodElement) {
_errorReporter.reportErrorForNode(
LanguageCode.IMPLICIT_DYNAMIC_METHOD,
node.function,
[element.displayName, element.typeParameters.join(', ')]);
return;
}
if (element is FunctionElement) {
_errorReporter.reportErrorForNode(
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION,
node.function,
[element.displayName, element.typeParameters.join(', ')]);
return;
}
}
// The catch all case if neither of those matched.
// For example, invoking a function expression.
_errorReporter.reportErrorForNode(LanguageCode.IMPLICIT_DYNAMIC_INVOKE,
node.function, [declaredType]);
}
}
}
void _checkForImplicitDynamicTypedLiteral(TypedLiteral node) {
if (_options.implicitDynamic || node.typeArguments != null) {
return;
}
DartType type = node.typeOrThrow;
// It's an error if either the key or value was inferred as dynamic.
if (type is InterfaceType &&
type.typeArguments.any((t) => t is DynamicType)) {
// TODO(brianwilkerson) Add StrongModeCode.IMPLICIT_DYNAMIC_SET_LITERAL
ErrorCode errorCode = node is ListLiteral
? LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL
: LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL;
_errorReporter.reportErrorForNode(errorCode, node);
}
}
/// Checks a type annotation for a raw generic type, and reports the

View file

@ -207,22 +207,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
/// `true`.
List<Linter>? _lintRules;
/// A flag indicating whether implicit casts are allowed in [strongMode]
/// (they are always allowed in Dart 1.0 mode).
///
/// This option is experimental and subject to change.
bool implicitCasts = true;
/// A flag indicating whether implicit dynamic type is allowed, on by default.
///
/// This flag can be used without necessarily enabling [strongMode], but it is
/// designed with strong mode's type inference in mind. Without type inference,
/// it will raise many errors. Also it does not provide type safety without
/// strong mode.
///
/// This option is experimental and subject to change.
bool implicitDynamic = true;
/// Indicates whether linter exceptions should be propagated to the caller (by
/// re-throwing them)
bool propagateLinterExceptions = false;
@ -271,8 +255,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
lintRules = options.lintRules;
if (options is AnalysisOptionsImpl) {
enableTiming = options.enableTiming;
implicitCasts = options.implicitCasts;
implicitDynamic = options.implicitDynamic;
propagateLinterExceptions = options.propagateLinterExceptions;
strictInference = options.strictInference;
strictRawTypes = options.strictRawTypes;
@ -336,8 +318,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
}
// Append boolean flags.
buffer.addBool(implicitCasts);
buffer.addBool(implicitDynamic);
buffer.addBool(propagateLinterExceptions);
buffer.addBool(strictCasts);
buffer.addBool(strictInference);

View file

@ -823,7 +823,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
_checkForTypeAnnotationDeferredClass(returnType);
_returnTypeVerifier.verifyReturnType(returnType);
_checkForImplicitDynamicReturn(node.name, node.declaredElement!);
_checkForMainFunction1(node.name, node.declaredElement!);
_checkForMainFunction2(node);
super.visitFunctionDeclaration(node);
@ -884,20 +883,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
try {
_checkForTypeAnnotationDeferredClass(node.returnType);
// TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and
// we can get the function element via `node?.element?.type?.element` but
// it doesn't have hasImplicitReturnType set correctly.
if (!_options.implicitDynamic && node.returnType == null) {
DartType parameterType = node.declaredElement!.type;
if (parameterType is FunctionType &&
parameterType.returnType is DynamicType) {
errorReporter.reportErrorForToken(
LanguageCode.IMPLICIT_DYNAMIC_RETURN,
node.name,
[node.name.lexeme]);
}
}
super.visitFunctionTypedFormalParameter(node);
} finally {
_isInFunctionTypedFormalParameter = old;
@ -922,12 +907,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
node.whenClause?.accept(this);
}
@override
void visitImplementsClause(ImplementsClause node) {
node.interfaces.forEach(_checkForImplicitDynamicType);
super.visitImplementsClause(node);
}
@override
void visitImportDirective(ImportDirective node) {
var importElement = node.element;
@ -983,7 +962,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_checkForNewWithUndefinedConstructor(node, constructorName, namedType);
}
}
_checkForImplicitDynamicType(namedType);
super.visitInstanceCreationExpression(node);
}
@ -1034,7 +1012,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_checkForExtensionDeclaresMemberOfObject(node);
_checkForTypeAnnotationDeferredClass(returnType);
_returnTypeVerifier.verifyReturnType(returnType);
_checkForImplicitDynamicReturn(node.name, node.declaredElement!);
_checkForWrongTypeParameterVarianceInMethod(node);
super.visitMethodDeclaration(node);
});
@ -1238,16 +1215,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
void visitSimpleFormalParameter(SimpleFormalParameter node) {
_checkForPrivateOptionalParameter(node);
_checkForTypeAnnotationDeferredClass(node.type);
// Checks for an implicit dynamic parameter type.
//
// We can skip other parameter kinds besides simple formal, because:
// - DefaultFormalParameter contains a simple one, so it gets here,
// - FieldFormalParameter error should be reported on the field,
// - FunctionTypedFormalParameter is a function type, not dynamic.
_checkForImplicitDynamicIdentifier(node, node.name,
variable: node.declaredElement!);
super.visitSimpleFormalParameter(node);
}
@ -1423,7 +1390,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_checkForBuiltInIdentifierAsName(node.name,
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME);
_checkForTypeAnnotationDeferredClass(node.bound);
_checkForImplicitDynamicType(node.bound);
_checkForGenericFunctionType(node.bound);
node.bound?.accept(_uninstantiatedBoundChecker);
super.visitTypeParameter(node);
@ -1441,8 +1407,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
final nameToken = node.name;
var initializerNode = node.initializer;
// do checks
_checkForImplicitDynamicIdentifier(node, nameToken,
variable: node.declaredElement!);
_checkForAbstractOrExternalVariableInitializer(node);
// visit initializer
String name = nameToken.lexeme;
@ -1481,12 +1445,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_isInLateLocalVariable.removeLast();
}
@override
void visitWithClause(WithClause node) {
node.mixinTypes.forEach(_checkForImplicitDynamicType);
super.visitWithClause(node);
}
/// Checks the class for problems with the superclass, mixins, or implemented
/// interfaces.
void _checkClassInheritance(
@ -1501,7 +1459,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
!_checkForImplementsClauseErrorCodes(implementsClause) &&
!_checkForAllMixinErrorCodes(withClause) &&
!_checkForNoGenerativeConstructorsInSuperclass(superclass)) {
_checkForImplicitDynamicType(superclass);
_checkForExtendsDeferredClass(superclass);
_checkForRepeatedType(implementsClause?.interfaces,
CompileTimeErrorCode.IMPLEMENTS_REPEATED);
@ -3257,61 +3214,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
return foundError;
}
void _checkForImplicitDynamicIdentifier(
AstNode node,
Token? id, {
required VariableElement variable,
}) {
if (id == null) {
return;
}
if (_options.implicitDynamic) {
return;
}
if (variable.hasImplicitType && variable.type is DynamicType) {
ErrorCode errorCode;
if (variable is FieldElement) {
errorCode = LanguageCode.IMPLICIT_DYNAMIC_FIELD;
} else if (variable is ParameterElement) {
errorCode = LanguageCode.IMPLICIT_DYNAMIC_PARAMETER;
} else {
errorCode = LanguageCode.IMPLICIT_DYNAMIC_VARIABLE;
}
// Parameters associated with a variable always have a name, so we can
// safely rely on [id] being non-`null`.
errorReporter.reportErrorForNode(errorCode, node, [id.lexeme]);
}
}
void _checkForImplicitDynamicReturn(
Token functionName, ExecutableElement element) {
if (_options.implicitDynamic) {
return;
}
if (element is PropertyAccessorElement && element.isSetter) {
return;
}
if (element.hasImplicitReturnType && element.returnType is DynamicType) {
errorReporter.reportErrorForToken(LanguageCode.IMPLICIT_DYNAMIC_RETURN,
functionName, [element.displayName]);
}
}
void _checkForImplicitDynamicType(TypeAnnotation? node) {
if (_options.implicitDynamic ||
node == null ||
(node is NamedType && node.typeArguments != null)) {
return;
}
DartType type = node.typeOrThrow;
if (type is ParameterizedType &&
type.typeArguments.isNotEmpty &&
type.typeArguments.any((t) => t is DynamicType)) {
errorReporter
.reportErrorForNode(LanguageCode.IMPLICIT_DYNAMIC_TYPE, node, [type]);
}
}
/// Check that if the visiting library is not system, then any given library
/// should not be SDK internal library. The [importElement] is the
/// [LibraryImportElement] retrieved from the node, if the element in the node was

View file

@ -14,54 +14,6 @@ import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';
// TODO(pq): migrate these codes to `option_codes.dart`?
/// A hint code indicating reference to a deprecated lint.
///
/// Parameters:
/// 0: the rule name
const AnalysisOptionsHintCode DEPRECATED_LINT_HINT = AnalysisOptionsHintCode(
'DEPRECATED_LINT_HINT',
"'{0}' is a deprecated lint rule and should not be used",
correctionMessage: "Try removing '{0}'.");
/// A hint code indicating reference to a deprecated lint.
///
/// Parameters:
/// 0: the deprecated lint name
/// 1: the replacing rule name
const AnalysisOptionsHintCode DEPRECATED_LINT_HINT_WITH_REPLACEMENT =
AnalysisOptionsHintCode('DEPRECATED_LINT_HINT_WITH_REPLACEMENT',
"'{0}' is deprecated and should be replaced by '{1}'",
correctionMessage: "Try replacing '{0}' with '{1}'.");
/// Duplicate rules.
///
/// Parameters:
/// 0: the rule name
const AnalysisOptionsHintCode DUPLICATE_RULE_HINT = AnalysisOptionsHintCode(
'DUPLICATE_RULE',
"The rule {0} is already specified and doesn't need to be specified again.",
correctionMessage: "Try removing all but one specification of the rule.");
/// An error code indicating an incompatible rule.
///
/// Parameters:
/// 0: the rule name
/// 1: the incompatible rule
const AnalysisOptionsWarningCode INCOMPATIBLE_LINT_WARNING =
AnalysisOptionsWarningCode('INCOMPATIBLE_LINT_WARNING',
"The rule '{0}' is incompatible with the rule '{1}'",
correctionMessage: "Try removing one of the incompatible rules.");
/// An error code indicating an undefined lint rule.
///
/// Parameters:
/// 0: the rule name
const AnalysisOptionsWarningCode UNDEFINED_LINT_WARNING =
AnalysisOptionsWarningCode(
'UNDEFINED_LINT_WARNING', "'{0}' is not a recognized lint rule");
/// Rule provider.
typedef LintRuleProvider = Iterable<LintRule> Function();
@ -127,7 +79,8 @@ class LinterRuleOptionsValidator extends OptionsValidator {
final rule = getRegisteredLint(value as Object);
if (rule == null) {
reporter.reportErrorForSpan(UNDEFINED_LINT_WARNING, node.span, [value]);
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.UNDEFINED_LINT, node.span, [value]);
return;
}
@ -135,9 +88,12 @@ class LinterRuleOptionsValidator extends OptionsValidator {
final incompatibleRule = findIncompatibleRule(rule);
if (incompatibleRule != null) {
reporter.reportErrorForSpan(
INCOMPATIBLE_LINT_WARNING, node.span, [value, incompatibleRule]);
AnalysisOptionsWarningCode.INCOMPATIBLE_LINT,
node.span,
[value, incompatibleRule]);
} else if (!seenRules.add(rule.name)) {
reporter.reportErrorForSpan(DUPLICATE_RULE_HINT, node.span, [value]);
reporter.reportErrorForSpan(
AnalysisOptionsHintCode.DUPLICATE_RULE, node.span, [value]);
}
}
// Report removed or deprecated lint warnings defined directly (and not in
@ -147,11 +103,13 @@ class LinterRuleOptionsValidator extends OptionsValidator {
if (state is DeprecatedState && isDeprecatedInCurrentSdk(state)) {
var replacedBy = state.replacedBy;
if (replacedBy != null) {
reporter.reportErrorForSpan(DEPRECATED_LINT_HINT_WITH_REPLACEMENT,
node.span, [value, replacedBy]);
reporter.reportErrorForSpan(
AnalysisOptionsHintCode.DEPRECATED_LINT_WITH_REPLACEMENT,
node.span,
[value, replacedBy]);
} else {
reporter
.reportErrorForSpan(DEPRECATED_LINT_HINT, node.span, [value]);
reporter.reportErrorForSpan(
AnalysisOptionsHintCode.DEPRECATED_LINT, node.span, [value]);
}
} else if (isRemovedInCurrentSdk(state)) {
var since = state.since.toString();

View file

@ -853,9 +853,7 @@ class StrongModeOptionValueValidator extends OptionsValidator {
var analyzer = options.valueAt(AnalyzerOptions.analyzer);
if (analyzer is YamlMap) {
var strongModeNode = analyzer.valueAt(AnalyzerOptions.strongMode);
if (strongModeNode is YamlScalar) {
return _validateStrongModeAsScalar(reporter, strongModeNode);
} else if (strongModeNode is YamlMap) {
if (strongModeNode is YamlMap) {
return _validateStrongModeAsMap(reporter, strongModeNode);
} else if (strongModeNode != null) {
reporter.reportErrorForSpan(
@ -875,21 +873,11 @@ class StrongModeOptionValueValidator extends OptionsValidator {
_builder.reportError(reporter, AnalyzerOptions.strongMode, k);
} else if (key == AnalyzerOptions.declarationCasts) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED,
k.span,
[AnalyzerOptions.declarationCasts]);
} else if (key == AnalyzerOptions.implicitCasts) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode
.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT,
k.span,
[AnalyzerOptions.implicitCasts, 'strict-casts']);
} else if (key == AnalyzerOptions.implicitDynamic) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode
.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT,
k.span,
[AnalyzerOptions.implicitDynamic, 'strict-raw-types']);
AnalysisOptionsWarningCode.UNSUPPORTED_VALUE, v.span, [
AnalyzerOptions.strongMode,
v.valueOrThrow,
AnalyzerOptions.trueOrFalseProposal
]);
} else {
// The key is valid.
if (v is YamlScalar) {
@ -905,26 +893,6 @@ class StrongModeOptionValueValidator extends OptionsValidator {
}
});
}
void _validateStrongModeAsScalar(
ErrorReporter reporter, YamlScalar strongModeNode) {
var stringValue = toLowerCase(strongModeNode.value);
if (!AnalyzerOptions.trueOrFalse.contains(stringValue)) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.UNSUPPORTED_VALUE, strongModeNode.span, [
AnalyzerOptions.strongMode,
strongModeNode.valueOrThrow,
AnalyzerOptions.trueOrFalseProposal
]);
} else if (stringValue == 'false') {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED, strongModeNode.span);
} else if (stringValue == 'true') {
reporter.reportErrorForSpan(
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED,
strongModeNode.span);
}
}
}
/// Validates `analyzer` top-level options.

View file

@ -54,10 +54,31 @@ AnalysisOptionsErrorCode:
Parameters:
0: the error message from the parse error
AnalysisOptionsHintCode:
STRONG_MODE_SETTING_DEPRECATED:
problemMessage: "The 'strong-mode: true' setting is deprecated."
correctionMessage: It is no longer necessary to explicitly enable strong mode.
comment: "An error code indicating that strong-mode: true is deprecated."
DEPRECATED_LINT:
problemMessage: "'{0}' is a deprecated lint rule and should not be used."
correctionMessage: Try removing '{0}'.
comment: |-
A hint code indicating reference to a deprecated lint.
Parameters:
0: the rule name
DEPRECATED_LINT_WITH_REPLACEMENT:
problemMessage: "'{0}' is deprecated and should be replaced by '{1}'."
correctionMessage: "Try replacing '{0}' with '{1}'."
comment: |-
A hint code indicating reference to a deprecated lint.
Parameters:
0: the deprecated lint name
1: the replacing rule name
DUPLICATE_RULE:
problemMessage: "The rule {0} is already specified and doesn't need to be specified again."
correctionMessage: "Try removing all but one specification of the rule."
comment: |-
Duplicate rules.
Parameters:
0: the rule name
AnalysisOptionsWarningCode:
ANALYSIS_OPTION_DEPRECATED:
problemMessage: "The option '{0}' is no longer supported."
@ -95,6 +116,15 @@ AnalysisOptionsWarningCode:
0: the URI of the file to be included
1: the path of the file containing the include directive
2: the path of the context being analyzed
INCOMPATIBLE_LINT:
problemMessage: "The rule '{0}' is incompatible with the rule '{1}'."
correctionMessage: "Try removing one of the incompatible rules."
comment: |-
An error code indicating an incompatible rule.
Parameters:
0: the rule name
1: the incompatible rule
INVALID_OPTION:
problemMessage: "Invalid option specified for '{0}': {1}"
comment: |-
@ -147,10 +177,14 @@ AnalysisOptionsWarningCode:
0: the rule name
1: the SDK version in which the lint was removed
2: the name of a replacing lint
SPEC_MODE_REMOVED:
problemMessage: "The option 'strong-mode: false' is no longer supported."
correctionMessage: "It's recommended to remove the 'strong-mode:' setting (and make your code Dart 2 compliant)."
comment: "An error code indicating that strong-mode: false is has been removed."
UNDEFINED_LINT:
problemMessage: "'{0}' is not a recognized lint rule."
correctionMessage: "Try using the name of a recognized lint rule."
comment: |-
An error code indicating an undefined lint rule.
Parameters:
0: the rule name
UNRECOGNIZED_ERROR_CODE:
problemMessage: "'{0}' isn't a recognized error code."
comment: |-
@ -20139,63 +20173,6 @@ HintCode:
UNUSED_LOCAL_VARIABLE:
aliasFor: WarningCode.UNUSED_LOCAL_VARIABLE
comment: This is the deprecated alias for [WarningCode.UNUSED_LOCAL_VARIABLE].
LanguageCode:
IMPLICIT_DYNAMIC_FIELD:
problemMessage: "Missing field type for '{0}'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the field
IMPLICIT_DYNAMIC_FUNCTION:
problemMessage: "Missing type arguments for generic function '{0}<{1}>'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the function
1: the names of the type arguments
IMPLICIT_DYNAMIC_INVOKE:
problemMessage: "Missing type arguments for calling generic function type '{0}'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of type
IMPLICIT_DYNAMIC_LIST_LITERAL:
problemMessage: Missing type argument for list literal.
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
IMPLICIT_DYNAMIC_MAP_LITERAL:
problemMessage: Missing type arguments for map literal.
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
IMPLICIT_DYNAMIC_METHOD:
problemMessage: "Missing type arguments for generic method '{0}<{1}>'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the function
1: the names of the type arguments
IMPLICIT_DYNAMIC_PARAMETER:
problemMessage: "Missing parameter type for '{0}'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the parameter
IMPLICIT_DYNAMIC_RETURN:
problemMessage: "Missing return type for '{0}'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the function or method
IMPLICIT_DYNAMIC_TYPE:
problemMessage: "Missing type arguments for generic type '{0}'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the type
IMPLICIT_DYNAMIC_VARIABLE:
problemMessage: "Missing variable type for '{0}'."
correctionMessage: Try adding an explicit type, or remove implicit-dynamic from your analysis options file.
comment: |-
Parameters:
0: the name of the variable
ManifestWarningCode:
CAMERA_PERMISSIONS_INCOMPATIBLE:
problemMessage: Camera permissions make app incompatible for Chrome OS, consider adding optional features "android.hardware.camera" and "android.hardware.camera.autofocus".

View file

@ -41,7 +41,6 @@ class TestAnalysisContext implements AnalysisContext {
);
_typeSystemLegacy = TypeSystemImpl(
implicitCasts: _analysisOptions.implicitCasts,
isNonNullableByDefault: false,
strictCasts: _analysisOptions.strictCasts,
strictInference: _analysisOptions.strictInference,
@ -49,7 +48,6 @@ class TestAnalysisContext implements AnalysisContext {
);
_typeSystemNonNullableByDefault = TypeSystemImpl(
implicitCasts: _analysisOptions.implicitCasts,
isNonNullableByDefault: true,
strictCasts: _analysisOptions.strictCasts,
strictInference: _analysisOptions.strictInference,

View file

@ -230,8 +230,6 @@ environment:
actual.lintRules.map((l) => l.name),
unorderedEquals(expected.lintRules.map((l) => l.name)),
);
expect(actual.implicitCasts, expected.implicitCasts);
expect(actual.implicitDynamic, expected.implicitDynamic);
expect(
actual.propagateLinterExceptions, expected.propagateLinterExceptions);
expect(actual.strictInference, expected.strictInference);

View file

@ -2518,46 +2518,6 @@ int b = a;
);
}
test_reuse_incompatibleOptions_implicitCasts() async {
newFile('/workspace/dart/aaa/BUILD', '');
newAnalysisOptionsYamlFile('/workspace/dart/aaa', r'''
analyzer:
strong-mode:
implicit-casts: false
''');
newFile('/workspace/dart/bbb/BUILD', '');
newAnalysisOptionsYamlFile('/workspace/dart/bbb', r'''
analyzer:
strong-mode:
implicit-casts: true
''');
// Implicit casts are disabled in 'aaa'.
var aPath = '/workspace/dart/aaa/lib/a.dart';
await assertErrorsInFile(aPath, r'''
num a = 0;
int b = a;
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 19, 1),
]);
// Implicit casts are enabled in 'bbb'.
var bPath = '/workspace/dart/bbb/lib/a.dart';
await assertErrorsInFile(bPath, r'''
num a = 0;
int b = a;
''', []);
// Implicit casts are still disabled in 'aaa'.
await assertErrorsInFile(aPath, r'''
num a = 0;
int b = a;
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 19, 1),
]);
}
test_switchCase_implementsEquals_enum() async {
await assertNoErrorsInCode(r'''
enum MyEnum {a, b, c}

View file

@ -43,8 +43,6 @@ export 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
class AnalysisOptionsFileConfig {
final List<String> experiments;
final bool implicitCasts;
final bool implicitDynamic;
final List<String> lints;
final bool strictCasts;
final bool strictInference;
@ -53,8 +51,6 @@ class AnalysisOptionsFileConfig {
AnalysisOptionsFileConfig({
this.experiments = const [],
this.implicitCasts = true,
this.implicitDynamic = true,
this.lints = const [],
this.strictCasts = false,
this.strictInference = false,
@ -74,9 +70,6 @@ class AnalysisOptionsFileConfig {
buffer.writeln(' strict-casts: $strictCasts');
buffer.writeln(' strict-inference: $strictInference');
buffer.writeln(' strict-raw-types: $strictRawTypes');
buffer.writeln(' strong-mode:');
buffer.writeln(' implicit-casts: $implicitCasts');
buffer.writeln(' implicit-dynamic: $implicitDynamic');
buffer.writeln(' cannot-ignore:');
for (var name in unignorableNames) {
buffer.writeln(' - $name');
@ -553,35 +546,6 @@ mixin WithLanguage219Mixin on PubPackageResolutionTest {
String? get testPackageLanguageVersion => '2.19';
}
mixin WithNoImplicitCastsMixin on PubPackageResolutionTest {
/// Asserts that no errors are reported in [code] when implicit casts are
/// allowed, and that [expectedErrors] are reported for the same [code] when
/// implicit casts are not allowed.
Future<void> assertErrorsWithNoImplicitCasts(
String code,
List<ExpectedError> expectedErrors,
) async {
await resolveTestCode(code);
assertNoErrorsInResult();
await disposeAnalysisContextCollection();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(
implicitCasts: false,
),
);
await resolveTestFile();
assertErrorsInResult(expectedErrors);
}
/// Asserts that no errors are reported in [code], both when implicit casts
/// are allowed and when implicit casts are not allowed.
Future<void> assertNoErrorsWithNoImplicitCasts(String code) async =>
assertErrorsWithNoImplicitCasts(code, []);
}
mixin WithoutConstructorTearoffsMixin on PubPackageResolutionTest {
@override
String? get testPackageLanguageVersion => '2.14';

View file

@ -12,8 +12,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ArgumentTypeNotAssignableTest);
defineReflectiveTests(
ArgumentTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(ArgumentTypeNotAssignableWithoutNullSafetyTest);
defineReflectiveTests(ArgumentTypeNotAssignableWithStrictCastsTest);
});
@ -720,31 +718,6 @@ g(C c) {
}
}
@reflectiveTest
class ArgumentTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_functionCall() async {
await assertErrorsWithNoImplicitCasts(r'''
int f(int i) => i;
num n = 0;
var v = f(n);
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 40, 1),
]);
}
test_operator() async {
await assertErrorsWithNoImplicitCasts(r'''
num n = 0;
int i = 0;
var v = i & n;
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 34, 1),
]);
}
}
@reflectiveTest
class ArgumentTypeNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(FieldInitializerNotAssignableTest);
defineReflectiveTests(
FieldInitializerNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(FieldInitializerNotAssignableWithStrictCastsTest);
});
}
@ -54,22 +52,6 @@ class A {
}
}
@reflectiveTest
class FieldInitializerNotAssignableWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_constructorInitializer() async {
await assertErrorsWithNoImplicitCasts('''
class A {
int i;
A(num n) : i = n;
}
''', [
error(CompileTimeErrorCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, 36, 1),
]);
}
}
@reflectiveTest
class FieldInitializerNotAssignableWithStrictCastsTest
extends PubPackageResolutionTest with WithStrictCastsMixin {

View file

@ -1,120 +0,0 @@
// Copyright (c) 2021, 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:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ImplicitDynamicFieldTest);
defineReflectiveTests(ImplicitDynamicFieldWithoutNullSafetyTest);
});
}
@reflectiveTest
class ImplicitDynamicFieldTest extends PubPackageResolutionTest
with ImplicitDynamicFieldTestCases {}
mixin ImplicitDynamicFieldTestCases on PubPackageResolutionTest {
@override
void setUp() {
super.setUp();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(implicitDynamic: false),
);
}
test_instance_explicitDynamic_initialized() async {
await assertNoErrorsInCode('''
class C {
dynamic f = (<dynamic>[])[0];
}
''');
}
test_instance_explicitDynamic_uninitialized() async {
await assertNoErrorsInCode('''
class C {
dynamic f;
}
''');
}
test_instance_final_initialized() async {
await assertErrorsInCode('''
class C {
final f = (<dynamic>[])[0];
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 18, 20,
messageContains: ["'f'"]),
]);
}
test_instance_final_uninitialized() async {
await assertErrorsInCode('''
class C {
final f;
C(this.f);
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 18, 1),
]);
}
test_instance_var_initialized() async {
await assertErrorsInCode('''
class C {
var f = (<dynamic>[])[0];
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 16, 20),
]);
}
test_instance_var_initialized_inference() async {
await assertNoErrorsInCode('''
class C {
var f = 0;
}
''');
}
test_instance_var_uninitialized() async {
await assertErrorsInCode('''
class C {
var f;
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 16, 1),
]);
}
test_instance_var_uninitialized_multiple() async {
await assertErrorsInCode('''
class C {
var f, g = 42, h;
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 16, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 27, 1),
]);
}
test_static_var_initialized() async {
await assertErrorsInCode('''
class C {
static var f = (<dynamic>[])[0];
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 23, 20),
]);
}
}
@reflectiveTest
class ImplicitDynamicFieldWithoutNullSafetyTest extends PubPackageResolutionTest
with ImplicitDynamicFieldTestCases, WithoutNullSafetyMixin {}

View file

@ -1,142 +0,0 @@
// Copyright (c) 2021, 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:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ImplicitDynamicFunctionTest);
defineReflectiveTests(ImplicitDynamicFunctionWithoutNullSafetyTest);
});
}
@reflectiveTest
class ImplicitDynamicFunctionTest extends PubPackageResolutionTest
with ImplicitDynamicFunctionTestCases {}
mixin ImplicitDynamicFunctionTestCases on PubPackageResolutionTest {
@override
void setUp() {
super.setUp();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(implicitDynamic: false),
);
}
test_local_downwardInferenceGivesInt() async {
await assertNoErrorsInCode('''
void f(int d) {
T g<T>() => throw 'x';
d = g();
}
''');
}
test_local_noDownwardsInference() async {
await assertErrorsInCode('''
void f(dynamic d) {
T a<T>() => throw 'x';
d = a();
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FUNCTION, 51, 1),
]);
}
test_local_noInference() async {
await assertErrorsInCode('''
void f(dynamic d) {
void a<T>() {};
a();
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FUNCTION, 40, 1),
]);
}
test_local_upwardsInferenceGivesDynamic() async {
await assertErrorsInCode('''
void f(dynamic d) {
void a<T>(T t) {};
a(d);
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FUNCTION, 43, 1),
]);
}
test_local_upwardsInferenceGivesInt() async {
await assertNoErrorsInCode('''
void f() {
void a<T>(T t) {};
a(42);
}
''');
}
test_topLevel_downwardInferenceGivesDynamic() async {
await assertErrorsInCode('''
external T a<T>();
void f(dynamic d) {
d = a();
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FUNCTION, 46, 1),
]);
}
test_topLevel_downwardInferenceGivesInt() async {
await assertNoErrorsInCode('''
external T a<T>();
void f(int d) {
d = a();
}
''');
}
test_topLevel_dynamicAssignmentToTypeVariable() async {
await assertErrorsInCode('''
T a<T>(T t) => t;
void f(dynamic d) {
a(d);
a(42);
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FUNCTION, 41, 1),
]);
}
test_topLevel_intAssignmentToTypeVariable() async {
await assertNoErrorsInCode('''
T a<T>(T t) => t;
void f() {
a(42);
}
''');
}
test_topLevel_noInference() async {
await assertErrorsInCode('''
void a<T>() {}
void f() {
a();
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_FUNCTION, 29, 1),
]);
}
}
@reflectiveTest
class ImplicitDynamicFunctionWithoutNullSafetyTest
extends PubPackageResolutionTest
with ImplicitDynamicFunctionTestCases, WithoutNullSafetyMixin {}

View file

@ -1,92 +0,0 @@
// Copyright (c) 2021, 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:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ImplicitDynamicListLiteralTest);
defineReflectiveTests(ImplicitDynamicListLiteralWithoutNullSafetyTest);
});
}
@reflectiveTest
class ImplicitDynamicListLiteralTest extends PubPackageResolutionTest
with ImplicitDynamicListLiteralTestCases {}
mixin ImplicitDynamicListLiteralTestCases on PubPackageResolutionTest {
@override
void setUp() {
super.setUp();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(implicitDynamic: false),
);
}
test_assignedToListWithExplicitTypeArgument_dynamic() async {
await assertErrorsInCode('''
List<dynamic> a = [];
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 18, 2),
]);
}
test_assignedToListWithExplicitTypeArgument_int() async {
await assertNoErrorsInCode('''
List<int> a = [];
''');
}
test_assignedToRawList() async {
await assertErrorsInCode('''
List a = [];
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 9, 2),
]);
}
test_assignedToVar_empty() async {
await assertErrorsInCode('''
var a = [];
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 8, 2),
]);
}
test_assignedToVar_nonDynamicElements() async {
await assertNoErrorsInCode('''
var a = [42];
''');
}
test_dynamicElements() async {
await assertErrorsInCode('''
void f(dynamic d) {
[d, d];
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL, 22, 6),
]);
}
test_explicitTypeArgument_dynamic() async {
await assertNoErrorsInCode('''
var a = <dynamic>[];
''');
}
test_explicitTypeArgument_int() async {
await assertNoErrorsInCode('''
var a = <int>[];
''');
}
}
@reflectiveTest
class ImplicitDynamicListLiteralWithoutNullSafetyTest
extends PubPackageResolutionTest
with ImplicitDynamicListLiteralTestCases, WithoutNullSafetyMixin {}

View file

@ -1,100 +0,0 @@
// Copyright (c) 2021, 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:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ImplicitDynamicMapLiteralTest);
defineReflectiveTests(ImplicitDynamicMapLiteralWithoutNullSafetyTest);
});
}
@reflectiveTest
class ImplicitDynamicMapLiteralTest extends PubPackageResolutionTest
with ImplicitDynamicMapLiteralTestCases {}
mixin ImplicitDynamicMapLiteralTestCases on PubPackageResolutionTest {
@override
void setUp() {
super.setUp();
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(implicitDynamic: false),
);
}
test_assignedToMapWithExplicitTypeArguments_dynamic() async {
await assertErrorsInCode('''
Map<dynamic, dynamic> a = {};
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 26, 2),
]);
}
test_assignedToMapWithExplicitTypeArguments_int() async {
await assertNoErrorsInCode('''
Map<int, int> a = {};
''');
}
test_assignedToRawMap() async {
await assertErrorsInCode('''
Map a = {};
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 8, 2),
]);
}
test_assignedToVar_empty() async {
await assertErrorsInCode('''
var a = {};
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 8, 2),
]);
}
test_assignedToVar_nonDynamicElements() async {
await assertNoErrorsInCode('''
var a = {0: 1};
''');
}
test_dynamicKey() async {
await assertErrorsInCode('''
dynamic d = 1;
var a = {d: 'x'};
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 23, 8),
]);
}
test_dynamicValue() async {
await assertErrorsInCode('''
dynamic d = 1;
var a = {'x': d};
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL, 23, 8),
]);
}
test_explicitTypeArguments_dynamic() async {
await assertNoErrorsInCode('''
var a = <dynamic, dynamic>{};
''');
}
test_explicitTypeArguments_int() async {
await assertNoErrorsInCode('''
var a = <int, int>{};
''');
}
}
@reflectiveTest
class ImplicitDynamicMapLiteralWithoutNullSafetyTest
extends PubPackageResolutionTest
with ImplicitDynamicMapLiteralTestCases, WithoutNullSafetyMixin {}

View file

@ -11,8 +11,6 @@ main() {
defineReflectiveSuite(() {
defineReflectiveTests(InvalidAssignment_ImplicitCallReferenceTest);
defineReflectiveTests(InvalidAssignmentTest);
defineReflectiveTests(
InvalidAssignmentWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(InvalidAssignmentWithoutNullSafetyTest);
defineReflectiveTests(InvalidAssignmentWithStrictCastsTest);
});
@ -1023,76 +1021,6 @@ main() {
}
}
@reflectiveTest
class InvalidAssignmentWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_assignment() async {
await assertErrorsWithNoImplicitCasts('''
void f(num n, int i) {
i = n;
}
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 29, 1),
]);
}
test_compoundAssignment() async {
await assertErrorsWithNoImplicitCasts('''
void f(num n, int i) {
i += n;
}
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 30, 1),
]);
}
@failingTest
test_list_spread_dynamic() async {
// TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
await assertErrorsWithNoImplicitCasts(r'''
void f(dynamic a) {
[...a];
}
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 26, 1),
]);
}
@failingTest
test_map_spread_dynamic() async {
// TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
await assertErrorsWithNoImplicitCasts(r'''
void f(dynamic a) {
<dynamic, dynamic>{...a};
}
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 44, 1),
]);
}
test_numericOps() async {
// Regression test for https://github.com/dart-lang/sdk/issues/26912
await assertNoErrorsWithNoImplicitCasts('''
void f(int x, int y) {
x += y;
}
''');
}
@failingTest
test_set_spread_dynamic() async {
// TODO(mfairhurst) fix this, see https://github.com/dart-lang/sdk/issues/36267
await assertErrorsWithNoImplicitCasts(r'''
void f(dynamic a) {
<dynamic>{...a};
}
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 35, 1),
]);
}
}
@reflectiveTest
class InvalidAssignmentWithoutNullSafetyTest extends PubPackageResolutionTest
with InvalidAssignmentTestCases, WithoutNullSafetyMixin {

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ListElementTypeNotAssignableTest);
defineReflectiveTests(
ListElementTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(ListElementTypeNotAssignableWithoutNullSafetyTest);
defineReflectiveTests(ListElementTypeNotAssignableWithStrictCastsTest);
});
@ -234,61 +232,6 @@ var v = <void>[42];
}
}
@reflectiveTest
class ListElementTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_ifElement_falseBranch_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int>[if (c) 0 else a];
}
''', [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 50, 1),
]);
}
test_ifElement_falseBranch_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int>[if (c) 0 else a];
}
''', [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 46, 1),
]);
}
test_ifElement_trueBranch_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int>[if (c) a];
}
''', [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 43, 1),
]);
}
test_ifElement_trueBranch_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int>[if (c) a];
}
''', [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 39, 1),
]);
}
test_spread_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(Iterable<num> a) {
<int>[...a];
}
''', [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 37, 1),
]);
}
}
@reflectiveTest
class ListElementTypeNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MapKeyTypeNotAssignableTest);
defineReflectiveTests(
MapKeyTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(MapKeyTypeNotAssignableWithoutNullSafetyTest);
defineReflectiveTests(MapKeyTypeNotAssignableWithStrictCastsTest);
});
@ -239,61 +237,6 @@ var v = <int, String>{...{a: 'a'}};
}
}
@reflectiveTest
class MapKeyTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_ifElement_falseBranch_key_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int, int>{if (c) 0: 0 else a: 0};
}
''', [
error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 58, 1),
]);
}
test_ifElement_falseBranch_key_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int, int>{if (c) 0: 0 else a: 0};
}
''', [
error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 54, 1),
]);
}
test_ifElement_trueBranch_key_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int, int>{if (c) a: 0 };
}
''', [
error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 48, 1),
]);
}
test_ifElement_trueBranch_key_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int, int>{if (c) a: 0};
}
''', [
error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 44, 1),
]);
}
test_spread_key_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(Map<num, dynamic> a) {
<int, dynamic>{...a};
}
''', [
error(CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, 50, 1),
]);
}
}
@reflectiveTest
class MapKeyTypeNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MapValueTypeNotAssignableTest);
defineReflectiveTests(
MapValueTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(MapValueTypeNotAssignableWithoutNullSafetyTest);
defineReflectiveTests(MapValueTypeNotAssignableWithStrictCastsTest);
});
@ -233,61 +231,6 @@ var v = <bool, int>{...{true: a}};
}
}
@reflectiveTest
class MapValueTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_ifElement_falseBranch_value_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int, int>{if (c) 0: 0 else 0: a};
}
''', [
error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 61, 1),
]);
}
test_ifElement_falseBranch_value_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int, int>{if (c) 0: 0 else 0: a};
}
''', [
error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 57, 1),
]);
}
test_ifElement_trueBranch_value_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int, int>{if (c) 0: a};
}
''', [
error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 51, 1),
]);
}
test_ifElement_trueBranch_value_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int, int>{if (c) 0: a};
}
''', [
error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 47, 1),
]);
}
test_spread_value_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(Map<dynamic, num> a) {
<dynamic, int>{...a};
}
''', [
error(CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, 50, 1),
]);
}
}
@reflectiveTest
class MapValueTypeNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NonBoolConditionWithoutNullSafetyTest);
defineReflectiveTests(
NonBoolConditionWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(NonBoolConditionTest);
defineReflectiveTests(NonBoolConditionWithStrictCastsTest);
});
@ -85,51 +83,6 @@ void f(Null a) {
}
}
@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 {

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ReturnOfInvalidTypeTest);
defineReflectiveTests(
ReturnOfInvalidTypeWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(ReturnOfInvalidTypeWithoutNullSafetyTest);
defineReflectiveTests(ReturnOfInvalidTypeWithStrictCastsTest);
});
@ -566,28 +564,6 @@ Map<int, int> f() => {...[1, 2, 3, 4]};
}
}
@reflectiveTest
class ReturnOfInvalidTypeWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_return() async {
await assertErrorsWithNoImplicitCasts('int f(num n) => n;', [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 16, 1),
]);
}
test_return_async() async {
await assertErrorsWithNoImplicitCasts(r'''
Future<List<String>> f() async {
List<Object> x = <Object>['hello', 'world'];
return x;
}
''', [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 89, 1),
]);
}
}
@reflectiveTest
class ReturnOfInvalidTypeWithoutNullSafetyTest extends PubPackageResolutionTest
with ReturnOfInvalidTypeTestCases, WithoutNullSafetyMixin {}

View file

@ -10,8 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(SetElementTypeNotAssignableTest);
defineReflectiveTests(
SetElementTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(SetElementTypeNotAssignableWithoutNullSafetyTest);
defineReflectiveTests(SetElementTypeNotAssignableWithStrictCastsTest);
});
@ -199,61 +197,6 @@ var v = <int>{'abc'};
}
}
@reflectiveTest
class SetElementTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, WithNoImplicitCastsMixin {
test_ifElement_falseBranch_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int>{if (c) 0 else a};
}
''', [
error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 50, 1),
]);
}
test_ifElement_falseBranch_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int>{if (c) 0 else a};
}
''', [
error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 46, 1),
]);
}
test_ifElement_trueBranch_dynamic() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, dynamic a) {
<int>{if (c) a};
}
''', [
error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 43, 1),
]);
}
test_ifElement_trueBranch_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(bool c, num a) {
<int>{if (c) a};
}
''', [
error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 39, 1),
]);
}
test_spread_supertype() async {
await assertErrorsWithNoImplicitCasts(r'''
void f(Iterable<num> a) {
<int>{...a};
}
''', [
error(CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE, 37, 1),
]);
}
}
@reflectiveTest
class SetElementTypeNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest

View file

@ -340,11 +340,6 @@ import 'implements_repeated_test.dart' as implements_repeated;
import 'implements_super_class_test.dart' as implements_super_class;
import 'implements_type_alias_expands_to_type_parameter_test.dart'
as implements_type_alias_expands_to_type_parameter;
import 'implicit_dynamic_field_test.dart' as implicit_dynamic_field;
import 'implicit_dynamic_function_test.dart' as implicit_dynamic_function;
import 'implicit_dynamic_list_literal_test.dart'
as implicit_dynamic_list_literal;
import 'implicit_dynamic_map_literal_test.dart' as implicit_dynamic_map_literal;
import 'implicit_this_reference_in_initializer_test.dart'
as implicit_this_reference_in_initializer;
import 'import_deferred_library_with_load_function_test.dart'
@ -1118,10 +1113,6 @@ main() {
implements_repeated.main();
implements_super_class.main();
implements_type_alias_expands_to_type_parameter.main();
implicit_dynamic_field.main();
implicit_dynamic_function.main();
implicit_dynamic_list_literal.main();
implicit_dynamic_map_literal.main();
implicit_this_reference_in_initializer.main();
import_deferred_library_with_load_function.main();
import_internal_library.main();

View file

@ -101,7 +101,7 @@ class OptionsRuleValidatorTest
linter:
rules:
- deprecated_lint_with_replacement
''', [DEPRECATED_LINT_HINT_WITH_REPLACEMENT]);
''', [AnalysisOptionsHintCode.DEPRECATED_LINT_WITH_REPLACEMENT]);
}
test_deprecated_rule_map() {
@ -109,7 +109,7 @@ linter:
linter:
rules:
deprecated_lint: false
''', [DEPRECATED_LINT_HINT]);
''', [AnalysisOptionsHintCode.DEPRECATED_LINT]);
}
test_deprecated_rule_withReplacement() {
@ -117,7 +117,7 @@ linter:
linter:
rules:
- deprecated_lint
''', [DEPRECATED_LINT_HINT]);
''', [AnalysisOptionsHintCode.DEPRECATED_LINT]);
}
test_deprecated_rule_withSince_inCurrentSdk() {
@ -127,7 +127,7 @@ linter:
rules:
- deprecated_since_3_lint
''',
[DEPRECATED_LINT_HINT],
[AnalysisOptionsHintCode.DEPRECATED_LINT],
sdk: dart3,
);
}
@ -163,7 +163,7 @@ linter:
rules:
- stable_lint
- stable_lint
''', [DUPLICATE_RULE_HINT]);
''', [AnalysisOptionsHintCode.DUPLICATE_RULE]);
}
test_incompatible_rule() {
@ -172,7 +172,7 @@ linter:
rules:
- rule_pos
- rule_neg
''', [INCOMPATIBLE_LINT_WARNING]);
''', [AnalysisOptionsWarningCode.INCOMPATIBLE_LINT]);
}
test_incompatible_rule_map() {
@ -181,7 +181,7 @@ linter:
rules:
rule_pos: true
rule_neg: true
''', [INCOMPATIBLE_LINT_WARNING]);
''', [AnalysisOptionsWarningCode.INCOMPATIBLE_LINT]);
}
test_incompatible_rule_map_disabled() {
@ -250,7 +250,7 @@ linter:
linter:
rules:
- this_rule_does_not_exist
''', [UNDEFINED_LINT_WARNING]);
''', [AnalysisOptionsWarningCode.UNDEFINED_LINT]);
}
test_undefined_rule_map() {
@ -258,7 +258,7 @@ linter:
linter:
rules:
this_rule_does_not_exist: false
''', [UNDEFINED_LINT_WARNING]);
''', [AnalysisOptionsWarningCode.UNDEFINED_LINT]);
}
}

View file

@ -252,68 +252,6 @@ analyzer:
''', []);
}
test_analyzer_strong_mode_deprecated() {
validate('''
analyzer:
strong-mode: true
''', [AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED]);
}
test_analyzer_strong_mode_deprecated_key() {
validate('''
analyzer:
strong-mode:
declaration-casts: false
''', [AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED]);
}
test_analyzer_strong_mode_deprecated_key_implicit_casts() {
validate('''
analyzer:
strong-mode:
implicit-casts: false
''', [AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT]);
}
test_analyzer_strong_mode_deprecated_key_implicit_dynamic() {
validate('''
analyzer:
strong-mode:
implicit-dynamic: false
''', [AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT]);
}
test_analyzer_strong_mode_error_code_supported() {
validate('''
analyzer:
errors:
invalid_cast_method: ignore
''', []);
}
test_analyzer_strong_mode_false_removed() {
validate('''
analyzer:
strong-mode: false
''', [AnalysisOptionsWarningCode.SPEC_MODE_REMOVED]);
}
test_analyzer_strong_mode_notAMap() {
validate('''
analyzer:
strong-mode:
- implicit_casts
''', [AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT]);
}
test_analyzer_strong_mode_unsupported_key() {
validate('''
analyzer:
strong-mode:
unsupported: true
''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]);
}
test_analyzer_supported_exclude() {
validate('''
analyzer:
@ -322,13 +260,6 @@ analyzer:
''', []);
}
test_analyzer_supported_strong_mode_supported_bad_value() {
validate('''
analyzer:
strong-mode: w00t
''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]);
}
test_analyzer_unsupported_option() {
validate('''
analyzer:

View file

@ -1605,217 +1605,6 @@ class H implements F {
]);
}
test_implicitDynamic_method() async {
_disableTestPackageImplicitDynamic();
await assertErrorsInCode(r'''
class C {
T m<T>(T s) => s;
T n<T>() => null;
}
class D<E> {
T m<T>(T s) => s;
T n<T>() => null;
}
void f() {
dynamic d;
int i;
new C().m(d);
new C().m(42);
new C().n();
d = new C().n();
i = new C().n();
new D<int>().m(d);
new D<int>().m(42);
new D<int>().n();
d = new D<int>().n();
i = new D<int>().n();
}
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 137, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_METHOD, 150, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_METHOD, 183, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_METHOD, 202, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_METHOD, 242, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_METHOD, 285, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_METHOD, 309, 1),
]);
}
test_implicitDynamic_parameter() async {
_disableTestPackageImplicitDynamic();
await assertErrorsInCode(r'''
const dynamic DYNAMIC_VALUE = 42;
// simple formal
void f0(x) {}
void f1(dynamic x) {}
// default formal
void df0([x = DYNAMIC_VALUE]) {}
void df1([dynamic x = DYNAMIC_VALUE]) {}
// https://github.com/dart-lang/sdk/issues/25794
void df2([x = 42]) {}
// default formal (named)
void nf0({x = DYNAMIC_VALUE}) {}
void nf1({dynamic x = DYNAMIC_VALUE}) {}
// https://github.com/dart-lang/sdk/issues/25794
void nf2({x = 42}) {}
// field formal
class C {
var x;
C(this.x);
}
// function typed formal
void ftf0(void x(y)) {}
void ftf1(void x(int y)) {}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_PARAMETER, 60, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_PARAMETER, 117, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_PARAMETER, 241, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_PARAMETER, 290, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_PARAMETER, 414, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_FIELD, 459, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_PARAMETER, 520, 1),
]);
}
test_implicitDynamic_return() async {
_disableTestPackageImplicitDynamic();
await assertErrorsInCode(r'''
// function
f0() {return f0();}
dynamic f1() { return 42; }
// nested function
void main() {
g0() {return g0();}
dynamic g1() { return 42; }
}
// methods
class B {
int m1() => 42;
}
class C extends B {
m0() => 123;
m1() => 123;
dynamic m2() => 'hi';
}
// accessors
set x(int value) {}
get y0 => 42;
dynamic get y1 => 42;
// function typed formals
void ftf0(f(int x)) {}
void ftf1(dynamic f(int x)) {}
// function expressions
var fe0 = (int x) => x as dynamic;
var fe1 = (int x) => x;
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_RETURN, 12, 2,
messageContains: ["'f0'"]),
error(LanguageCode.IMPLICIT_DYNAMIC_RETURN, 96, 2,
messageContains: ["'g0'"]),
error(WarningCode.UNUSED_ELEMENT, 96, 2),
error(WarningCode.UNUSED_ELEMENT, 126, 2),
error(LanguageCode.IMPLICIT_DYNAMIC_RETURN, 212, 2,
messageContains: ["'m0'"]),
error(LanguageCode.IMPLICIT_DYNAMIC_RETURN, 304, 2,
messageContains: ["'y0'"]),
error(LanguageCode.IMPLICIT_DYNAMIC_RETURN, 373, 1,
messageContains: ["'f'"]),
]);
}
test_implicitDynamic_static() async {
_disableTestPackageImplicitDynamic();
await assertNoErrorsInCode(r'''
class C {
static void test(int body()) {}
}
void main() {
C.test(() {
return 42;
});
}
''');
}
test_implicitDynamic_type() async {
_disableTestPackageImplicitDynamic();
await assertErrorsInCode(r'''
class C<T> {}
class M1<T extends List> {}
class M2<T> {}
class I<T> {}
class D<T, S> extends C
with M1, M2
implements I {}
class D2<T, S> = C
with M1, M2
implements I;
C f(D d) {
D x = new D();
D<int, dynamic> y = new D();
D<dynamic, int> z = new D();
return new C();
}
class A<T extends num> {}
class N1<T extends List<int>> {}
class N2<T extends Object> {}
class J<T extends Object> {}
class B<T extends Object> extends A with N1, N2 implements J {}
A g(B b) {
B y = new B();
return new A();
}
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 33, 4),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 93, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 108, 2),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 126, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 148, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 163, 2),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 181, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 200, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 208, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 231, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 239, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 262, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 270, 1),
error(LanguageCode.IMPLICIT_DYNAMIC_TYPE, 288, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 493, 1),
]);
}
test_implicitDynamic_variable() async {
_disableTestPackageImplicitDynamic();
await assertErrorsInCode(r'''
var x0;
var x1 = (<dynamic>[])[0];
var x2, x3 = 42, x4;
dynamic y0;
dynamic y1 = (<dynamic>[])[0];
''', [
error(LanguageCode.IMPLICIT_DYNAMIC_VARIABLE, 4, 2),
error(LanguageCode.IMPLICIT_DYNAMIC_VARIABLE, 12, 21),
error(LanguageCode.IMPLICIT_DYNAMIC_VARIABLE, 39, 2),
error(LanguageCode.IMPLICIT_DYNAMIC_VARIABLE, 52, 2),
]);
}
test_interfaceOverridesAreAllChecked() {
// Regression test for https://github.com/dart-lang/sdk/issues/29766
return assertErrorsInCode(r'''
@ -3278,12 +3067,4 @@ void main () {
error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 58, 3),
]);
}
void _disableTestPackageImplicitDynamic() {
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(
implicitDynamic: false,
),
);
}
}

View file

@ -34,10 +34,6 @@ const List<ErrorClassInfo> errorClasses = [
superclass: 'AnalyzerErrorCode',
type: 'COMPILE_TIME_ERROR',
extraImports: ['package:analyzer/src/error/analyzer_error_code.dart']),
ErrorClassInfo(
filePath: 'lib/src/error/codes.g.dart',
name: 'LanguageCode',
type: 'COMPILE_TIME_ERROR'),
ErrorClassInfo(
filePath: 'lib/src/error/codes.g.dart',
name: 'StaticWarningCode',

View file

@ -321,7 +321,6 @@ class FixBuilder {
// TODO(paulberry): do we need to test both possible values of
// strictInference?
return TypeSystemImpl(
implicitCasts: typeSystem.implicitCasts,
isNonNullableByDefault: true,
strictCasts: typeSystem.strictCasts,
strictInference: typeSystem.strictInference,

View file

@ -69,7 +69,6 @@ class AssignmentCheckerTest extends Object
var decoratedClassHierarchy = _DecoratedClassHierarchyForTesting();
var checker = AssignmentCheckerForTesting(
TypeSystemImpl(
implicitCasts: true,
isNonNullableByDefault: false,
strictCasts: false,
strictInference: false,
@ -500,7 +499,6 @@ class AssignmentCheckerTest extends Object
static void _setCoreLibrariesTypeSystem(TypeProviderImpl typeProvider) {
var typeSystem = TypeSystemImpl(
isNonNullableByDefault: false,
implicitCasts: true,
strictCasts: false,
strictInference: false,
typeProvider: typeProvider,

View file

@ -641,9 +641,6 @@ int? y = 0;
projectContents['example/$filePath'] = subProject[filePath];
}
projectContents['example/analysis_options.yaml'] = '''
analyzer:
strong-mode:
implicit-casts: false
linter:
rules:
- empty_constructor_bodies