Skip to content

Commit

Permalink
Version 3.4.0-107.0.dev
Browse files Browse the repository at this point in the history
Merge 6f83936 into dev
  • Loading branch information
Dart CI committed Feb 3, 2024
2 parents 0ee50c7 + 6f83936 commit e2ae399
Show file tree
Hide file tree
Showing 52 changed files with 534 additions and 972 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class PostfixCompletionProcessor {
_findOuterExpression(node, typeProvider.iterableDynamicType);

Expression? findObjectExpression() =>
_findOuterExpression(node, typeProvider.objectType);
_findOuterExpression(node, typeProvider.objectQuestionType);

Statement? findStatement() {
var astNode = node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,6 @@ f() {

@reflectiveTest
class _NotNullTest extends PostfixCompletionTest {
@override
String get testPackageLanguageVersion => '2.9';

Future<void> test_nn() async {
await _prepareCompletion('.nn', '''
f() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,16 @@ class ConvertToWhereTypeTest extends FixProcessorLintTest {
@override
String get lintCode => LintNames.prefer_iterable_whereType;

@override
String get testPackageLanguageVersion => '2.9';

Future<void> test_default_declaredType() async {
await resolveTestCode('''
Iterable<C> f(List<Object> list) {
return list.where((e) => e is C);
Iterable<Object?> f(List<Object> list) {
return list.where((e) => e is int);
}
class C {}
''');
await assertHasFix('''
Iterable<C> f(List<Object> list) {
return list.whereType<C>();
Iterable<Object?> f(List<Object> list) {
return list.whereType<int>();
}
class C {}
''');
}
}
53 changes: 15 additions & 38 deletions pkg/analyzer/lib/src/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ class AnalysisContextImpl implements AnalysisContext {
@override
final SourceFactory sourceFactory;

TypeProviderImpl? _typeProviderLegacy;
TypeProviderImpl? _typeProviderNonNullableByDefault;

TypeSystemImpl? _typeSystemLegacy;
TypeSystemImpl? _typeSystemNonNullableByDefault;
TypeProviderImpl? _typeProvider;
TypeSystemImpl? _typeSystem;

AnalysisContextImpl({
required AnalysisOptionsMap analysisOptionsMap,
Expand All @@ -44,57 +41,37 @@ class AnalysisContextImpl implements AnalysisContext {
}

bool get hasTypeProvider {
return _typeProviderNonNullableByDefault != null;
}

TypeProviderImpl get typeProviderLegacy {
return _typeProviderLegacy!;
}

TypeProviderImpl get typeProviderNonNullableByDefault {
return _typeProviderNonNullableByDefault!;
return _typeProvider != null;
}

TypeSystemImpl get typeSystemLegacy {
return _typeSystemLegacy!;
TypeProviderImpl get typeProvider {
return _typeProvider!;
}

TypeSystemImpl get typeSystemNonNullableByDefault {
return _typeSystemNonNullableByDefault!;
TypeSystemImpl get typeSystem {
return _typeSystem!;
}

void clearTypeProvider() {
_typeProviderLegacy = null;
_typeProviderNonNullableByDefault = null;

_typeSystemLegacy = null;
_typeSystemNonNullableByDefault = null;
_typeProvider = null;
_typeSystem = null;
}

@override
AnalysisOptionsImpl getAnalysisOptionsForFile(File file) =>
_analysisOptionsMap.getOptions(file);

void setTypeProviders({
required TypeProviderImpl legacy,
required TypeProviderImpl nonNullableByDefault,
required TypeProviderImpl typeProvider,
}) {
if (_typeProviderLegacy != null ||
_typeProviderNonNullableByDefault != null) {
throw StateError('TypeProvider(s) can be set only once.');
if (_typeProvider != null) {
throw StateError('TypeProvider can be set only once.');
}

_typeSystemLegacy = TypeSystemImpl(
isNonNullableByDefault: false,
typeProvider: legacy,
);
_typeProvider = typeProvider;

_typeSystemNonNullableByDefault = TypeSystemImpl(
isNonNullableByDefault: true,
typeProvider: nonNullableByDefault,
_typeSystem = TypeSystemImpl(
typeProvider: typeProvider,
);

_typeProviderLegacy = legacy;
_typeProviderNonNullableByDefault = nonNullableByDefault;
}
}
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 337;
static const int DATA_VERSION = 338;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/dart/constant/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ class DartObjectImpl implements DartObject, Constant {
DartObjectImpl isIdentical(
TypeProvider typeProvider, DartObjectImpl rightOperand) {
var typeSystem = TypeSystemImpl(
isNonNullableByDefault: false,
typeProvider: typeProvider,
);
return isIdentical2(typeSystem, rightOperand);
Expand Down
62 changes: 19 additions & 43 deletions pkg/analyzer/lib/src/dart/element/generic_inferrer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class GenericInferrer {
}
}

bool get isNonNullableByDefault => _typeSystem.isNonNullableByDefault;

TypeProviderImpl get typeProvider => _typeSystem.typeProvider;

/// Performs upwards inference, producing a final set of inferred types that
Expand All @@ -140,7 +138,6 @@ class GenericInferrer {
parameterType,
parameterName,
genericClass: genericClass,
isNonNullableByDefault: isNonNullableByDefault,
);
_tryMatchSubtypeOf(argumentType, parameterType, origin, covariant: false);
}
Expand All @@ -167,11 +164,7 @@ class GenericInferrer {
/// [contextType].
void constrainGenericFunctionInContext(
FunctionType fnType, DartType contextType) {
var origin = _TypeConstraintFromFunctionContext(
fnType,
contextType,
isNonNullableByDefault: isNonNullableByDefault,
);
var origin = _TypeConstraintFromFunctionContext(fnType, contextType);

// Since we're trying to infer the instantiation, we want to ignore type
// formals as we check the parameters and return type.
Expand All @@ -187,11 +180,7 @@ class GenericInferrer {
/// Apply a return type constraint, which asserts that the [declaredType]
/// is a subtype of the [contextType].
void constrainReturnType(DartType declaredType, DartType contextType) {
var origin = _TypeConstraintFromReturnType(
declaredType,
contextType,
isNonNullableByDefault: isNonNullableByDefault,
);
var origin = _TypeConstraintFromReturnType(declaredType, contextType);
_tryMatchSubtypeOf(declaredType, contextType, origin, covariant: true);
}

Expand Down Expand Up @@ -222,7 +211,6 @@ class GenericInferrer {
parameter,
parameterBoundRaw,
parameterBound,
isNonNullableByDefault: isNonNullableByDefault,
);
constraints.add(extendsConstraint);
success = extendsConstraint.isSatisfiedBy(_typeSystem, inferred);
Expand Down Expand Up @@ -450,11 +438,11 @@ class GenericInferrer {
var bound = typeParam.bound;
if (bound != null) {
extendsClause = _TypeConstraint.fromExtends(
typeParam,
bound,
Substitution.fromPairs(_typeFormals, inferredTypes)
.substituteType(bound),
isNonNullableByDefault: isNonNullableByDefault);
typeParam,
bound,
Substitution.fromPairs(_typeFormals, inferredTypes)
.substituteType(bound),
);
}

var constraints = _constraints[typeParam]!;
Expand All @@ -481,13 +469,13 @@ class GenericInferrer {
}

String _elementStr(Element element) {
return element.getDisplayString(withNullability: isNonNullableByDefault);
return element.getDisplayString(withNullability: true);
}

String _formatError(TypeParameterElement typeParam, DartType inferred,
Iterable<_TypeConstraint> constraints) {
var inferredStr = inferred.getDisplayString(
withNullability: isNonNullableByDefault,
withNullability: true,
);
var intro = "Tried to infer '$inferredStr' for '${typeParam.name}'"
" which doesn't work:";
Expand Down Expand Up @@ -553,10 +541,8 @@ class GenericInferrer {
}

void _nonNullifyTypes(List<DartType> types) {
if (_typeSystem.isNonNullableByDefault) {
for (var i = 0; i < types.length; i++) {
types[i] = _typeSystem.nonNullifyLegacy(types[i]);
}
for (var i = 0; i < types.length; i++) {
types[i] = _typeSystem.nonNullifyLegacy(types[i]);
}
for (var i = 0; i < types.length; i++) {
types[i] = _typeSystem.demoteType(types[i]);
Expand Down Expand Up @@ -632,8 +618,7 @@ class GenericInferrer {
} else if (errorNode is Expression) {
var type = errorNode.staticType;
if (type != null) {
var typeDisplayString = type.getDisplayString(
withNullability: _typeSystem.isNonNullableByDefault);
var typeDisplayString = _typeStr(type);
errorReporter.atNode(
errorNode,
WarningCode.INFERENCE_FAILURE_ON_GENERIC_INVOCATION,
Expand Down Expand Up @@ -675,7 +660,7 @@ class GenericInferrer {
}

String _typeStr(DartType type) {
return type.getDisplayString(withNullability: isNonNullableByDefault);
return type.getDisplayString(withNullability: true);
}

static String _formatConstraints(Iterable<_TypeConstraint> constraints) {
Expand Down Expand Up @@ -717,14 +702,12 @@ class _TypeConstraint extends _TypeRange {
_TypeConstraint(this.origin, this.typeParameter, {super.upper, super.lower});

_TypeConstraint.fromExtends(
TypeParameterElement element, DartType boundType, DartType extendsType,
{required bool isNonNullableByDefault})
TypeParameterElement element, DartType boundType, DartType extendsType)
: this(
_TypeConstraintFromExtendsClause(
element,
boundType,
extendsType,
isNonNullableByDefault: isNonNullableByDefault,
),
element,
upper: extendsType);
Expand All @@ -748,7 +731,7 @@ class _TypeConstraintFromArgument extends _TypeConstraintOrigin {

_TypeConstraintFromArgument(
this.argumentType, this.parameterType, this.parameterName,
{this.genericClass, required super.isNonNullableByDefault});
{this.genericClass});

@override
List<String> formatError() {
Expand Down Expand Up @@ -793,8 +776,7 @@ class _TypeConstraintFromExtendsClause extends _TypeConstraintOrigin {
final DartType extendsType;

_TypeConstraintFromExtendsClause(
this.typeParam, this.boundType, this.extendsType,
{required super.isNonNullableByDefault});
this.typeParam, this.boundType, this.extendsType);

@override
List<String> formatError() {
Expand All @@ -811,8 +793,7 @@ class _TypeConstraintFromFunctionContext extends _TypeConstraintOrigin {
final DartType contextType;
final DartType functionType;

_TypeConstraintFromFunctionContext(this.functionType, this.contextType,
{required super.isNonNullableByDefault});
_TypeConstraintFromFunctionContext(this.functionType, this.contextType);

@override
List<String> formatError() {
Expand All @@ -828,8 +809,7 @@ class _TypeConstraintFromReturnType extends _TypeConstraintOrigin {
final DartType contextType;
final DartType declaredType;

_TypeConstraintFromReturnType(this.declaredType, this.contextType,
{required super.isNonNullableByDefault});
_TypeConstraintFromReturnType(this.declaredType, this.contextType);

@override
List<String> formatError() {
Expand All @@ -845,14 +825,10 @@ class _TypeConstraintFromReturnType extends _TypeConstraintOrigin {
/// readable error message during type inference as well as determining whether
/// the constraint was used to fix the type parameter or not.
abstract class _TypeConstraintOrigin {
final bool isNonNullableByDefault;

_TypeConstraintOrigin({required this.isNonNullableByDefault});

List<String> formatError();

String _typeStr(DartType type) {
return type.getDisplayString(withNullability: isNonNullableByDefault);
return type.getDisplayString(withNullability: true);
}
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/analyzer/lib/src/dart/element/least_upper_bound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,6 @@ class LeastUpperBoundHelper {
if (bound != null) {
return bound;
}
return _typeSystem.isNonNullableByDefault
? _typeSystem.objectQuestion
: _typeSystem.objectStar;
return _typeSystem.objectQuestion;
}
}
34 changes: 9 additions & 25 deletions pkg/analyzer/lib/src/dart/element/replace_top_bottom_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,17 @@ class ReplaceTopBottomVisitor {
);

DartType process(DartType type, Variance variance) {
if (_typeSystem.isNonNullableByDefault) {
if (variance.isContravariant) {
// ...replacing every occurrence in `T` of a type `S` in a contravariant
// position where `S <: Never` by `Object?`
if (_typeSystem.isSubtypeOf(type, NeverTypeImpl.instance)) {
return _topType;
}
} else {
// ...and every occurrence in `T` of a top type in a position which
// is not contravariant by `Never`.
if (_typeSystem.isTop(type)) {
return _bottomType;
}
if (variance.isContravariant) {
// ...replacing every occurrence in `T` of a type `S` in a contravariant
// position where `S <: Never` by `Object?`
if (_typeSystem.isSubtypeOf(type, NeverTypeImpl.instance)) {
return _topType;
}
} else {
if (variance.isCovariant) {
// ...replacing every occurrence in `T` of a top type in a covariant
// position by `Null`
if (_typeSystem.isTop(type)) {
return _bottomType;
}
} else if (variance.isContravariant) {
// ...and every occurrence in `T` of `Null` in a contravariant
// position by `Object`
if (type.isDartCoreNull) {
return _topType;
}
// ...and every occurrence in `T` of a top type in a position which
// is not contravariant by `Never`.
if (_typeSystem.isTop(type)) {
return _bottomType;
}
}

Expand Down
Loading

0 comments on commit e2ae399

Please sign in to comment.