mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:51:29 +00:00
Deprecate 'DartType.isVoid', use 'is VoidType' instead.
Maybe? With an explicit type check we don't try to make an impression that anything more happens here, e.g. for type parameters. Similarly, for https://github.com/dart-lang/sdk/issues/36697 we would need to introduce `InvalidType`, which is not `DynamicType`. And so, `DartType.isDynamic` should not return `true` for `InvalidType`, it is not a property that various types may have, and should be replaced with explicit `is DynamicType`. We also have `UnknownInferredType`, but it should never leak to clients. Change-Id: I302b06355143d97bb52922c805dbad585a522e0a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288340 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
9698e72c8f
commit
5ecf6db857
|
@ -365,7 +365,7 @@ class DartCompletionRequest {
|
|||
);
|
||||
|
||||
var opType = OpType.forCompletion(target, offset);
|
||||
if (contextType != null && contextType.isVoid) {
|
||||
if (contextType is VoidType) {
|
||||
opType.includeVoidReturnSuggestions = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
|
|||
return;
|
||||
}
|
||||
var returnType = element.returnType;
|
||||
if (returnType.isVoid) {
|
||||
if (returnType is VoidType) {
|
||||
if (opType.includeVoidReturnSuggestions) {
|
||||
builder.suggestTopLevelFunction(element, kind: kind, prefix: prefix);
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ class LocalReferenceContributor extends DartCompletionContributor {
|
|||
for (var method in type.methods) {
|
||||
if (!method.isStatic) {
|
||||
if (_visibilityTracker._isVisible(method.declaration)) {
|
||||
if (!method.returnType.isVoid) {
|
||||
if (method.returnType is! VoidType) {
|
||||
if (opType.includeReturnValueSuggestions) {
|
||||
memberBuilder.addSuggestionForMethod(
|
||||
method: method,
|
||||
|
|
|
@ -102,7 +102,7 @@ CompletionDefaultArgumentList computeCompletionDefaultArgumentList(
|
|||
// todo (pq): consider refactoring to share common logic w/
|
||||
// ArgListContributor.buildClosureSuggestions
|
||||
final returnType = parameterType.returnType;
|
||||
if (returnType.isVoid) {
|
||||
if (returnType is VoidType) {
|
||||
blockBuffer.write('{');
|
||||
rangeStart = sb.length + blockBuffer.length;
|
||||
blockBuffer.write(' }');
|
||||
|
|
|
@ -77,7 +77,7 @@ class AddAsync extends CorrectionProducer {
|
|||
/// Return `true` if the [type] is `Future<void>`.
|
||||
bool _isFutureVoid(DartType type) {
|
||||
if (type is InterfaceType && type.isDartAsyncFuture) {
|
||||
return type.typeArguments[0].isVoid;
|
||||
return type.typeArguments[0] is VoidType;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:analysis_server/src/services/correction/dart/abstract_producer.d
|
|||
import 'package:analysis_server/src/services/correction/name_suggestion.dart';
|
||||
import 'package:analysis_server/src/utilities/extensions/ast.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/src/dart/ast/utilities.dart';
|
||||
import 'package:analyzer_plugin/utilities/assist/assist.dart';
|
||||
|
@ -50,7 +51,7 @@ class AssignToLocalVariable extends CorrectionProducer {
|
|||
var offset = expression.offset;
|
||||
// prepare expression type
|
||||
var type = expression.typeOrThrow;
|
||||
if (type.isVoid) {
|
||||
if (type is VoidType) {
|
||||
return;
|
||||
}
|
||||
// prepare excluded names
|
||||
|
|
|
@ -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:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.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';
|
||||
|
@ -64,7 +65,7 @@ class ConvertIntoBlockBody extends CorrectionProducer {
|
|||
var lines = ['// TODO: implement ${functionElement.displayName}'];
|
||||
|
||||
var returnValueType = functionElement.returnType;
|
||||
if (!returnValueType.isVoid) {
|
||||
if (returnValueType is! VoidType) {
|
||||
lines.add('throw UnimplementedError();');
|
||||
}
|
||||
return lines;
|
||||
|
@ -85,9 +86,9 @@ class ConvertIntoBlockBody extends CorrectionProducer {
|
|||
var returnValueType = returnValue.typeOrThrow;
|
||||
var returnValueCode = utils.getNodeText(returnValue);
|
||||
var returnCode = '';
|
||||
if (!returnValueType.isVoid &&
|
||||
if (returnValueType is! VoidType &&
|
||||
!returnValueType.isBottom &&
|
||||
!functionElement.returnType.isVoid) {
|
||||
functionElement.returnType is! VoidType) {
|
||||
returnCode = 'return ';
|
||||
}
|
||||
returnCode += '$returnValueCode;';
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:analysis_server/src/services/search/search_engine.dart';
|
|||
import 'package:analyzer/dart/analysis/session.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/analysis/session_helper.dart';
|
||||
import 'package:analyzer/src/dart/ast/utilities.dart';
|
||||
import 'package:analyzer_plugin/utilities/range_factory.dart';
|
||||
|
@ -88,7 +89,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
|
|||
'Only class methods or top-level functions can be converted to getters.');
|
||||
}
|
||||
// returns a value
|
||||
if (element.returnType.isVoid) {
|
||||
if (element.returnType is VoidType) {
|
||||
return RefactoringStatus.fatal(
|
||||
'Cannot convert ${element.kind.displayName} returning void.');
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:analyzer/dart/ast/ast.dart';
|
|||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/ast/utilities.dart';
|
||||
import 'package:analyzer/src/generated/java_core.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
|
@ -314,7 +315,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
|
|||
if (node is MethodInvocation) {
|
||||
var invocation = node;
|
||||
var element = invocation.methodName.staticElement;
|
||||
if (element is ExecutableElement && element.returnType.isVoid) {
|
||||
if (element is ExecutableElement && element.returnType is VoidType) {
|
||||
if (singleExpression == null) {
|
||||
return RefactoringStatus.fatal(
|
||||
'Cannot extract the void expression.',
|
||||
|
|
|
@ -104,7 +104,7 @@ class ImpliedTypeCollector extends RecursiveAstVisitor<void> {
|
|||
void handleVariableDeclaration(VariableDeclaration node, DartType? dartType) {
|
||||
// If some untyped variable declaration
|
||||
if (node.equals != null && dartType == null ||
|
||||
(dartType != null && (dartType.isDynamic || dartType.isVoid))) {
|
||||
(dartType != null && (dartType.isDynamic || 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) {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
## 5.8.0-dev
|
||||
* Deprecated `DartType.isVoid`, use `is VoidType` instead.
|
||||
|
||||
## 5.7.1
|
||||
* Require SDK `>=2.19.0 <3.0.0` to use `PathNotFoundException` from `dart:io`.
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ abstract class DartType {
|
|||
bool get isDynamic;
|
||||
|
||||
/// Return `true` if this type represents the type 'void'.
|
||||
@Deprecated('Use `is VoidType` instead')
|
||||
bool get isVoid;
|
||||
|
||||
/// Return the name of this type, or `null` if the type does not have a name,
|
||||
|
|
|
@ -1462,6 +1462,7 @@ class VoidTypeImpl extends TypeImpl implements VoidType {
|
|||
@override
|
||||
int get hashCode => 2;
|
||||
|
||||
@Deprecated('Use `is VoidType` instead')
|
||||
@override
|
||||
bool get isVoid => true;
|
||||
|
||||
|
|
|
@ -1100,7 +1100,7 @@ class TypeSystemImpl implements TypeSystem {
|
|||
|
||||
@override
|
||||
bool isNonNullable(DartType type) {
|
||||
if (type.isDynamic || type.isVoid || type.isDartCoreNull) {
|
||||
if (type.isDynamic || type is VoidType || type.isDartCoreNull) {
|
||||
return false;
|
||||
} else if (type is TypeParameterTypeImpl && type.promotedBound != null) {
|
||||
return isNonNullable(type.promotedBound!);
|
||||
|
@ -1141,7 +1141,7 @@ class TypeSystemImpl implements TypeSystem {
|
|||
|
||||
@override
|
||||
bool isNullable(DartType type) {
|
||||
if (type.isDynamic || type.isVoid || type.isDartCoreNull) {
|
||||
if (type.isDynamic || type is VoidType || type.isDartCoreNull) {
|
||||
return true;
|
||||
} else if (type is TypeParameterTypeImpl && type.promotedBound != null) {
|
||||
return isNullable(type.promotedBound!);
|
||||
|
@ -1183,7 +1183,7 @@ class TypeSystemImpl implements TypeSystem {
|
|||
|
||||
@override
|
||||
bool isStrictlyNonNullable(DartType type) {
|
||||
if (type.isDynamic || type.isVoid || type.isDartCoreNull) {
|
||||
if (type.isDynamic || type is VoidType || type.isDartCoreNull) {
|
||||
return false;
|
||||
} else if (type.nullabilitySuffix != NullabilitySuffix.none) {
|
||||
return false;
|
||||
|
|
|
@ -119,7 +119,7 @@ class AssignmentExpressionResolver {
|
|||
DartType rightType, {
|
||||
required Map<DartType, NonPromotionReason> Function()? whyNotPromoted,
|
||||
}) {
|
||||
if (!writeType.isVoid && _checkForUseOfVoidResult(right)) {
|
||||
if (writeType is! VoidType && _checkForUseOfVoidResult(right)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ class AssignmentExpressionResolver {
|
|||
// Values of the type void cannot be used.
|
||||
// Example: `y += 0`, is not allowed.
|
||||
if (operatorType != TokenType.EQ) {
|
||||
if (leftType.isVoid) {
|
||||
if (leftType is VoidType) {
|
||||
_errorReporter.reportErrorForToken(
|
||||
CompileTimeErrorCode.USE_OF_VOID_RESULT,
|
||||
operator,
|
||||
|
|
|
@ -127,11 +127,11 @@ class BodyInferenceContext {
|
|||
// If `R` is `void`, or the function literal is marked `async` and `R` is
|
||||
// `FutureOr<void>`, let `S` be `void`.
|
||||
if (_typeSystem.isNonNullableByDefault) {
|
||||
if (R.isVoid ||
|
||||
if (R is VoidType ||
|
||||
isAsynchronous &&
|
||||
R is InterfaceType &&
|
||||
R.isDartAsyncFutureOr &&
|
||||
R.typeArguments[0].isVoid) {
|
||||
R.typeArguments[0] is VoidType) {
|
||||
return VoidTypeImpl.instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ class ExtensionMemberResolver {
|
|||
substitution,
|
||||
);
|
||||
|
||||
if (receiverType.isVoid) {
|
||||
if (receiverType is VoidType) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.USE_OF_VOID_RESULT, receiverExpression);
|
||||
} else if (!_typeSystem.isAssignableTo(receiverType, extendedType)) {
|
||||
|
|
|
@ -127,7 +127,7 @@ class LegacyTypeAsserter extends GeneralizingAstVisitor<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (type.isDynamic || type.isVoid) {
|
||||
if (type.isDynamic || type is VoidType) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class PropertyElementResolver with ScopeHelpers {
|
|||
var targetType = target.typeOrThrow;
|
||||
targetType = _typeSystem.resolveToBound(targetType);
|
||||
|
||||
if (targetType.isVoid) {
|
||||
if (targetType is VoidType) {
|
||||
// TODO(scheglov) Report directly in TypePropertyResolver?
|
||||
_reportUnresolvedIndex(
|
||||
node,
|
||||
|
@ -431,7 +431,7 @@ class PropertyElementResolver with ScopeHelpers {
|
|||
);
|
||||
}
|
||||
|
||||
if (targetType.isVoid) {
|
||||
if (targetType is VoidType) {
|
||||
errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.USE_OF_VOID_RESULT,
|
||||
propertyName,
|
||||
|
|
|
@ -1579,12 +1579,13 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
if (returnType == null) return;
|
||||
|
||||
bool isReturnVoid;
|
||||
if (returnType.isVoid) {
|
||||
if (returnType is VoidType) {
|
||||
isReturnVoid = true;
|
||||
} else if (returnType is ParameterizedType &&
|
||||
(returnType.isDartAsyncFuture || returnType.isDartAsyncFutureOr)) {
|
||||
var typeArguments = returnType.typeArguments;
|
||||
isReturnVoid = typeArguments.length == 1 && typeArguments.first.isVoid;
|
||||
isReturnVoid =
|
||||
typeArguments.length == 1 && typeArguments.first is VoidType;
|
||||
} else {
|
||||
isReturnVoid = false;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class LiteralElementVerifier {
|
|||
void _verifyElement(CollectionElement? element) {
|
||||
if (element is Expression) {
|
||||
if (forList || forSet) {
|
||||
if (!elementType!.isVoid &&
|
||||
if (elementType is! VoidType &&
|
||||
_errorVerifier.checkForUseOfVoidResult(element)) {
|
||||
return;
|
||||
}
|
||||
|
@ -103,14 +103,14 @@ class LiteralElementVerifier {
|
|||
/// Verify that the [entry]'s key and value are assignable to [mapKeyType]
|
||||
/// and [mapValueType].
|
||||
void _verifyMapLiteralEntry(MapLiteralEntry entry) {
|
||||
var mapKeyType = this.mapKeyType;
|
||||
if (!mapKeyType!.isVoid &&
|
||||
var mapKeyType = this.mapKeyType!;
|
||||
if (mapKeyType is! VoidType &&
|
||||
_errorVerifier.checkForUseOfVoidResult(entry.key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var mapValueType = this.mapValueType;
|
||||
if (!mapValueType!.isVoid &&
|
||||
var mapValueType = this.mapValueType!;
|
||||
if (mapValueType is! VoidType &&
|
||||
_errorVerifier.checkForUseOfVoidResult(entry.value)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class ReturnTypeVerifier {
|
|||
|
||||
void verifyExpressionFunctionBody(ExpressionFunctionBody node) {
|
||||
// This enables concise declarations of void functions.
|
||||
if (_flattenedReturnType.isVoid) {
|
||||
if (_flattenedReturnType is VoidType) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ class ReturnTypeVerifier {
|
|||
// It is a compile-time error if the declared return type of
|
||||
// a function marked `sync*` or `async*` is `void`.
|
||||
if (enclosingExecutable.isGenerator) {
|
||||
if (enclosingExecutable.returnType.isVoid) {
|
||||
if (enclosingExecutable.returnType is VoidType) {
|
||||
return reportError();
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ class ReturnTypeVerifier {
|
|||
if (enclosingExecutable.isSynchronous) {
|
||||
// It is a compile-time error if `T` is `void`,
|
||||
// and `S` is neither `void`, `dynamic`, nor `Null`.
|
||||
if (T.isVoid) {
|
||||
if (T is VoidType) {
|
||||
if (!_isVoidDynamicOrNull(S)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -210,7 +210,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `S` is `void`,
|
||||
// and `T` is neither `void`, `dynamic`, nor `Null`.
|
||||
if (S.isVoid) {
|
||||
if (S is VoidType) {
|
||||
if (!_isVoidDynamicOrNull(T)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -218,7 +218,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `S` is not `void`,
|
||||
// and `S` is not assignable to `T`.
|
||||
if (!S.isVoid) {
|
||||
if (S is! VoidType) {
|
||||
if (!_typeSystem.isAssignableTo(S, T)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -238,7 +238,7 @@ class ReturnTypeVerifier {
|
|||
// implementing it now would be a breaking change. So, the code below
|
||||
// intentionally does not implement the specification.
|
||||
// https://github.com/dart-lang/sdk/issues/41803#issuecomment-635852474
|
||||
if (T.isVoid) {
|
||||
if (T is VoidType) {
|
||||
if (!_isVoidDynamicOrNull(flatten_S)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -246,7 +246,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `flatten(S)` is `void`,
|
||||
// and `flatten(T)` is neither `void`, `dynamic`, nor `Null`.
|
||||
if (flatten_S.isVoid) {
|
||||
if (flatten_S is VoidType) {
|
||||
if (!_isVoidDynamicOrNull(flatten_T)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -254,7 +254,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `flatten(S)` is not `void`,
|
||||
// and `Future<flatten(S)>` is not assignable to `T`.
|
||||
if (!flatten_S.isVoid) {
|
||||
if (flatten_S is! VoidType) {
|
||||
var future_flatten_S = _typeProvider.futureType(flatten_S);
|
||||
if (!_typeSystem.isAssignableTo(future_flatten_S, T)) {
|
||||
reportTypeError();
|
||||
|
@ -321,7 +321,7 @@ class ReturnTypeVerifier {
|
|||
if (enclosingExecutable.isSynchronous) {
|
||||
// It is a compile-time error if `T` is `void`,
|
||||
// and `S` is neither `void`, `dynamic`, nor `Null`.
|
||||
if (T.isVoid) {
|
||||
if (T is VoidType) {
|
||||
if (!_isVoidDynamicOrNull(S)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -329,7 +329,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `S` is `void`,
|
||||
// and `T` is neither `void` nor `dynamic`.
|
||||
if (S.isVoid) {
|
||||
if (S is VoidType) {
|
||||
if (!_isVoidDynamic(T)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -337,7 +337,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `S` is not `void`,
|
||||
// and `S` is not assignable to `T`.
|
||||
if (!S.isVoid) {
|
||||
if (S is! VoidType) {
|
||||
if (T is RecordType) {
|
||||
if (S is! RecordType && T.positionalFields.length == 1) {
|
||||
var field = T.positionalFields.first;
|
||||
|
@ -366,7 +366,7 @@ class ReturnTypeVerifier {
|
|||
var flatten_S = _typeSystem.flatten(S);
|
||||
// It is a compile-time error if `flatten(T)` is `void`,
|
||||
// and `flatten(S)` is neither `void`, `dynamic`, nor `Null`.
|
||||
if (T_v.isVoid) {
|
||||
if (T_v is VoidType) {
|
||||
if (!_isVoidDynamicOrNull(flatten_S)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -374,7 +374,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `flatten(S)` is `void`,
|
||||
// and `flatten(T)` is neither `void`, `dynamic`.
|
||||
if (flatten_S.isVoid) {
|
||||
if (flatten_S is VoidType) {
|
||||
if (!_isVoidDynamic(T_v)) {
|
||||
reportTypeError();
|
||||
return;
|
||||
|
@ -382,7 +382,7 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
// It is a compile-time error if `flatten(S)` is not `void`,
|
||||
// and `Future<flatten(S)>` is not assignable to `T`.
|
||||
if (!flatten_S.isVoid) {
|
||||
if (flatten_S is! VoidType) {
|
||||
if (!_typeSystem.isAssignableTo(S, T_v) &&
|
||||
!_typeSystem.isSubtypeOf(flatten_S, T_v)) {
|
||||
reportTypeError();
|
||||
|
@ -448,10 +448,10 @@ class ReturnTypeVerifier {
|
|||
}
|
||||
|
||||
static bool _isVoidDynamic(DartType type) {
|
||||
return type.isVoid || type.isDynamic;
|
||||
return type is VoidType || type.isDynamic;
|
||||
}
|
||||
|
||||
static bool _isVoidDynamicOrNull(DartType type) {
|
||||
return type.isVoid || type.isDynamic || type.isDartCoreNull;
|
||||
return type is VoidType || type.isDynamic || type.isDartCoreNull;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ mixin ErrorDetectionHelpers {
|
|||
DartType actualStaticType,
|
||||
ErrorCode errorCode,
|
||||
{Map<DartType, NonPromotionReason> Function()? whyNotPromoted}) {
|
||||
if (!expectedStaticType.isVoid && checkForUseOfVoidResult(expression)) {
|
||||
if (expectedStaticType is! VoidType &&
|
||||
checkForUseOfVoidResult(expression)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,8 @@ mixin ErrorDetectionHelpers {
|
|||
DartType expectedStaticType,
|
||||
ErrorCode errorCode,
|
||||
{Map<DartType, NonPromotionReason> Function()? whyNotPromoted}) {
|
||||
if (!expectedStaticType.isVoid && checkForUseOfVoidResult(expression)) {
|
||||
if (expectedStaticType is! VoidType &&
|
||||
checkForUseOfVoidResult(expression)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -123,7 +125,7 @@ mixin ErrorDetectionHelpers {
|
|||
// test the static type of the expression
|
||||
DartType staticType = expression.typeOrThrow;
|
||||
if (typeSystem.isAssignableTo(staticType, fieldType)) {
|
||||
if (!fieldType.isVoid) {
|
||||
if (fieldType is! VoidType) {
|
||||
checkForUseOfVoidResult(expression);
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -4024,7 +4024,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
var annotation = declaration.returnType;
|
||||
if (annotation != null) {
|
||||
DartType type = annotation.typeOrThrow;
|
||||
if (!type.isVoid) {
|
||||
if (type is! VoidType) {
|
||||
errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.NON_VOID_RETURN_FOR_OPERATOR, annotation);
|
||||
}
|
||||
|
@ -4038,7 +4038,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
void _checkForNonVoidReturnTypeForSetter(TypeAnnotation? namedType) {
|
||||
if (namedType != null) {
|
||||
DartType type = namedType.typeOrThrow;
|
||||
if (!type.isVoid) {
|
||||
if (type is! VoidType) {
|
||||
errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.NON_VOID_RETURN_FOR_SETTER, namedType);
|
||||
}
|
||||
|
|
|
@ -899,8 +899,8 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
} else if (nativeReturnType == _PrimitiveDartType.bool) {
|
||||
return dartType.isDartCoreBool;
|
||||
} else if (nativeReturnType == _PrimitiveDartType.void_) {
|
||||
return dartType.isVoid;
|
||||
} else if (dartType.isVoid) {
|
||||
return dartType is VoidType;
|
||||
} else if (dartType is VoidType) {
|
||||
// Don't allow other native subtypes if the Dart return type is void.
|
||||
return nativeReturnType == _PrimitiveDartType.void_;
|
||||
} else if (nativeReturnType == _PrimitiveDartType.handle) {
|
||||
|
@ -1077,7 +1077,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
|
||||
// TODO(brianwilkerson) Validate that `f` is a top-level function.
|
||||
final DartType R = (T as FunctionType).returnType;
|
||||
if ((FT as FunctionType).returnType.isVoid ||
|
||||
if ((FT as FunctionType).returnType is VoidType ||
|
||||
R.isPointer ||
|
||||
R.isHandle ||
|
||||
R.isCompoundSubtype) {
|
||||
|
|
|
@ -620,7 +620,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
errorCode = CompileTimeErrorCode.BODY_MIGHT_COMPLETE_NORMALLY;
|
||||
} else {
|
||||
var returnTypeBase = typeSystem.futureOrBase(returnType);
|
||||
if (returnTypeBase.isVoid ||
|
||||
if (returnTypeBase is VoidType ||
|
||||
returnTypeBase.isDynamic ||
|
||||
returnTypeBase.isDartCoreNull) {
|
||||
return;
|
||||
|
@ -3610,7 +3610,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
|||
final targetFutureType = instanceOfFuture.typeArguments.first;
|
||||
final expectedReturnType = typeProvider.futureOrType(targetFutureType);
|
||||
final returnTypeBase = typeSystem.futureOrBase(expectedReturnType);
|
||||
if (returnTypeBase.isVoid ||
|
||||
if (returnTypeBase is VoidType ||
|
||||
returnTypeBase.isDynamic ||
|
||||
returnTypeBase.isDartCoreNull) {
|
||||
return;
|
||||
|
|
|
@ -649,7 +649,7 @@ class CodeChecker extends RecursiveAstVisitor {
|
|||
bool? _needsImplicitCast(SyntacticEntity expr,
|
||||
{required DartType from, required DartType to}) {
|
||||
// Void is considered Top, but may only be *explicitly* cast.
|
||||
if (from.isVoid) return null;
|
||||
if (from is VoidType) return null;
|
||||
|
||||
if (to is FunctionType) {
|
||||
var needsCast = _checkFunctionTypeCasts(to, from);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: analyzer
|
||||
version: 5.7.1
|
||||
version: 5.8.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
|
||||
|
|
|
@ -2015,6 +2015,7 @@ class VoidTypeImplTest extends AbstractTypeSystemTest {
|
|||
/// Reference {code VoidTypeImpl.getInstance()}.
|
||||
final DartType _voidType = VoidTypeImpl.instance;
|
||||
|
||||
@deprecated
|
||||
void test_isVoid() {
|
||||
expect(_voidType.isVoid, isTrue);
|
||||
}
|
||||
|
|
|
@ -484,7 +484,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
|
|||
selectHere();
|
||||
writeln();
|
||||
}
|
||||
} else if (returnType.isVoid) {
|
||||
} else if (returnType is VoidType) {
|
||||
if (invokeSuper) {
|
||||
writeln();
|
||||
write(prefix2);
|
||||
|
|
|
@ -256,7 +256,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor<void> {
|
|||
if (0 <= index && index < parameters.length) {
|
||||
var param = parameters[index];
|
||||
var paramType = param.type;
|
||||
if (paramType is FunctionType && paramType.returnType.isVoid) {
|
||||
if (paramType is FunctionType && paramType.returnType is VoidType) {
|
||||
optype.includeVoidReturnSuggestions = true;
|
||||
}
|
||||
if (param.isNamed == true) {
|
||||
|
@ -574,7 +574,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor<void> {
|
|||
if (parent is FunctionExpression) {
|
||||
type = parent.staticType;
|
||||
if (type is FunctionType) {
|
||||
if (type.returnType.isVoid) {
|
||||
if (type.returnType is VoidType) {
|
||||
// TODO(brianwilkerson) Determine whether the return type can ever
|
||||
// be inferred as void and remove this case if it can't be.
|
||||
optype.includeVoidReturnSuggestions = true;
|
||||
|
@ -585,7 +585,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor<void> {
|
|||
if (parameter != null) {
|
||||
var parameterType = parameter.type;
|
||||
if (parameterType is FunctionType &&
|
||||
parameterType.returnType.isVoid) {
|
||||
parameterType.returnType is VoidType) {
|
||||
optype.includeVoidReturnSuggestions = true;
|
||||
}
|
||||
}
|
||||
|
@ -594,7 +594,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor<void> {
|
|||
}
|
||||
} else if (parent is MethodDeclaration) {
|
||||
type = parent.declaredElement?.returnType;
|
||||
if (type != null && type.isVoid) {
|
||||
if (type != null && type is VoidType) {
|
||||
optype.includeVoidReturnSuggestions = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class InheritedReferenceContributor
|
|||
}
|
||||
}
|
||||
for (var elem in type.methods) {
|
||||
if (!elem.returnType.isVoid) {
|
||||
if (elem.returnType is! VoidType) {
|
||||
if (optype.includeReturnValueSuggestions) {
|
||||
addSuggestion(elem);
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ 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.isVoid || type.isDynamic) {
|
||||
if (type is VoidType || type.isDynamic) {
|
||||
var node = NullabilityNode.forAlreadyMigrated(target);
|
||||
_graph.makeNullableUnion(
|
||||
node, AlwaysNullableTypeOrigin.forElement(element, type.isVoid));
|
||||
node, AlwaysNullableTypeOrigin.forElement(element, type is VoidType));
|
||||
return DecoratedType(type, node);
|
||||
}
|
||||
NullabilityNode node;
|
||||
|
|
|
@ -450,7 +450,7 @@ class DecoratedType implements DecoratedTypeInfo, SubstitutedType {
|
|||
} else {
|
||||
return inner._performSubstitution(this, undecoratedResult!);
|
||||
}
|
||||
} else if (type!.isVoid || type.isDynamic) {
|
||||
} else if (type is VoidType || type!.isDynamic) {
|
||||
return this;
|
||||
}
|
||||
throw '$type.substitute($type | $substitution)'; // TODO(paulberry)
|
||||
|
|
|
@ -2273,7 +2273,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
? NullabilityNode.forLUB(left.node, right.node)
|
||||
: _nullabilityNodeForGLB(astNode, left.node, right.node);
|
||||
|
||||
if (type!.isDynamic || type.isVoid) {
|
||||
if (type!.isDynamic || type is VoidType) {
|
||||
return DecoratedType(type, node);
|
||||
} else if (leftType!.isBottom) {
|
||||
return right.withNode(node);
|
||||
|
@ -3905,7 +3905,7 @@ mixin _AssignmentChecker {
|
|||
return;
|
||||
}
|
||||
} else if (destinationType.isDynamic ||
|
||||
destinationType.isVoid ||
|
||||
destinationType is VoidType ||
|
||||
destinationType.isDartCoreObject) {
|
||||
// No further edges need to be created, since all types are trivially
|
||||
// subtypes of dynamic, Object, and void, since all are treated as
|
||||
|
@ -3979,7 +3979,7 @@ mixin _AssignmentChecker {
|
|||
|
||||
if (sourceType.isDynamic ||
|
||||
sourceType.isDartCoreObject ||
|
||||
sourceType.isVoid) {
|
||||
sourceType is VoidType) {
|
||||
if (destinationType is InterfaceType) {
|
||||
for (final param in destinationType.element.typeParameters) {
|
||||
assert(param.bound == null,
|
||||
|
|
|
@ -1460,7 +1460,7 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor<void>
|
|||
}
|
||||
|
||||
bool _typeIsNaturallyNullable(DartType type) =>
|
||||
type.isDynamic || type.isVoid || type.isDartCoreNull;
|
||||
type.isDynamic || type is VoidType || type.isDartCoreNull;
|
||||
}
|
||||
|
||||
/// Specialization of [_AssignmentLikeExpressionHandler] for
|
||||
|
|
|
@ -531,7 +531,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
DecoratedType visitTypeAnnotation(TypeAnnotation node) {
|
||||
var type = node.type!;
|
||||
var target = safeTarget.withCodeRef(node);
|
||||
if (type.isVoid || type.isDynamic) {
|
||||
if (type is VoidType || type.isDynamic) {
|
||||
var nullabilityNode = NullabilityNode.forTypeAnnotation(target);
|
||||
var decoratedType = DecoratedType(type, nullabilityNode);
|
||||
_variables.recordDecoratedTypeAnnotation(source, node, decoratedType);
|
||||
|
|
|
@ -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.isVoid || type.isDynamic) return type;
|
||||
if (type is VoidType || type.isDynamic) return type;
|
||||
if (type is NeverType) {
|
||||
if (decoratedType.node.isNullable) {
|
||||
return (_typeProvider.nullType as TypeImpl)
|
||||
|
|
Loading…
Reference in a new issue