Remove all support for all 'strong-mode' analysis options

Fixes https://github.com/dart-lang/sdk/issues/50679

Change-Id: I3572faf51276f5c7551d35b7725c799567189413
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274921
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2022-12-13 21:32:24 +00:00 committed by Commit Queue
parent 1b624249c2
commit ea120b5d44
50 changed files with 34 additions and 1851 deletions

View file

@ -56,6 +56,15 @@
[`MAX_USER_TAGS`]: https://api.dart.dev/stable/dart-developer/UserTag/MAX_USER_TAGS-constant.html
[`maxUserTags`]: https://api.dart.dev/beta/2.19.0-255.2.beta/dart-developer/UserTag/maxUserTags-constant.html
### Tools
#### Analyzer
- Remove deprecated 'strong-mode' analysis options from `analysis_options.yaml`
files. These options are replaced by the supported "strict" options
documented at
[dart.dev](https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks).
## 2.19.0
### Language

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

@ -43,9 +43,6 @@ AnalysisOptionsErrorCode.PARSE_ERROR:
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED:
status: needsFix
notes: Fixed.
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED:
status: needsFix
notes: Fixed.
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND:
status: noFix
notes: |-
@ -66,10 +63,6 @@ AnalysisOptionsWarningCode.INVALID_OPTION:
replace the invalid option with the selected replacement.
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT:
status: needsEvaluation
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED:
status: needsFix
notes: |-
Provide a fix to remove the deprecated setting.
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE:
status: needsEvaluation
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE:
@ -1714,56 +1707,6 @@ HintCode.UNUSED_RESULT_WITH_MESSAGE:
There is no predictable common way in which a result _should_ be used.
HintCode.UNUSED_SHOWN_NAME:
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

