diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart index a2fe59310c9..3af81c417db 100644 --- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart +++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart @@ -223,7 +223,7 @@ class DartUnitHighlightsComputer { var element = node.writeOrReadElement; if (element is LocalVariableElement) { var elementType = element.type; - if (elementType.isDynamic) { + if (elementType is DynamicType) { var type = node.inDeclarationContext() ? HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_DECLARATION : HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE; @@ -232,7 +232,7 @@ class DartUnitHighlightsComputer { } if (element is ParameterElement) { var elementType = element.type; - if (elementType.isDynamic) { + if (elementType is DynamicType) { var type = node.inDeclarationContext() ? HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION : HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE; @@ -601,7 +601,7 @@ class DartUnitHighlightsComputer { static bool _isDynamicExpression(Expression e) { var type = e.staticType; - return type != null && type.isDynamic; + return type != null && type is DynamicType; } } @@ -1162,7 +1162,7 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor { void visitNamedType(NamedType node) { var type = node.type; if (type != null) { - var isDynamic = type.isDynamic && node.name2.lexeme == 'dynamic'; + var isDynamic = type is DynamicType && node.name2.lexeme == 'dynamic'; var isNever = type is NeverType; if (isDynamic || isNever) { computer._addRegion_token( diff --git a/pkg/analysis_server/lib/src/computer/computer_hover.dart b/pkg/analysis_server/lib/src/computer/computer_hover.dart index 54ae90dba00..0ff13df36a2 100644 --- a/pkg/analysis_server/lib/src/computer/computer_hover.dart +++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart @@ -173,7 +173,7 @@ class DartUnitHoverComputer { staticType = element.type; } else if (parent is MethodInvocation && parent.methodName == node) { staticType = parent.staticInvokeType; - if (staticType != null && staticType.isDynamic) { + if (staticType != null && staticType is DynamicType) { staticType = null; } } else if (node is PatternFieldName && parent is PatternField) { diff --git a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart index b9cfc08f34a..8ebf5801378 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart @@ -166,7 +166,7 @@ class FeatureComputer { final contextType = node.accept( _ContextTypeVisitor(typeProvider, offset), ); - if (contextType == null || contextType.isDynamic) { + if (contextType == null || contextType is DynamicType) { return null; } return typeSystem.resolveToBound(contextType); diff --git a/pkg/analysis_server/lib/src/services/completion/dart/type_member_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/type_member_contributor.dart index 2b7a32b28a5..d5d440c805d 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/type_member_contributor.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/type_member_contributor.dart @@ -129,7 +129,7 @@ class TypeMemberContributor extends DartCompletionContributor { var type = expressionType != null ? request.libraryElement.typeSystem.resolveToBound(expressionType) : null; - if (type == null || type.isDynamic) { + if (type == null || type is DynamicType) { // If the expression does not provide a good type, then attempt to get a // better type from the element. if (expression is Identifier) { @@ -141,7 +141,7 @@ class TypeMemberContributor extends DartCompletionContributor { } else if (elem is LocalVariableElement) { type = elem.type; } - if ((type == null || type.isDynamic) && + if ((type == null || type is DynamicType) && expression is SimpleIdentifier) { // If the element does not provide a good type, then attempt to get a // better type from a local declaration. diff --git a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart index da264a16d89..295c6057ed0 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart @@ -211,7 +211,7 @@ String getRequestLineIndent(DartCompletionRequest request) { } String getTypeString(DartType type, {required bool withNullability}) { - if (type.isDynamic) { + if (type is DynamicType) { return ''; } else { return '${type.getDisplayString(withNullability: withNullability)} '; @@ -245,7 +245,7 @@ String? nameForType(SimpleIdentifier identifier, TypeAnnotation? declaredType) { } // If the type is unresolved, use the declared type. - if (type.isDynamic) { + if (type is DynamicType) { if (declaredType is NamedType) { return declaredType.qualifiedName; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart index 5c39b67b0f5..dc204f52b22 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart @@ -79,7 +79,7 @@ class AddDiagnosticPropertyReference extends CorrectionProducer { constructorId = 'TransformProperty'; } else { constructorId = 'DiagnosticsProperty'; - if (!type.isDynamic) { + if (type is! DynamicType) { typeArgs = [type]; } } @@ -94,7 +94,7 @@ class AddDiagnosticPropertyReference extends CorrectionProducer { builder.write('<'); builder.writeTypes(typeArgs); builder.write('>'); - } else if (type.isDynamic) { + } else if (type is DynamicType) { TypeAnnotation? declType; final decl = node.thisOrAncestorOfType(); if (decl != null) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart index 97e7e9480b6..ae412cbfe9d 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart @@ -67,9 +67,9 @@ class AddReturnType extends CorrectionProducer { final insertBeforeEntity_final = insertBeforeEntity; await builder.addDartFileEdit(file, (builder) { - if (returnType.isDynamic || builder.canWriteType(returnType)) { + if (returnType is DynamicType || builder.canWriteType(returnType)) { builder.addInsertion(insertBeforeEntity_final.offset, (builder) { - if (returnType.isDynamic) { + if (returnType is DynamicType) { builder.write('dynamic'); } else { builder.writeType(returnType); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_map_literal.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_map_literal.dart index 2946e196144..6c86e595226 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_map_literal.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_map_literal.dart @@ -58,8 +58,8 @@ class ConvertToMapLiteral extends CorrectionProducer { creation.thisOrAncestorOfType(); if (variableDeclarationList?.type == null) { staticTypeArguments = type.typeArguments; - if (staticTypeArguments.first.isDynamic && - staticTypeArguments.last.isDynamic) { + if (staticTypeArguments.first is DynamicType && + staticTypeArguments.last is DynamicType) { staticTypeArguments = null; } } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_normal_parameter.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_normal_parameter.dart index 2084c65193d..28eb6a87d64 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_normal_parameter.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_normal_parameter.dart @@ -5,6 +5,7 @@ import 'package:analysis_server/src/services/correction/assist.dart'; import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart'; import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer_plugin/utilities/assist/assist.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; import 'package:analyzer_plugin/utilities/range_factory.dart'; @@ -30,7 +31,7 @@ class ConvertToNormalParameter extends CorrectionProducer { await builder.addDartFileEdit(file, (builder) { // replace parameter - if (type.isDynamic) { + if (type is DynamicType) { builder.addSimpleReplacement(range.node(parameter), name); } else { builder.addReplacement(range.node(parameter), (builder) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_iterable.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_iterable.dart index 1c2b1779b40..4b8f77a6d69 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_iterable.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_iterable.dart @@ -5,6 +5,7 @@ import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart'; import 'package:analysis_server/src/services/correction/fix.dart'; import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; import 'package:analyzer_plugin/utilities/range_factory.dart'; @@ -27,7 +28,7 @@ class ReplaceReturnTypeIterable extends CorrectionProducer { return; } var type = typeAnnotation.type; - if (type == null || type.isDynamic || type.isDartCoreIterable) { + if (type == null || type is DynamicType || type.isDartCoreIterable) { return; } _typeArgument = utils.getNodeText(typeAnnotation); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_stream.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_stream.dart index bc38772be7d..6784c93ea06 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_stream.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_return_type_stream.dart @@ -5,6 +5,7 @@ import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart'; import 'package:analysis_server/src/services/correction/fix.dart'; import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; import 'package:analyzer_plugin/utilities/range_factory.dart'; @@ -27,7 +28,7 @@ class ReplaceReturnTypeStream extends CorrectionProducer { return; } var type = typeAnnotation.type; - if (type == null || type.isDynamic || type.isDartAsyncStream) { + if (type == null || type is DynamicType || type.isDartAsyncStream) { return; } _typeArgument = utils.getNodeText(typeAnnotation); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart index abb1a1044ee..111d0a29e88 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart @@ -6,6 +6,7 @@ import 'package:analysis_server/src/services/correction/assist.dart'; import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart'; import 'package:analysis_server/src/services/correction/fix.dart'; import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/dart/ast/extensions.dart'; import 'package:analyzer_plugin/utilities/assist/assist.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; @@ -124,7 +125,7 @@ class ReplaceWithVar extends CorrectionProducer { /// Return `true` if the type in the [node] can be replaced with `var`. bool _canConvertVariableDeclarationList(VariableDeclarationList node) { final staticType = node.type?.type; - if (staticType == null || staticType.isDynamic) { + if (staticType == null || staticType is DynamicType) { return false; } for (final child in node.variables) { @@ -147,7 +148,7 @@ class ReplaceWithVar extends CorrectionProducer { } else if (parent is ForEachPartsWithDeclaration) { var loopVariableType = parent.loopVariable.type; var staticType = loopVariableType?.type; - if (staticType == null || staticType.isDynamic) { + if (staticType == null || staticType is DynamicType) { return false; } final iterableType = parent.iterable.typeOrThrow; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/split_variable_declaration.dart b/pkg/analysis_server/lib/src/services/correction/dart/split_variable_declaration.dart index f2f5c81e0ad..454ed2ba827 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/split_variable_declaration.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/split_variable_declaration.dart @@ -6,6 +6,7 @@ import 'package:_fe_analyzer_shared/src/scanner/token.dart'; import 'package:analysis_server/src/services/correction/assist.dart'; import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart'; import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer_plugin/utilities/assist/assist.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; import 'package:analyzer_plugin/utilities/range_factory.dart'; @@ -53,7 +54,7 @@ class SplitVariableDeclaration extends CorrectionProducer { await builder.addDartFileEdit(file, (builder) { if (variableList.type == null) { final type = variable.declaredElement!.type; - if (!type.isDynamic && keyword != null) { + if (type is! DynamicType && keyword != null) { if (!builder.canWriteType(type)) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart index 96c8e57a80b..c027114cabc 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart @@ -544,7 +544,7 @@ class _MatcherBuilder { if (type != null) { if (type is InterfaceType) { return type.element.name; - } else if (type.isDynamic) { + } else if (type is DynamicType) { // The name is likely to be undefined. return target.name; } diff --git a/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart b/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart index 98f97215bde..9fdb95fe68d 100644 --- a/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart +++ b/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart @@ -58,7 +58,7 @@ List getVariableNameSuggestionsForExpression(DartType? expectedType, } } // use type - if (expectedType != null && !expectedType.isDynamic) { + if (expectedType != null && expectedType is! DynamicType) { if (expectedType.isDartCoreInt) { _addSingleCharacterName(excluded, res, 0x69); } else if (expectedType.isDartCoreDouble) { diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart index f1b1476f093..a3c424e2f26 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart @@ -792,7 +792,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl } else { returnType = 'void'; } - } else if (returnTypeObj.isDynamic) { + } else if (returnTypeObj is DynamicType) { variableType = ''; if (_hasAwait) { returnType = _getTypeCode(typeProvider.futureDynamicType); diff --git a/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart b/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart index 7e3801cba82..c857586edab 100644 --- a/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart +++ b/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart @@ -104,10 +104,11 @@ class ImpliedTypeCollector extends RecursiveAstVisitor { void handleVariableDeclaration(VariableDeclaration node, DartType? dartType) { // If some untyped variable declaration if (node.equals != null && dartType == null || - (dartType != null && (dartType.isDynamic || dartType is VoidType))) { + (dartType != null && + (dartType is DynamicType || dartType is VoidType))) { // And if we can determine the type on the RHS of the variable declaration var rhsType = node.initializer?.staticType; - if (rhsType != null && !rhsType.isDynamic) { + if (rhsType != null && rhsType is! DynamicType) { // Record the name with the type. data.recordImpliedType( node.name.lexeme, diff --git a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart index 7609882cdc7..faf6d342ffa 100644 --- a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart @@ -1661,9 +1661,9 @@ class RelevanceDataCollector extends RecursiveAstVisitor { var overrideType = overrideParameter?.type; var overriddenType = overriddenParameter?.type; if (overrideType == null || - overrideType.isDynamic || + overrideType is DynamicType || overriddenType == null || - overriddenType.isDynamic) { + overriddenType is DynamicType) { return; } _recordTypeRelationships( @@ -1764,7 +1764,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor { /// in the expression match the type of the associated parameter. void _recordTypeMatch(Expression argument) { var parameterType = argument.staticParameterElement?.type; - if (parameterType == null || parameterType.isDynamic) { + if (parameterType == null || parameterType is DynamicType) { return; } if (parameterType is FunctionType) { diff --git a/pkg/analysis_server/tool/code_completion/visitors.dart b/pkg/analysis_server/tool/code_completion/visitors.dart index 5b681ab123f..edf164d9653 100644 --- a/pkg/analysis_server/tool/code_completion/visitors.dart +++ b/pkg/analysis_server/tool/code_completion/visitors.dart @@ -11,6 +11,7 @@ import 'package:analyzer/dart/ast/syntactic_entity.dart'; import 'package:analyzer/dart/ast/token.dart'; import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/dart/element/element.dart' as element; +import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/source/line_info.dart'; class ExpectedCompletion { @@ -773,7 +774,7 @@ class ExpectedCompletionsVisitor extends RecursiveAstVisitor { // If the type of the SimpleIdentifier is dynamic, don't include. var staticType = node.staticType; - if (staticType != null && staticType.isDynamic) { + if (staticType != null && staticType is DynamicType) { return false; } diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index ab2fa2e7ec6..465dc5acc06 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -1,3 +1,6 @@ +## 5.12.0-dev +* Deprecated `DartType.isDynamic`, use `is DynamicType` instead. + ## 5.11.1 * Restore previously published `finalKeyword`, `interfaceKeyword` and `sealedKeyword` of `MixinElement`. We added them preliminary while diff --git a/pkg/analyzer/lib/dart/element/type.dart b/pkg/analyzer/lib/dart/element/type.dart index e10fac8b5a7..41f303615f8 100644 --- a/pkg/analyzer/lib/dart/element/type.dart +++ b/pkg/analyzer/lib/dart/element/type.dart @@ -124,6 +124,7 @@ abstract class DartType { bool get isDartCoreType; /// Return `true` if this type represents the type 'dynamic'. + @Deprecated('Use `is DynamicType` instead') bool get isDynamic; /// Return `true` if this type represents the type 'void'. diff --git a/pkg/analyzer/lib/src/dart/element/display_string_builder.dart b/pkg/analyzer/lib/src/dart/element/display_string_builder.dart index 0497a7eb9e4..e003ba4502d 100644 --- a/pkg/analyzer/lib/src/dart/element/display_string_builder.dart +++ b/pkg/analyzer/lib/src/dart/element/display_string_builder.dart @@ -381,7 +381,7 @@ class ElementDisplayStringBuilder { } if (skipAllDynamicArguments) { - if (typeArguments.every((t) => t.isDynamic)) { + if (typeArguments.every((t) => t is DynamicType)) { return; } } diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart index 7ebde9eda89..28047fa9613 100644 --- a/pkg/analyzer/lib/src/dart/element/type.dart +++ b/pkg/analyzer/lib/src/dart/element/type.dart @@ -48,6 +48,7 @@ class DynamicTypeImpl extends TypeImpl implements DynamicType { @override int get hashCode => 1; + @Deprecated('Use `is DynamicType` instead') @override bool get isDynamic => true; @@ -362,7 +363,7 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType { return null; } - if (!bound2.isDynamic) { + if (bound2 is! DynamicType) { pFresh.bound = bound2; } } @@ -1247,6 +1248,7 @@ abstract class TypeImpl implements DartType { @override bool get isDartCoreType => false; + @Deprecated('Use `is DynamicType` instead') @override bool get isDynamic => false; diff --git a/pkg/analyzer/lib/src/dart/element/type_schema.dart b/pkg/analyzer/lib/src/dart/element/type_schema.dart index d3916a2d2e6..176b882479a 100644 --- a/pkg/analyzer/lib/src/dart/element/type_schema.dart +++ b/pkg/analyzer/lib/src/dart/element/type_schema.dart @@ -32,6 +32,7 @@ class UnknownInferredType extends TypeImpl { @override int get hashCode => 1; + @Deprecated('Use `is UnknownInferredType` instead') @override bool get isDynamic => true; diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart index ba0bdf5c86a..5706755ae44 100644 --- a/pkg/analyzer/lib/src/dart/element/type_system.dart +++ b/pkg/analyzer/lib/src/dart/element/type_system.dart @@ -914,7 +914,7 @@ class TypeSystemImpl implements TypeSystem { // Now handle NNBD default behavior, where we disable non-dynamic downcasts. if (isNonNullableByDefault) { - return fromType.isDynamic; + return fromType is DynamicType; } // Don't allow implicit downcasts between function types @@ -1243,7 +1243,10 @@ class TypeSystemImpl implements TypeSystem { @override bool isNonNullable(DartType type) { - if (type.isDynamic || type is VoidType || type.isDartCoreNull) { + if (type is DynamicType || + type is UnknownInferredType || + type is VoidType || + type.isDartCoreNull) { return false; } else if (type is TypeParameterTypeImpl && type.promotedBound != null) { return isNonNullable(type.promotedBound!); @@ -1284,7 +1287,10 @@ class TypeSystemImpl implements TypeSystem { @override bool isNullable(DartType type) { - if (type.isDynamic || type is VoidType || type.isDartCoreNull) { + if (type is DynamicType || + type is UnknownInferredType || + type is VoidType || + type.isDartCoreNull) { return true; } else if (type is TypeParameterTypeImpl && type.promotedBound != null) { return isNullable(type.promotedBound!); @@ -1326,7 +1332,10 @@ class TypeSystemImpl implements TypeSystem { @override bool isStrictlyNonNullable(DartType type) { - if (type.isDynamic || type is VoidType || type.isDartCoreNull) { + if (type is DynamicType || + type is UnknownInferredType || + type is VoidType || + type.isDartCoreNull) { return false; } else if (type.nullabilitySuffix != NullabilitySuffix.none) { return false; @@ -1682,7 +1691,7 @@ class TypeSystemImpl implements TypeSystem { return null; } - if (!bound1.isDynamic) { + if (bound1 is! DynamicType) { freshTypeParameters[i].bound = bound1; } } diff --git a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart index a4935f4316c..d87f8141202 100644 --- a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart @@ -13,6 +13,7 @@ import 'package:analyzer/error/listener.dart'; import 'package:analyzer/src/dart/ast/ast.dart'; import 'package:analyzer/src/dart/ast/extensions.dart'; import 'package:analyzer/src/dart/element/type.dart'; +import 'package:analyzer/src/dart/element/type_schema.dart'; import 'package:analyzer/src/dart/element/type_system.dart'; import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart'; import 'package:analyzer/src/dart/resolver/resolution_result.dart'; @@ -176,7 +177,9 @@ class BinaryExpressionResolver { var leftType = left.typeOrThrow; var rightContextType = contextType; - if (rightContextType == null || rightContextType.isDynamic) { + if (rightContextType == null || + rightContextType is DynamicType || + rightContextType is UnknownInferredType) { rightContextType = leftType; } diff --git a/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart index 9aa6ebcc959..684f8d10f5f 100644 --- a/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart +++ b/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart @@ -427,7 +427,7 @@ class TypeSystemOperations } @override - bool isDynamic(DartType type) => type.isDynamic; + bool isDynamic(DartType type) => type is DynamicType; @override bool isNever(DartType type) { diff --git a/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart index cde77546f02..2f7f97b1152 100644 --- a/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart @@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/dart/ast/ast.dart'; import 'package:analyzer/src/dart/element/element.dart'; import 'package:analyzer/src/dart/element/type.dart'; +import 'package:analyzer/src/dart/element/type_schema.dart'; import 'package:analyzer/src/dart/element/type_system.dart'; import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart'; import 'package:analyzer/src/generated/migration.dart'; @@ -53,7 +54,7 @@ class FunctionExpressionResolver { if (instantiatedType is FunctionType) { _inferFormalParameters(node.parameters, instantiatedType); var returnType = instantiatedType.returnType; - if (!returnType.isDynamic) { + if (!(returnType is DynamicType || returnType is UnknownInferredType)) { imposedType = returnType; } } @@ -91,7 +92,7 @@ class FunctionExpressionResolver { void inferType(ParameterElementImpl p, DartType inferredType) { // Check that there is no declared type, and that we have not already // inferred a type in some fashion. - if (p.hasImplicitType && p.type.isDynamic) { + if (p.hasImplicitType && p.type is DynamicType) { // If no type is declared for a parameter and there is a // corresponding parameter in the context type schema with type // schema `K`, the parameter is given an inferred type `T` where `T` @@ -111,7 +112,7 @@ class FunctionExpressionResolver { } else { inferredType = _typeSystem.nonNullifyLegacy(inferredType); } - if (!inferredType.isDynamic) { + if (inferredType is! DynamicType) { p.type = inferredType; } } diff --git a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart index 9fff0b34cf5..40720acb203 100644 --- a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart @@ -102,7 +102,7 @@ class FunctionReferenceResolver { prefixType = prefixElement.variable.type; } - if (prefixType != null && prefixType.isDynamic) { + if (prefixType is DynamicType) { _errorReporter.reportErrorForNode( CompileTimeErrorCode.GENERIC_METHOD_TYPE_INSTANTIATION_ON_DYNAMIC, function, @@ -520,7 +520,7 @@ class FunctionReferenceResolver { return; } else { var targetType = target.staticType; - if (targetType != null && targetType.isDynamic) { + if (targetType is DynamicType) { _errorReporter.reportErrorForNode( CompileTimeErrorCode.GENERIC_METHOD_TYPE_INSTANTIATION_ON_DYNAMIC, node, diff --git a/pkg/analyzer/lib/src/dart/resolver/legacy_type_asserter.dart b/pkg/analyzer/lib/src/dart/resolver/legacy_type_asserter.dart index e29344f0c85..18d3cefb7d7 100644 --- a/pkg/analyzer/lib/src/dart/resolver/legacy_type_asserter.dart +++ b/pkg/analyzer/lib/src/dart/resolver/legacy_type_asserter.dart @@ -127,7 +127,7 @@ class LegacyTypeAsserter extends GeneralizingAstVisitor { return; } - if (type.isDynamic || type is VoidType) { + if (type is DynamicType || type is VoidType) { return; } diff --git a/pkg/analyzer/lib/src/dart/resolver/record_literal_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/record_literal_resolver.dart index 9612b79e848..a37b5360b78 100644 --- a/pkg/analyzer/lib/src/dart/resolver/record_literal_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/record_literal_resolver.dart @@ -128,7 +128,7 @@ class RecordLiteralResolver { field = _resolver.popRewrite()!; // Implicit cast from `dynamic`. - if (contextType != null && field.typeOrThrow.isDynamic) { + if (contextType != null && field.typeOrThrow is DynamicType) { field.staticType = contextType; if (field is NamedExpressionImpl) { field.expression.staticType = contextType; diff --git a/pkg/analyzer/lib/src/dart/resolver/typed_literal_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/typed_literal_resolver.dart index de27813edea..5b60a57bc6c 100644 --- a/pkg/analyzer/lib/src/dart/resolver/typed_literal_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/typed_literal_resolver.dart @@ -101,7 +101,7 @@ class TypedLiteralResolver { if (typeArguments != null) { if (typeArguments.length == 1) { DartType elementType = typeArguments[0].typeOrThrow; - if (!elementType.isDynamic) { + if (elementType is! DynamicType) { listType = _typeProvider.listType(elementType); } } @@ -220,7 +220,7 @@ class TypedLiteralResolver { return iterableType.typeArguments[0]; } - if (expressionType.isDynamic) { + if (expressionType is DynamicType) { return _typeProvider.dynamicType; } @@ -411,7 +411,7 @@ class TypedLiteralResolver { ); } - if (expressionType.isDynamic) { + if (expressionType is DynamicType) { return _InferredCollectionElementTypeInformation( elementType: expressionType, keyType: expressionType, @@ -679,7 +679,7 @@ class TypedLiteralResolver { } DartType literalType = _inferSetOrMapLiteralType(inferrer, literalResolution, node); - if (literalType.isDynamic) { + if (literalType is DynamicType) { // The literal is ambiguous, and further analysis won't resolve the // ambiguity. Leave it as neither a set nor a map. } else if (literalType is InterfaceType && @@ -821,12 +821,9 @@ class _InferredCollectionElementTypeInformation { bool get canBeSet => elementType != null; bool get isDynamic => - elementType != null && - elementType!.isDynamic && - keyType != null && - keyType!.isDynamic && - valueType != null && - valueType!.isDynamic; + elementType is DynamicType && + keyType is DynamicType && + valueType is DynamicType; bool get mustBeMap => canBeMap && elementType == null; diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart index c410435d46d..346c7925782 100644 --- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart +++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart @@ -629,7 +629,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { // Only report non-aliased, non-user-defined `Null?` and `dynamic?`. Do // not report synthetic `dynamic` in place of an unresolved type. if ((type is InterfaceType && type.element == _nullType.element || - (type.isDynamic && node.name2.lexeme == 'dynamic')) && + (type is DynamicType && node.name2.lexeme == 'dynamic')) && type.alias == null) { _errorReporter.reportErrorForToken( WarningCode.UNNECESSARY_QUESTION_MARK, @@ -753,7 +753,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { } // `is dynamic` or `is! dynamic` - if (rightType.isDynamic) { + if (rightType is DynamicType) { var rightTypeStr = rightNode.ifTypeOrNull()?.qualifiedName; if (rightTypeStr == Keyword.DYNAMIC.lexeme) { report(); @@ -1601,12 +1601,12 @@ class BestPracticesVerifier extends RecursiveAstVisitor { var rightType = node.type.typeOrThrow; // `dynamicValue as SomeType` is a valid use case. - if (leftType.isDynamic) { + if (leftType is DynamicType) { return false; } // `x as Unresolved` is already reported as an error. - if (rightType.isDynamic) { + if (rightType is DynamicType) { return false; } diff --git a/pkg/analyzer/lib/src/error/literal_element_verifier.dart b/pkg/analyzer/lib/src/error/literal_element_verifier.dart index 275d9fc05fa..2f32ab60ebd 100644 --- a/pkg/analyzer/lib/src/error/literal_element_verifier.dart +++ b/pkg/analyzer/lib/src/error/literal_element_verifier.dart @@ -138,7 +138,7 @@ class LiteralElementVerifier { /// assigned to the [elementType] of the enclosing collection. void _verifySpreadForListOrSet(bool isNullAware, Expression expression) { var expressionType = expression.typeOrThrow; - if (expressionType.isDynamic) { + if (expressionType is DynamicType) { if (typeSystem.strictCasts) { return errorReporter.reportErrorForNode( CompileTimeErrorCode.NOT_ITERABLE_SPREAD, @@ -232,7 +232,7 @@ class LiteralElementVerifier { /// its key and values are assignable to [mapKeyType] and [mapValueType]. void _verifySpreadForMap(bool isNullAware, Expression expression) { var expressionType = expression.typeOrThrow; - if (expressionType.isDynamic) { + if (expressionType is DynamicType) { if (typeSystem.strictCasts) { return errorReporter.reportErrorForNode( CompileTimeErrorCode.NOT_MAP_SPREAD, diff --git a/pkg/analyzer/lib/src/error/return_type_verifier.dart b/pkg/analyzer/lib/src/error/return_type_verifier.dart index b1d4c40cbab..411d9463d9e 100644 --- a/pkg/analyzer/lib/src/error/return_type_verifier.dart +++ b/pkg/analyzer/lib/src/error/return_type_verifier.dart @@ -448,10 +448,10 @@ class ReturnTypeVerifier { } static bool _isVoidDynamic(DartType type) { - return type is VoidType || type.isDynamic; + return type is VoidType || type is DynamicType; } static bool _isVoidDynamicOrNull(DartType type) { - return type is VoidType || type.isDynamic || type.isDartCoreNull; + return type is VoidType || type is DynamicType || type.isDartCoreNull; } } diff --git a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart index 63a39b91f4e..f3af78f34c8 100644 --- a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart +++ b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart @@ -232,7 +232,7 @@ class TypeArgumentsVerifier { declaredType is FunctionType && declaredType.typeFormals.isNotEmpty) { List typeArgs = node.typeArgumentTypes!; - if (typeArgs.any((t) => t.isDynamic)) { + 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) { @@ -268,7 +268,8 @@ class TypeArgumentsVerifier { } 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)) { + 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 @@ -608,7 +609,7 @@ class TypeArgumentsVerifier { // Check if this type has type arguments and at least one is dynamic. // If so, we may need to issue a strict-raw-types error. - if (typeArguments.any((t) => t.isDynamic)) { + if (typeArguments.any((t) => t is DynamicType)) { if (element != null && element.hasOptionalTypeArgs) { return false; } diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart index 9dcc6de497e..c51ba8ea8fb 100644 --- a/pkg/analyzer/lib/src/generated/element_resolver.dart +++ b/pkg/analyzer/lib/src/generated/element_resolver.dart @@ -161,7 +161,7 @@ class ElementResolver { if (type == null) { return; } - if (type.isDynamic) { + if (type is DynamicType) { // Nothing to do. } else if (type is InterfaceType) { // look up ConstructorElement diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 5668ad8edd9..c1cd538d21c 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -825,7 +825,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (!_options.implicitDynamic && node.returnType == null) { DartType parameterType = node.declaredElement!.type; if (parameterType is FunctionType && - parameterType.returnType.isDynamic) { + parameterType.returnType is DynamicType) { errorReporter.reportErrorForToken( LanguageCode.IMPLICIT_DYNAMIC_RETURN, node.name, @@ -2478,7 +2478,7 @@ class ErrorVerifier extends RecursiveAstVisitor // Use an explicit string instead of [loopType] to remove the "". String loopNamedType = awaitKeyword != null ? 'Stream' : 'Iterable'; - if (iterableType.isDynamic && typeSystem.strictCasts) { + if (iterableType is DynamicType && typeSystem.strictCasts) { errorReporter.reportErrorForNode( CompileTimeErrorCode.FOR_IN_OF_INVALID_TYPE, node.iterable, @@ -3003,7 +3003,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (_options.implicitDynamic) { return; } - if (variable.hasImplicitType && variable.type.isDynamic) { + if (variable.hasImplicitType && variable.type is DynamicType) { ErrorCode errorCode; if (variable is FieldElement) { errorCode = LanguageCode.IMPLICIT_DYNAMIC_FIELD; @@ -3026,7 +3026,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (element is PropertyAccessorElement && element.isSetter) { return; } - if (element.hasImplicitReturnType && element.returnType.isDynamic) { + if (element.hasImplicitReturnType && element.returnType is DynamicType) { errorReporter.reportErrorForToken(LanguageCode.IMPLICIT_DYNAMIC_RETURN, functionName, [element.displayName]); } @@ -3041,7 +3041,7 @@ class ErrorVerifier extends RecursiveAstVisitor DartType type = node.typeOrThrow; if (type is ParameterizedType && type.typeArguments.isNotEmpty && - type.typeArguments.any((t) => t.isDynamic)) { + type.typeArguments.any((t) => t is DynamicType)) { errorReporter .reportErrorForNode(LanguageCode.IMPLICIT_DYNAMIC_TYPE, node, [type]); } diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart index 8c9957854c1..e26d46ee901 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart @@ -629,8 +629,9 @@ class ResolverVisitor extends ThrowingAstVisitor errorCode = CompileTimeErrorCode.BODY_MIGHT_COMPLETE_NORMALLY; } else { var returnTypeBase = typeSystem.futureOrBase(returnType); - if (returnTypeBase is VoidType || - returnTypeBase.isDynamic || + if (returnTypeBase is DynamicType || + returnTypeBase is UnknownInferredType || + returnTypeBase is VoidType || returnTypeBase.isDartCoreNull) { return; } else { @@ -2214,7 +2215,7 @@ class ResolverVisitor extends ThrowingAstVisitor node.parameters.accept(this); node.initializers.accept(this); node.redirectedConstructor?.accept(this); - node.body.resolve(this, returnType.isDynamic ? null : returnType); + node.body.resolve(this, returnType is DynamicType ? null : returnType); elementResolver.visitConstructorDeclaration(node); } finally { _enclosingFunction = outerFunction; @@ -2957,7 +2958,7 @@ class ResolverVisitor extends ThrowingAstVisitor node.returnType?.accept(this); node.typeParameters?.accept(this); node.parameters?.accept(this); - node.body.resolve(this, returnType.isDynamic ? null : returnType); + node.body.resolve(this, returnType is DynamicType ? null : returnType); elementResolver.visitMethodDeclaration(node); } finally { _enclosingFunction = outerFunction; @@ -3653,8 +3654,9 @@ class ResolverVisitor extends ThrowingAstVisitor final targetFutureType = instanceOfFuture.typeArguments.first; final expectedReturnType = typeProvider.futureOrType(targetFutureType); final returnTypeBase = typeSystem.futureOrBase(expectedReturnType); - if (returnTypeBase is VoidType || - returnTypeBase.isDynamic || + if (returnTypeBase is DynamicType || + returnTypeBase is UnknownInferredType || + returnTypeBase is VoidType || returnTypeBase.isDartCoreNull) { return; } diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart index 98ba14bd803..bc6acc79c2d 100644 --- a/pkg/analyzer/lib/src/task/strong/checker.dart +++ b/pkg/analyzer/lib/src/task/strong/checker.dart @@ -594,7 +594,7 @@ class CodeChecker extends RecursiveAstVisitor { } } if (yieldStar) { - if (type.isDynamic) { + if (type is DynamicType) { // Ensure it's at least a Stream / Iterable. return expectedElement.instantiate( typeArguments: [_typeProvider.dynamicType], @@ -606,7 +606,7 @@ class CodeChecker extends RecursiveAstVisitor { return type; } } - if (type.isDynamic) { + if (type is DynamicType) { return type; } else if (type is InterfaceType && type.element == expectedElement) { return type.typeArguments[0]; diff --git a/pkg/analyzer/pubspec.yaml b/pkg/analyzer/pubspec.yaml index d12c9c2a934..fa3aa667497 100644 --- a/pkg/analyzer/pubspec.yaml +++ b/pkg/analyzer/pubspec.yaml @@ -1,5 +1,5 @@ name: analyzer -version: 5.11.1 +version: 5.12.0-dev description: >- This package provides a library that performs static analysis of Dart code. repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer diff --git a/pkg/analyzer/test/generated/resolver_test_case.dart b/pkg/analyzer/test/generated/resolver_test_case.dart index 64edff5c9c4..7e0111bd166 100644 --- a/pkg/analyzer/test/generated/resolver_test_case.dart +++ b/pkg/analyzer/test/generated/resolver_test_case.dart @@ -70,7 +70,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { return; } var operandType = node.leftOperand.staticType; - if (operandType == null || operandType.isDynamic) { + if (operandType == null || operandType is DynamicType) { return; } _checkResolved(node, node.staticElement, (node) => node is MethodElement); @@ -124,7 +124,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { void visitIndexExpression(IndexExpression node) { node.visitChildren(this); var targetType = node.realTarget.staticType; - if (targetType == null || targetType.isDynamic) { + if (targetType == null || targetType is DynamicType) { return; } var parent = node.parent; @@ -162,7 +162,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { return; } var operandType = node.operand.staticType; - if (operandType == null || operandType.isDynamic) { + if (operandType == null || operandType is DynamicType) { return; } _checkResolved(node, node.staticElement, (node) => node is MethodElement); @@ -173,7 +173,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { SimpleIdentifier prefix = node.prefix; prefix.accept(this); var prefixType = prefix.staticType; - if (prefixType == null || prefixType.isDynamic) { + if (prefixType == null || prefixType is DynamicType) { return; } _checkResolved(node, node.staticElement, null); @@ -186,7 +186,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { return; } var operandType = node.operand.staticType; - if (operandType == null || operandType.isDynamic) { + if (operandType == null || operandType is DynamicType) { return; } _checkResolved(node, node.staticElement, (node) => node is MethodElement); @@ -197,7 +197,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { Expression target = node.realTarget; target.accept(this); var targetType = target.staticType; - if (targetType == null || targetType.isDynamic) { + if (targetType == null || targetType is DynamicType) { return; } var parent = node.parent; @@ -218,9 +218,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { } var staticType = node.staticType; - if (staticType != null && - staticType.isDynamic && - node.staticElement == null) { + if (staticType is DynamicType && node.staticElement == null) { return; } @@ -233,7 +231,7 @@ class ResolutionVerifier extends RecursiveAstVisitor { if (identical(invocation.methodName, node)) { var target = invocation.realTarget; var targetType = target?.staticType; - if (targetType == null || targetType.isDynamic) { + if (targetType == null || targetType is DynamicType) { return; } } diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart index b6b12dfd675..4a33deb8af9 100644 --- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart +++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart @@ -69,7 +69,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { @override bool canWriteType(DartType? type, {ExecutableElement? methodBeingCopied}) => - type != null && !type.isDynamic + type != null && type is! DynamicType ? _canWriteType(type, methodBeingCopied: methodBeingCopied) : false; @@ -273,7 +273,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { write(Keyword.STATIC.lexeme); write(' '); } - if (returnType != null && !returnType.isDynamic) { + if (returnType != null && returnType is! DynamicType) { if (writeType(returnType, groupName: returnTypeGroupName)) { write(' '); } @@ -730,7 +730,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { write(name); } write('('); - if (parameterType != null && !parameterType.isDynamic) { + if (parameterType != null && parameterType is! DynamicType) { if (writeType(parameterType, groupName: parameterTypeGroupName)) { write(' '); } @@ -753,7 +753,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { ExecutableElement? methodBeingCopied, bool required = false}) { var wroteType = false; - if (type != null && !type.isDynamic) { + if (type != null && type is! DynamicType) { if (groupName != null) { addLinkedEdit(groupName, (LinkedEditBuilder builder) { wroteType = _writeType(type, methodBeingCopied: methodBeingCopied); @@ -879,7 +879,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { if (type == null) { return false; } - if (type.isDynamic) { + if (type is DynamicType) { if (required) { return true; } @@ -1092,7 +1092,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { } } // use type - if (expectedType != null && !expectedType.isDynamic) { + if (expectedType != null && expectedType is! DynamicType) { if (expectedType.isDartCoreInt) { _addSingleCharacterName(excluded, res, $i); } else if (expectedType.isDartCoreDouble) { @@ -1223,7 +1223,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { if (type == null) { return false; } - if (type.isDynamic) { + if (type is DynamicType) { if (required) { write('dynamic'); return true; @@ -1360,7 +1360,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { var hasArguments = false; var allArgumentsVisible = true; for (var argument in typeArguments) { - hasArguments = hasArguments || !argument.isDynamic; + hasArguments = hasArguments || argument is! DynamicType; allArgumentsVisible = allArgumentsVisible && _getVisibleType(argument, methodBeingCopied: methodBeingCopied) != null; @@ -1628,7 +1628,7 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl // Check whether the type needs to be replaced. // var type = typeAnnotation?.type; - if (type == null || type.isDynamic || type.isDartAsyncFuture) { + if (type == null || type is DynamicType || type.isDartAsyncFuture) { return; } diff --git a/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart b/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart index 821bea82386..264ce1c1dbf 100644 --- a/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart +++ b/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart @@ -75,7 +75,7 @@ class TypeMemberContributor implements CompletionContributor { // Determine the target expression's type var type = expression.staticType; - if (type == null || type.isDynamic) { + if (type == null || type is DynamicType) { // If the expression does not provide a good type // then attempt to get a better type from the element if (expression is Identifier) { @@ -87,7 +87,7 @@ class TypeMemberContributor implements CompletionContributor { } else if (elem is LocalVariableElement) { type = elem.type; } - if ((type == null || type.isDynamic) && + if ((type == null || type is DynamicType) && expression is SimpleIdentifier) { // If the element does not provide a good type // then attempt to get a better type from a local declaration @@ -111,7 +111,7 @@ class TypeMemberContributor implements CompletionContributor { containingMethodName = id.lexeme; } } - if (type == null || type.isDynamic) { + if (type == null || type is DynamicType) { // Suggest members from object if target is "dynamic" type = request.result.typeProvider.objectType; } diff --git a/pkg/nnbd_migration/lib/src/already_migrated_code_decorator.dart b/pkg/nnbd_migration/lib/src/already_migrated_code_decorator.dart index cc58f759586..6a357ab5141 100644 --- a/pkg/nnbd_migration/lib/src/already_migrated_code_decorator.dart +++ b/pkg/nnbd_migration/lib/src/already_migrated_code_decorator.dart @@ -29,7 +29,7 @@ class AlreadyMigratedCodeDecorator { /// TODO(paulberry): do we still need element or can we use target now? DecoratedType decorate( DartType type, Element element, NullabilityNodeTarget target) { - if (type is VoidType || type.isDynamic) { + if (type is VoidType || type is DynamicType) { var node = NullabilityNode.forAlreadyMigrated(target); _graph.makeNullableUnion( node, AlwaysNullableTypeOrigin.forElement(element, type is VoidType)); diff --git a/pkg/nnbd_migration/lib/src/decorated_type.dart b/pkg/nnbd_migration/lib/src/decorated_type.dart index 40ec33e1fa9..35fe682ec39 100644 --- a/pkg/nnbd_migration/lib/src/decorated_type.dart +++ b/pkg/nnbd_migration/lib/src/decorated_type.dart @@ -450,7 +450,7 @@ class DecoratedType implements DecoratedTypeInfo, SubstitutedType { } else { return inner._performSubstitution(this, undecoratedResult!); } - } else if (type is VoidType || type!.isDynamic) { + } else if (type is VoidType || type is DynamicType) { return this; } throw '$type.substitute($type | $substitution)'; // TODO(paulberry) diff --git a/pkg/nnbd_migration/lib/src/edge_builder.dart b/pkg/nnbd_migration/lib/src/edge_builder.dart index 1785cf5ef6f..a4f4b8eebb4 100644 --- a/pkg/nnbd_migration/lib/src/edge_builder.dart +++ b/pkg/nnbd_migration/lib/src/edge_builder.dart @@ -2275,7 +2275,7 @@ class EdgeBuilder extends GeneralizingAstVisitor ? NullabilityNode.forLUB(left.node, right.node) : _nullabilityNodeForGLB(astNode, left.node, right.node); - if (type!.isDynamic || type is VoidType) { + if (type is DynamicType || type is VoidType) { return DecoratedType(type, node); } else if (leftType!.isBottom) { return right.withNode(node); @@ -3439,7 +3439,7 @@ class EdgeBuilder extends GeneralizingAstVisitor EdgeOrigin _makeEdgeOrigin(DecoratedType sourceType, Expression expression, {bool isSetupAssignment = false}) { - if (sourceType.type!.isDynamic) { + if (sourceType.type is DynamicType) { return DynamicAssignmentOrigin(source, expression, isSetupAssignment: isSetupAssignment); } else { @@ -3913,7 +3913,7 @@ mixin _AssignmentChecker { hard: false); return; } - } else if (destinationType.isDynamic || + } else if (destinationType is DynamicType || destinationType is VoidType || destinationType.isDartCoreObject) { // No further edges need to be created, since all types are trivially @@ -3965,7 +3965,7 @@ mixin _AssignmentChecker { hard: false, checkable: false); } - } else if (destinationType.isDynamic || sourceType.isDynamic) { + } else if (destinationType is DynamicType || sourceType is DynamicType) { // ok; nothing further to do. } else if (destinationType is InterfaceType && sourceType is FunctionType) { // Either this is an upcast to Function or Object, or it is erroneous @@ -3986,7 +3986,7 @@ mixin _AssignmentChecker { _connect(source.node, destination.node, origin, FixReasonTarget.root, hard: hard); - if (sourceType.isDynamic || + if (sourceType is DynamicType || sourceType.isDartCoreObject || sourceType is VoidType) { if (destinationType is InterfaceType) { diff --git a/pkg/nnbd_migration/lib/src/fix_aggregator.dart b/pkg/nnbd_migration/lib/src/fix_aggregator.dart index 31609d64933..e3f27431e76 100644 --- a/pkg/nnbd_migration/lib/src/fix_aggregator.dart +++ b/pkg/nnbd_migration/lib/src/fix_aggregator.dart @@ -120,7 +120,7 @@ class FixAggregator extends UnifyingAstVisitor { String typeFormalToCode(TypeParameterElement formal) { var bound = formal.bound; if (bound == null || - bound.isDynamic || + bound is DynamicType || (bound.isDartCoreObject && bound.nullabilitySuffix != NullabilitySuffix.none)) { return formal.name; diff --git a/pkg/nnbd_migration/lib/src/fix_builder.dart b/pkg/nnbd_migration/lib/src/fix_builder.dart index ec93c55c09f..e8b9da77441 100644 --- a/pkg/nnbd_migration/lib/src/fix_builder.dart +++ b/pkg/nnbd_migration/lib/src/fix_builder.dart @@ -472,7 +472,7 @@ class MigrationResolutionHooksImpl .decoratedTypeParameterBound(element, allowNullUnparentedBounds: true); if (decoratedBound == null) return element.boundInternal; var bound = _fixBuilder._variables!.toFinalType(decoratedBound); - if (bound.isDynamic) { + if (bound is DynamicType) { return null; } else if (bound.isDartCoreObject && bound.nullabilitySuffix == NullabilitySuffix.question) { @@ -807,7 +807,7 @@ class MigrationResolutionHooksImpl hintComment: hint), hint: hint); } - if (type.isDynamic) return type; + if (type is DynamicType) return type; var ancestor = _findNullabilityContextAncestor(node); context ??= _contextTypes[ancestor] ?? DynamicTypeImpl.instance; if (!_isSubtypeOrCoercible(type, context)) { @@ -1082,7 +1082,7 @@ abstract class _AssignmentLikeExpressionHandler { .isWeakNullAware = true; } } else { - if (!readType!.isDynamic && + if (readType is! DynamicType && fixBuilder._typeSystem.isPotentiallyNullable(readType!)) { (fixBuilder._getChange(node) as NodeChangeForAssignmentLike) .hasNullableSource = true; @@ -1460,7 +1460,7 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor } bool _typeIsNaturallyNullable(DartType type) => - type.isDynamic || type is VoidType || type.isDartCoreNull; + type is DynamicType || type is VoidType || type.isDartCoreNull; } /// Specialization of [_AssignmentLikeExpressionHandler] for diff --git a/pkg/nnbd_migration/lib/src/node_builder.dart b/pkg/nnbd_migration/lib/src/node_builder.dart index 3d8f3107aca..3443226d607 100644 --- a/pkg/nnbd_migration/lib/src/node_builder.dart +++ b/pkg/nnbd_migration/lib/src/node_builder.dart @@ -531,7 +531,7 @@ class NodeBuilder extends GeneralizingAstVisitor DecoratedType visitTypeAnnotation(TypeAnnotation node) { var type = node.type!; var target = safeTarget.withCodeRef(node); - if (type is VoidType || type.isDynamic) { + if (type is VoidType || type is DynamicType) { var nullabilityNode = NullabilityNode.forTypeAnnotation(target); var decoratedType = DecoratedType(type, nullabilityNode); _variables.recordDecoratedTypeAnnotation(source, node, decoratedType); @@ -777,7 +777,7 @@ class NodeBuilder extends GeneralizingAstVisitor decoratedReturnType = DecoratedType.forImplicitType( _typeProvider, functionType.returnType, _graph, target); instrumentation?.implicitReturnType(source, node, decoratedReturnType); - if (isExternal && functionType.returnType.isDynamic) { + if (isExternal && functionType.returnType is DynamicType) { _graph.makeNullableUnion( decoratedReturnType.node, ExternalDynamicOrigin(source, node)); } diff --git a/pkg/nnbd_migration/lib/src/variables.dart b/pkg/nnbd_migration/lib/src/variables.dart index 3a62643af40..dbe9f4bce58 100644 --- a/pkg/nnbd_migration/lib/src/variables.dart +++ b/pkg/nnbd_migration/lib/src/variables.dart @@ -297,7 +297,7 @@ class Variables { /// types should be nullable and which types should not. DartType toFinalType(DecoratedType decoratedType) { var type = decoratedType.type!; - if (type is VoidType || type.isDynamic) return type; + if (type is VoidType || type is DynamicType) return type; if (type is NeverType) { if (decoratedType.node.isNullable) { return (_typeProvider.nullType as TypeImpl) diff --git a/pkg/nnbd_migration/test/node_builder_test.dart b/pkg/nnbd_migration/test/node_builder_test.dart index 7fc1668e911..12f2090865d 100644 --- a/pkg/nnbd_migration/test/node_builder_test.dart +++ b/pkg/nnbd_migration/test/node_builder_test.dart @@ -1084,7 +1084,7 @@ typedef F(); '''); var decoratedType = variables .decoratedElementType(findElement.typeAlias('F').aliasedElement!); - expect(decoratedType.returnType!.type!.isDynamic, isTrue); + expect(decoratedType.returnType!.type is DynamicType, isTrue); expect(decoratedType.returnType!.node.isImmutable, false); expect(decoratedType.typeFormals, isEmpty); } @@ -1347,7 +1347,7 @@ typedef F = Function(); .decoratedElementType(findElement.typeAlias('F').aliasedElement!); expect(decoratedType, same(decoratedGenericFunctionTypeAnnotation('Function'))); - expect(decoratedType.returnType!.type!.isDynamic, isTrue); + expect(decoratedType.returnType!.type is DynamicType, isTrue); expect(decoratedType.returnType!.node.isImmutable, false); expect(decoratedType.typeFormals, isEmpty); } @@ -1808,7 +1808,7 @@ void f(x) {} findNode.simpleFormalParameter('x').declaredElement!); expect(decoratedFunctionType('f').positionalParameters![0], same(decoratedType)); - expect(decoratedType.type!.isDynamic, isTrue); + expect(decoratedType.type is DynamicType, isTrue); } Future test_topLevelFunction_parameterType_named_no_default() async { @@ -1897,7 +1897,7 @@ void f(int i) {} f() {} '''); var decoratedType = decoratedFunctionType('f').returnType!; - expect(decoratedType.type!.isDynamic, isTrue); + expect(decoratedType.type is DynamicType, isTrue); } Future test_topLevelFunction_returnType_simple() async {