Skip to content

Commit ccc39d5

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
For FunctionExpression inference check for null subtype explicitly.
Change-Id: Ie724d8227c2e5bade8924d0d8e25b00ac0b9367e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151001 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent f46efc7 commit ccc39d5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ class FunctionExpressionResolver {
9494
// Check that there is no declared type, and that we have not already
9595
// inferred a type in some fashion.
9696
if (p.hasImplicitType && (p.type == null || p.type.isDynamic)) {
97+
// If no type is declared for a parameter and there is a
98+
// corresponding parameter in the context type schema with type
99+
// schema `K`, the parameter is given an inferred type `T` where `T`
100+
// is derived from `K` as follows.
97101
inferredType = _typeSystem.greatestClosure(inferredType);
98-
if (inferredType.isDartCoreNull || inferredType is NeverTypeImpl) {
102+
103+
// If the greatest closure of `K` is `S` and `S` is a subtype of
104+
// `Null`, then `T` is `Object?`. Otherwise, `T` is `S`.
105+
if (_typeSystem.isSubtypeOf2(inferredType, _typeSystem.nullNone)) {
99106
inferredType = _isNonNullableByDefault
100107
? _typeSystem.objectQuestion
101108
: _typeSystem.objectStar;

0 commit comments

Comments
 (0)