@ -65,9 +65,6 @@ class AnalysisOptionsFixGenerator {
if (errorCode ==
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED) {
await _addFix_removeSetting(coveringNodePath);
} else if (errorCode ==
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED) {
await _addFix_removeSetting(coveringNodePath);
} else if (errorCode == DEPRECATED_LINT_HINT) {
await _addFix_removeLint(coveringNodePath);
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING) {

View file

@ -452,8 +452,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

@ -105,12 +105,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:');
}
@ -121,11 +120,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

@ -27,8 +27,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;
@ -36,8 +34,6 @@ class AnalysisOptionsFileConfig {
AnalysisOptionsFileConfig({
this.experiments = const [],
this.implicitCasts = true,
this.implicitDynamic = true,
this.lints = const [],
this.strictCasts = false,
this.strictInference = false,
@ -58,9 +54,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('linter:');
buffer.writeln(' rules:');

View file

@ -359,13 +359,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:');
}
@ -383,11 +382,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

@ -69,7 +69,7 @@ class FlutterNotificationOutlineTest extends PubPackageAnalysisServerTest {
);
newAnalysisOptionsYamlFile(testPackageRootPath, '''
analyzer:
strong-mode: true
language: true
''');
await pumpEventQueue();
await server.onAnalysisComplete;

View file

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

View file

@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@ -119,16 +118,4 @@ f() {
}
''');
}
Future<void> test_synthetic_implicitCast() async {
createAnalysisOptionsFile(implicitCasts: false);
await resolveTestCode('''
int foo =
''');
await assertNoFix(
errorFilter: (e) {
return e.errorCode == CompileTimeErrorCode.INVALID_ASSIGNMENT;
},
);
}
}

View file

@ -68,15 +68,6 @@ class AnalysisOptionsHintCode extends ErrorCode {
correctionMessage: "It is no longer necessary to explicitly enable Dart 2.",
);
/// An error code indicating that strong-mode: true is deprecated.
static const AnalysisOptionsHintCode STRONG_MODE_SETTING_DEPRECATED =
AnalysisOptionsHintCode(
'STRONG_MODE_SETTING_DEPRECATED',
"The 'strong-mode: true' setting is deprecated.",
correctionMessage:
"It is no longer necessary to explicitly enable strong mode.",
);
/// Initialize a newly created error code to have the given [name].
const AnalysisOptionsHintCode(
String name,
@ -146,16 +137,6 @@ class AnalysisOptionsWarningCode extends ErrorCode {
"Invalid format for the '{0}' section.",
);
/// An error code indicating that strong-mode: false is has been removed.
static const AnalysisOptionsWarningCode SPEC_MODE_REMOVED =
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).",
);
/// An error code indicating that an unrecognized error code is being used to
/// specify an error filter.
///

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

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

View file

@ -55,11 +55,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].
@ -89,7 +84,6 @@ class TypeSystemImpl implements TypeSystem {
late final SubtypeHelper _subtypeHelper;
TypeSystemImpl({
required this.implicitCasts,
required this.isNonNullableByDefault,
required this.strictCasts,
required this.strictInference,
@ -686,10 +680,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;
}
@ -1638,11 +1631,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

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

View file

@ -5242,126 +5242,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

@ -23,12 +23,10 @@ const List<ErrorCode> errorCodeValues = [
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
AnalysisOptionsErrorCode.PARSE_ERROR,
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED,
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED,
AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING,
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
AnalysisOptionsWarningCode.INVALID_OPTION,
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED,
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITHOUT_VALUES,
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE,
@ -688,16 +686,6 @@ const List<ErrorCode> errorCodeValues = [
HintCode.UNUSED_RESULT,
HintCode.UNUSED_RESULT_WITH_MESSAGE,
HintCode.UNUSED_SHOWN_NAME,
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,62 +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.isDynamic)) {
// 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.isDynamic)) {
// 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

@ -197,22 +197,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;
@ -261,8 +245,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;
@ -319,8 +301,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

@ -768,7 +768,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);
@ -829,20 +828,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.isDynamic) {
errorReporter.reportErrorForToken(
LanguageCode.IMPLICIT_DYNAMIC_RETURN,
node.name,
[node.name.lexeme]);
}
}
super.visitFunctionTypedFormalParameter(node);
} finally {
_isInFunctionTypedFormalParameter = old;
@ -867,12 +852,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;
@ -921,7 +900,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
_checkForListConstructor(node, type);
}
_checkForImplicitDynamicType(namedType);
super.visitInstanceCreationExpression(node);
}
@ -972,7 +950,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_checkForExtensionDeclaresMemberOfObject(node);
_checkForTypeAnnotationDeferredClass(returnType);
_returnTypeVerifier.verifyReturnType(returnType);
_checkForImplicitDynamicReturn(node.name, node.declaredElement!);
_checkForWrongTypeParameterVarianceInMethod(node);
super.visitMethodDeclaration(node);
});
@ -1160,15 +1137,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_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);
}
@ -1319,7 +1287,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);
@ -1337,8 +1304,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;
@ -1377,12 +1342,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(
@ -1397,7 +1356,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
!_checkForImplementsClauseErrorCodes(implementsClause) &&
!_checkForAllMixinErrorCodes(withClause) &&
!_checkForNoGenerativeConstructorsInSuperclass(superclass)) {
_checkForImplicitDynamicType(superclass);
_checkForExtendsDeferredClass(superclass);
_checkForRepeatedType(implementsClause?.interfaces,
CompileTimeErrorCode.IMPLEMENTS_REPEATED);
@ -2854,61 +2812,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.isDynamic) {
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.isDynamic) {
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.isDynamic)) {
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

@ -129,16 +129,10 @@ class AnalyzerOptions {
static const String language = 'language';
static const String optionalChecks = 'optional-checks';
static const String plugins = 'plugins';
static const String strongMode = 'strong-mode';
// Optional checks options.
static const String chromeOsManifestChecks = 'chrome-os-manifest-checks';
// Strong mode options (see AnalysisOptionsImpl for documentation).
static const String declarationCasts = 'declaration-casts';
static const String implicitCasts = 'implicit-casts';
static const String implicitDynamic = 'implicit-dynamic';
// Language options (see AnalysisOptionsImpl for documentation).
static const String strictCasts = 'strict-casts';
static const String strictInference = 'strict-inference';
@ -171,14 +165,6 @@ class AnalyzerOptions {
optionalChecks,
plugins,
propagateLinterExceptions,
strongMode,
];
/// Supported `analyzer` strong-mode options.
static const List<String> strongModeOptions = [
declarationCasts, // deprecated
implicitCasts,
implicitDynamic,
];
/// Supported `analyzer` language options.
@ -208,7 +194,6 @@ class AnalyzerOptionsValidator extends CompositeValidator {
AnalyzerOptionsValidator()
: super([
TopLevelAnalyzerOptionsValidator(),
StrongModeOptionValueValidator(),
ErrorFilterOptionValidator(),
EnabledExperimentsValidator(),
LanguageOptionValidator(),
@ -622,64 +607,6 @@ class OptionsFileValidator {
}
}
/// Validates `analyzer` strong-mode value configuration options.
class StrongModeOptionValueValidator extends OptionsValidator {
final ErrorBuilder _builder = ErrorBuilder(AnalyzerOptions.strongModeOptions);
@override
void validate(ErrorReporter reporter, YamlMap options) {
var analyzer = options.valueAt(AnalyzerOptions.analyzer);
if (analyzer is YamlMap) {
var v = analyzer.valueAt(AnalyzerOptions.strongMode);
if (v is YamlScalar) {
var value = toLowerCase(v.value);
if (!AnalyzerOptions.trueOrFalse.contains(value)) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.UNSUPPORTED_VALUE, v.span, [
AnalyzerOptions.strongMode,
v.value,
AnalyzerOptions.trueOrFalseProposal
]);
} else if (value == 'false') {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED, v.span);
} else if (value == 'true') {
reporter.reportErrorForSpan(
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED, v.span);
}
} else if (v is YamlMap) {
v.nodes.forEach((k, v) {
String? key, value;
bool validKey = false;
if (k is YamlScalar) {
key = k.value?.toString();
if (!AnalyzerOptions.strongModeOptions.contains(key)) {
_builder.reportError(reporter, AnalyzerOptions.strongMode, k);
} else if (key != AnalyzerOptions.declarationCasts) {
// If we have a valid key, go on and check the value.
validKey = true;
}
}
if (validKey && v is YamlScalar) {
value = toLowerCase(v.value);
if (!AnalyzerOptions.trueOrFalse.contains(value)) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.UNSUPPORTED_VALUE,
v.span,
[key!, v.value, AnalyzerOptions.trueOrFalseProposal]);
}
}
});
} else if (v != null) {
reporter.reportErrorForSpan(
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
v.span,
[AnalyzerOptions.enableExperiment]);
}
}
}
}
/// Validates `analyzer` top-level options.
class TopLevelAnalyzerOptionsValidator extends TopLevelOptionValidator {
TopLevelAnalyzerOptionsValidator()
@ -730,10 +657,6 @@ class _OptionsProcessor {
}
var analyzer = optionMap.valueAt(AnalyzerOptions.analyzer);
if (analyzer is YamlMap) {
// Process strong mode option.
var strongMode = analyzer.valueAt(AnalyzerOptions.strongMode);
_applyStrongOptions(options, strongMode);
// Process filters.
var filters = analyzer.valueAt(AnalyzerOptions.errors);
_applyProcessors(options, filters);
@ -873,32 +796,6 @@ class _OptionsProcessor {
options.errorProcessors = config.processors;
}
void _applyStrongModeOption(
AnalysisOptionsImpl options, String? feature, Object value) {
var boolValue = toBool(value);
if (boolValue != null) {
if (feature == AnalyzerOptions.implicitCasts) {
options.implicitCasts = boolValue;
}
if (feature == AnalyzerOptions.implicitDynamic) {
options.implicitDynamic = boolValue;
}
if (feature == AnalyzerOptions.propagateLinterExceptions) {
options.propagateLinterExceptions = boolValue;
}
}
}
void _applyStrongOptions(AnalysisOptionsImpl options, YamlNode? config) {
if (config is YamlMap) {
config.nodes.forEach((k, v) {
if (k is YamlScalar && v is YamlScalar) {
_applyStrongModeOption(options, k.value?.toString(), v.value);
}
});
}
}
void _applyUnignorables(AnalysisOptionsImpl options, YamlNode? cannotIgnore) {
if (cannotIgnore is YamlList) {
var names = <String>{};

View file

@ -60,10 +60,6 @@ AnalysisOptionsHintCode:
comment: |-
An error code indicating that the enablePreviewDart2 setting is
deprecated.
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."
AnalysisOptionsWarningCode:
INCLUDED_FILE_WARNING:
problemMessage: "Warning in the included options file {0}({1}..{2}): {3}"
@ -100,10 +96,6 @@ AnalysisOptionsWarningCode:
Parameters:
0: the section name
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."
UNRECOGNIZED_ERROR_CODE:
problemMessage: "'{0}' isn't a recognized error code."
comment: |-
@ -22140,63 +22132,6 @@ HintCode:
var x = min(0, 1);
```
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

@ -70,7 +70,7 @@ linter:
test('test_bad_yaml (1)', () {
var src = '''
analyzer: # <= bang
strong-mode: true
language: true
''';
var optionsProvider = AnalysisOptionsProvider();
@ -81,7 +81,7 @@ strong-mode: true
test('test_bad_yaml (2)', () {
var src = '''
analyzer:
strong-mode:true # missing space (sdk/issues/24885)
language:true # missing space (sdk/issues/24885)
''';
var optionsProvider = AnalysisOptionsProvider();

View file

@ -62,14 +62,6 @@ analyzer:
expect(context.getProcessor(unused_local_variable), isNull);
expect(context.getProcessor(use_of_void_result), isNull);
});
test('does not upgrade other warnings to errors in strong mode', () {
context.configureOptions('''
analyzer:
strong-mode: true
''');
expect(context.getProcessor(unused_local_variable), isNull);
});
});
group('ErrorConfig', () {

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

@ -808,8 +808,8 @@ class FileResolverTest extends FileResolutionTest {
test_analysisOptions_default_fromPackageUri() async {
newFile('/workspace/dart/analysis_options/lib/default.yaml', r'''
analyzer:
strong-mode:
implicit-casts: false
language:
strict-casts: true
''');
await assertErrorsInCode(r'''
@ -823,8 +823,8 @@ int b = a;
test_analysisOptions_file_inPackage() async {
newAnalysisOptionsYamlFile('/workspace/dart/test', r'''
analyzer:
strong-mode:
implicit-casts: false
language:
strict-casts: true
''');
await assertErrorsInCode(r'''
@ -838,14 +838,14 @@ int b = a;
test_analysisOptions_file_inThirdParty() async {
newFile('/workspace/dart/analysis_options/lib/third_party.yaml', r'''
analyzer:
strong-mode:
implicit-casts: false
language:
strict-casts: true
''');
newAnalysisOptionsYamlFile('/workspace/third_party/dart/aaa', r'''
analyzer:
strong-mode:
implicit-casts: true
language:
strict-casts: false
''');
var aPath = convertPath('/workspace/third_party/dart/aaa/lib/a.dart');
@ -860,14 +860,14 @@ int b = a;
test_analysisOptions_file_inThirdPartyDartLang() async {
newFile('/workspace/dart/analysis_options/lib/third_party.yaml', r'''
analyzer:
strong-mode:
implicit-casts: false
language:
strict-casts: true
''');
newAnalysisOptionsYamlFile('/workspace/third_party/dart_lang/aaa', r'''
analyzer:
strong-mode:
implicit-casts: true
language:
strict-casts: false
''');
var aPath = convertPath('/workspace/third_party/dart_lang/aaa/lib/a.dart');
@ -2482,15 +2482,15 @@ int b = a;
newFile('/workspace/dart/aaa/BUILD', '');
newAnalysisOptionsYamlFile('/workspace/dart/aaa', r'''
analyzer:
strong-mode:
implicit-casts: false
language:
strict-casts: true
''');
newFile('/workspace/dart/bbb/BUILD', '');
newAnalysisOptionsYamlFile('/workspace/dart/bbb', r'''
analyzer:
strong-mode:
implicit-casts: true
language:
strict-casts: false
''');
// Implicit casts are disabled in 'aaa'.

View file

@ -41,8 +41,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;
@ -51,8 +49,6 @@ class AnalysisOptionsFileConfig {
AnalysisOptionsFileConfig({
this.experiments = const [],
this.implicitCasts = true,
this.implicitDynamic = true,
this.lints = const [],
this.strictCasts = false,
this.strictInference = false,
@ -72,9 +68,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');
@ -535,35 +528,6 @@ mixin WithLanguage218Mixin on PubPackageResolutionTest {
String? get testPackageLanguageVersion => '2.18';
}
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

@ -11,8 +11,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ArgumentTypeNotAssignableTest);
defineReflectiveTests(
ArgumentTypeNotAssignableWithoutNullSafetyAndNoImplicitCastsTest);
defineReflectiveTests(ArgumentTypeNotAssignableWithoutNullSafetyTest);
defineReflectiveTests(ArgumentTypeNotAssignableWithStrictCastsTest);
});
@ -826,31 +824,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);
});
}
@ -68,22 +66,6 @@ enum E {
}
}
@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);
});
@ -40,51 +38,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);
});
@ -556,28 +554,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

@ -296,11 +296,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'
@ -1021,10 +1016,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

@ -445,52 +445,6 @@ analyzer:
''', []);
}
test_analyzer_strong_mode_deprecated() {
validate('''
analyzer:
strong-mode: true
''', [AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED]);
}
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_strong_mode_unsupported_value() {
validate('''
analyzer:
strong-mode:
implicit-dynamic: foo
''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]);
}
test_analyzer_supported_exclude() {
validate('''
analyzer:
@ -499,13 +453,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

@ -1795,217 +1795,6 @@ main() {
]);
}
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(HintCode.UNUSED_ELEMENT, 96, 2),
error(HintCode.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'''
@ -3468,12 +3257,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

@ -323,7 +323,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

@ -68,7 +68,6 @@ class AssignmentCheckerTest extends Object
var decoratedClassHierarchy = _DecoratedClassHierarchyForTesting();
var checker = AssignmentCheckerForTesting(
TypeSystemImpl(
implicitCasts: true,
isNonNullableByDefault: false,
strictCasts: false,
strictInference: false,
@ -499,7 +498,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

@ -637,9 +637,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