Skip to content

Commit 617d0a8

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[model] Remove more nullability-related assignability error messages
This is a preparation for removing the subtype checking procedure that ignores the nullability in the input types. Change-Id: I3c1db55abde0433e9059d949f1c98aaeb61e210c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428980 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Erik Ernst <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 4a63257 commit 617d0a8

File tree

133 files changed

+1316
-2553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1316
-2553
lines changed

pkg/front_end/lib/src/codes/cfe_codes_generated.dart

Lines changed: 80 additions & 891 deletions
Large diffs are not rendered by default.

pkg/front_end/lib/src/type_inference/closure_context.dart

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,7 @@ class _SyncClosureContext implements ClosureContext {
219219
_returnContext, expressionType, statement.expression!,
220220
fileOffset: statement.expression!.fileOffset,
221221
isVoidAllowed: true,
222-
errorTemplate: templateInvalidReturn,
223-
nullabilityErrorTemplate: templateInvalidReturnNullability,
224-
nullabilityPartErrorTemplate: templateInvalidReturnPartNullability,
225-
nullabilityNullErrorTemplate: templateInvalidReturnNullabilityNull,
226-
nullabilityNullTypeErrorTemplate:
227-
templateInvalidReturnNullabilityNullType);
222+
errorTemplate: templateInvalidReturn);
228223
statement.expression = expression..parent = statement;
229224
}
230225
}
@@ -491,14 +486,7 @@ class _AsyncClosureContext implements ClosureContext {
491486
inferrer.computeGreatestClosure2(_returnContext),
492487
declaredContextType: returnType,
493488
isVoidAllowed: false,
494-
errorTemplate: templateInvalidReturnAsync,
495-
nullabilityErrorTemplate: templateInvalidReturnAsyncNullability,
496-
nullabilityPartErrorTemplate:
497-
templateInvalidReturnAsyncPartNullability,
498-
nullabilityNullErrorTemplate:
499-
templateInvalidReturnAsyncNullabilityNull,
500-
nullabilityNullTypeErrorTemplate:
501-
templateInvalidReturnAsyncNullabilityNullType)
489+
errorTemplate: templateInvalidReturnAsync)
502490
..parent = statement;
503491
}
504492
}

pkg/front_end/lib/src/type_inference/for_in.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ class LocalForInVariable implements ForInVariable {
6060
Expression rhs = visitor.ensureAssignable(
6161
variableType, rhsType, variableSet.value,
6262
errorTemplate: templateForInLoopElementTypeNotAssignable,
63-
nullabilityErrorTemplate:
64-
templateForInLoopElementTypeNotAssignableNullability,
65-
nullabilityPartErrorTemplate:
66-
templateForInLoopElementTypeNotAssignablePartNullability,
6763
isVoidAllowed: true);
6864

6965
variableSet.value = rhs..parent = variableSet;
@@ -141,10 +137,6 @@ class PropertyForInVariable implements ForInVariable {
141137
Expression rhs = visitor.ensureAssignable(
142138
visitor.computeGreatestClosure(_writeType!), rhsType, _rhs!,
143139
errorTemplate: templateForInLoopElementTypeNotAssignable,
144-
nullabilityErrorTemplate:
145-
templateForInLoopElementTypeNotAssignableNullability,
146-
nullabilityPartErrorTemplate:
147-
templateForInLoopElementTypeNotAssignablePartNullability,
148140
isVoidAllowed: true);
149141

150142
propertySet.value = rhs..parent = propertySet;
@@ -179,10 +171,6 @@ class AbstractSuperPropertyForInVariable implements ForInVariable {
179171
rhsType,
180172
superPropertySet.value,
181173
errorTemplate: templateForInLoopElementTypeNotAssignable,
182-
nullabilityErrorTemplate:
183-
templateForInLoopElementTypeNotAssignableNullability,
184-
nullabilityPartErrorTemplate:
185-
templateForInLoopElementTypeNotAssignablePartNullability,
186174
isVoidAllowed: true);
187175
superPropertySet.value = rhs..parent = superPropertySet;
188176
ExpressionInferenceResult result = visitor.inferExpression(
@@ -218,10 +206,6 @@ class SuperPropertyForInVariable implements ForInVariable {
218206
rhsType,
219207
superPropertySet.value,
220208
errorTemplate: templateForInLoopElementTypeNotAssignable,
221-
nullabilityErrorTemplate:
222-
templateForInLoopElementTypeNotAssignableNullability,
223-
nullabilityPartErrorTemplate:
224-
templateForInLoopElementTypeNotAssignablePartNullability,
225209
isVoidAllowed: true);
226210
superPropertySet.value = rhs..parent = superPropertySet;
227211
ExpressionInferenceResult result = visitor.inferExpression(
@@ -247,10 +231,6 @@ class StaticForInVariable implements ForInVariable {
247231
Expression rhs = visitor.ensureAssignable(
248232
setterType, rhsType, staticSet.value,
249233
errorTemplate: templateForInLoopElementTypeNotAssignable,
250-
nullabilityErrorTemplate:
251-
templateForInLoopElementTypeNotAssignableNullability,
252-
nullabilityPartErrorTemplate:
253-
templateForInLoopElementTypeNotAssignablePartNullability,
254234
isVoidAllowed: true);
255235

256236
staticSet.value = rhs..parent = staticSet;
@@ -297,10 +277,6 @@ class ExtensionSetForInVariable implements ForInVariable {
297277
Expression rhs = visitor.ensureAssignable(
298278
setterType!, rhsType, extensionSet.value,
299279
errorTemplate: templateForInLoopElementTypeNotAssignable,
300-
nullabilityErrorTemplate:
301-
templateForInLoopElementTypeNotAssignableNullability,
302-
nullabilityPartErrorTemplate:
303-
templateForInLoopElementTypeNotAssignablePartNullability,
304280
isVoidAllowed: true);
305281

306282
extensionSet.value = rhs..parent = extensionSet;

pkg/front_end/lib/src/type_inference/inference_visitor.dart

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,11 +1624,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase
16241624
variable.type, inferredType, variableGet,
16251625
isVoidAllowed: true,
16261626
fileOffset: parent.fileOffset,
1627-
errorTemplate: templateForInLoopElementTypeNotAssignable,
1628-
nullabilityErrorTemplate:
1629-
templateForInLoopElementTypeNotAssignableNullability,
1630-
nullabilityPartErrorTemplate:
1631-
templateForInLoopElementTypeNotAssignablePartNullability);
1627+
errorTemplate: templateForInLoopElementTypeNotAssignable);
16321628
Statement? expressionEffect;
16331629
if (!identical(implicitDowncast, variableGet)) {
16341630
variable.initializer = implicitDowncast..parent = variable;
@@ -1668,10 +1664,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase
16681664
wrapType(const DynamicType(), iterableClass, Nullability.nonNullable),
16691665
inferredExpressionType,
16701666
iterable,
1671-
errorTemplate: templateForInLoopTypeNotIterable,
1672-
nullabilityErrorTemplate: templateForInLoopTypeNotIterableNullability,
1673-
nullabilityPartErrorTemplate:
1674-
templateForInLoopTypeNotIterablePartNullability);
1667+
errorTemplate: templateForInLoopTypeNotIterable);
16751668
DartType inferredType = const DynamicType();
16761669
if (inferredExpressionType is TypeDeclarationType) {
16771670
// TODO(johnniwinther): Should we use the type of
@@ -1803,10 +1796,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase
18031796
Nullability.nonNullable),
18041797
result.expressionType.unwrapTypeView(),
18051798
iterable,
1806-
errorTemplate: templateForInLoopTypeNotIterable,
1807-
nullabilityErrorTemplate: templateForInLoopTypeNotIterableNullability,
1808-
nullabilityPartErrorTemplate:
1809-
templateForInLoopTypeNotIterablePartNullability);
1799+
errorTemplate: templateForInLoopTypeNotIterable);
18101800
// This is matched by the call to [forEach_end] in
18111801
// [inferElement], [inferMapEntry] or [inferForInStatement].
18121802
flowAnalysis.forEach_bodyBegin(node);
@@ -6774,14 +6764,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase
67746764
DartType contextType =
67756765
rightType.withDeclaredNullability(Nullability.nullable);
67766766
rightResult = ensureAssignableResult(contextType, rightResult,
6777-
errorTemplate: templateArgumentTypeNotAssignable,
6778-
nullabilityErrorTemplate: templateArgumentTypeNotAssignableNullability,
6779-
nullabilityPartErrorTemplate:
6780-
templateArgumentTypeNotAssignablePartNullability,
6781-
nullabilityNullErrorTemplate:
6782-
templateArgumentTypeNotAssignableNullabilityNull,
6783-
nullabilityNullTypeErrorTemplate:
6784-
templateArgumentTypeNotAssignableNullabilityNullType);
6767+
errorTemplate: templateArgumentTypeNotAssignable);
67856768
right = rightResult.expression;
67866769

67876770
FunctionType functionType =

pkg/front_end/lib/src/type_inference/inference_visitor_base.dart

Lines changed: 19 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
349349
bool isVoidAllowed = false,
350350
bool coerceExpression = true,
351351
Template<Message Function(DartType, DartType)>? errorTemplate,
352-
Template<Message Function(DartType, DartType)>? nullabilityErrorTemplate,
353-
Template<Message Function(DartType)>? nullabilityNullErrorTemplate,
354-
Template<Message Function(DartType, DartType)>?
355-
nullabilityNullTypeErrorTemplate,
356-
Template<Message Function(DartType, DartType, DartType, DartType)>?
357-
nullabilityPartErrorTemplate,
358352
Map<SharedTypeView, NonPromotionReason> Function()? whyNotPromoted}) {
359353
return ensureAssignableResult(expectedType,
360354
new ExpressionInferenceResult(expressionType, expression),
@@ -364,10 +358,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
364358
isVoidAllowed: isVoidAllowed,
365359
coerceExpression: coerceExpression,
366360
errorTemplate: errorTemplate,
367-
nullabilityErrorTemplate: nullabilityErrorTemplate,
368-
nullabilityNullErrorTemplate: nullabilityNullErrorTemplate,
369-
nullabilityNullTypeErrorTemplate: nullabilityNullTypeErrorTemplate,
370-
nullabilityPartErrorTemplate: nullabilityPartErrorTemplate,
371361
whyNotPromoted: whyNotPromoted)
372362
.expression;
373363
}
@@ -463,34 +453,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
463453
bool isVoidAllowed = false,
464454
bool isCoercionAllowed = true,
465455
Template<Message Function(DartType, DartType)>? errorTemplate,
466-
Template<Message Function(DartType, DartType)>? nullabilityErrorTemplate,
467-
Template<Message Function(DartType)>? nullabilityNullErrorTemplate,
468-
Template<Message Function(DartType, DartType)>?
469-
nullabilityNullTypeErrorTemplate,
470-
Template<Message Function(DartType, DartType, DartType, DartType)>?
471-
nullabilityPartErrorTemplate,
472456
Map<SharedTypeView, NonPromotionReason> Function()? whyNotPromoted}) {
473-
// [errorTemplate], [nullabilityErrorTemplate], and
474-
// [nullabilityPartErrorTemplate] should be provided together.
475-
assert((errorTemplate == null) == (nullabilityErrorTemplate == null) &&
476-
(nullabilityErrorTemplate == null) ==
477-
(nullabilityPartErrorTemplate == null));
478-
// [nullabilityNullErrorTemplate] and [nullabilityNullTypeErrorTemplate]
479-
// should be provided together.
480-
assert((nullabilityNullErrorTemplate == null) ==
481-
(nullabilityNullTypeErrorTemplate == null));
482457
errorTemplate ??= templateInvalidAssignmentError;
483-
if (nullabilityErrorTemplate == null) {
484-
// Use [templateInvalidAssignmentErrorNullabilityNull] only if no
485-
// specific [nullabilityErrorTemplate] template was passed.
486-
nullabilityNullErrorTemplate ??=
487-
templateInvalidAssignmentErrorNullabilityNull;
488-
}
489-
nullabilityNullTypeErrorTemplate ??= nullabilityErrorTemplate ??
490-
templateInvalidAssignmentErrorNullabilityNullType;
491-
nullabilityErrorTemplate ??= templateInvalidAssignmentErrorNullability;
492-
nullabilityPartErrorTemplate ??=
493-
templateInvalidAssignmentErrorPartNullability;
494458

495459
fileOffset ??= inferenceResult.expression.fileOffset;
496460
contextType = computeGreatestClosure(contextType);
@@ -558,47 +522,29 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
558522
break;
559523
case AssignabilityKind.unassignableNullability:
560524
if (expressionType == assignabilityResult.subtype &&
561-
contextType == assignabilityResult.supertype) {
562-
if (expression is NullLiteral &&
563-
nullabilityNullErrorTemplate != null) {
564-
result = _wrapUnassignableExpression(
565-
expression,
566-
expressionType,
567-
contextType,
568-
nullabilityNullErrorTemplate
569-
.withArguments(declaredContextType ?? contextType));
570-
} else if (expressionType is NullType) {
571-
result = _wrapUnassignableExpression(
572-
expression,
573-
expressionType,
574-
contextType,
575-
nullabilityNullTypeErrorTemplate.withArguments(
576-
expressionType, declaredContextType ?? contextType));
577-
} else {
578-
whyNotPromoted ??= flowAnalysis.whyNotPromoted(expression);
579-
result = _wrapUnassignableExpression(
580-
expression,
581-
expressionType,
582-
contextType,
583-
nullabilityErrorTemplate.withArguments(
584-
expressionType, declaredContextType ?? contextType),
585-
context: getWhyNotPromotedContext(
586-
whyNotPromoted.call(),
587-
expression,
588-
// Coverage-ignore(suite): Not run.
589-
(type) => typeSchemaEnvironment.isSubtypeOf(type,
590-
contextType, SubtypeCheckMode.withNullabilities)));
591-
}
525+
contextType == assignabilityResult.supertype &&
526+
expression is! NullLiteral &&
527+
expressionType is! NullType) {
528+
whyNotPromoted ??= flowAnalysis.whyNotPromoted(expression);
529+
result = _wrapUnassignableExpression(
530+
expression,
531+
expressionType,
532+
contextType,
533+
errorTemplate.withArguments(
534+
expressionType, declaredContextType ?? contextType),
535+
context: getWhyNotPromotedContext(
536+
whyNotPromoted.call(),
537+
expression,
538+
// Coverage-ignore(suite): Not run.
539+
(type) => typeSchemaEnvironment.isSubtypeOf(
540+
type, contextType, SubtypeCheckMode.withNullabilities)));
592541
} else {
593542
result = _wrapUnassignableExpression(
594543
expression,
595544
expressionType,
596545
contextType,
597-
nullabilityPartErrorTemplate.withArguments(
598-
expressionType,
599-
declaredContextType ?? contextType,
600-
assignabilityResult.subtype!,
601-
assignabilityResult.supertype!));
546+
errorTemplate.withArguments(
547+
expressionType, declaredContextType ?? contextType));
602548
}
603549
break;
604550
}
@@ -623,12 +569,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
623569
bool isVoidAllowed = false,
624570
bool coerceExpression = true,
625571
Template<Message Function(DartType, DartType)>? errorTemplate,
626-
Template<Message Function(DartType, DartType)>? nullabilityErrorTemplate,
627-
Template<Message Function(DartType)>? nullabilityNullErrorTemplate,
628-
Template<Message Function(DartType, DartType)>?
629-
nullabilityNullTypeErrorTemplate,
630-
Template<Message Function(DartType, DartType, DartType, DartType)>?
631-
nullabilityPartErrorTemplate,
632572
Map<SharedTypeView, NonPromotionReason> Function()? whyNotPromoted}) {
633573
if (coerceExpression) {
634574
ExpressionInferenceResult? coercionResult = coerceExpressionForAssignment(
@@ -651,10 +591,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
651591
isVoidAllowed: isVoidAllowed,
652592
isCoercionAllowed: coerceExpression,
653593
errorTemplate: errorTemplate,
654-
nullabilityErrorTemplate: nullabilityErrorTemplate,
655-
nullabilityNullErrorTemplate: nullabilityNullErrorTemplate,
656-
nullabilityNullTypeErrorTemplate: nullabilityNullTypeErrorTemplate,
657-
nullabilityPartErrorTemplate: nullabilityPartErrorTemplate,
658594
whyNotPromoted: whyNotPromoted);
659595

660596
return inferenceResult;
@@ -2066,15 +2002,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
20662002
expectedType, argumentResultToCheck,
20672003
isVoidAllowed: expectedType is VoidType,
20682004
isCoercionAllowed: coerceExpression,
2069-
errorTemplate: templateArgumentTypeNotAssignable,
2070-
nullabilityErrorTemplate:
2071-
templateArgumentTypeNotAssignableNullability,
2072-
nullabilityPartErrorTemplate:
2073-
templateArgumentTypeNotAssignablePartNullability,
2074-
nullabilityNullErrorTemplate:
2075-
templateArgumentTypeNotAssignableNullabilityNull,
2076-
nullabilityNullTypeErrorTemplate:
2077-
templateArgumentTypeNotAssignableNullabilityNullType);
2005+
errorTemplate: templateArgumentTypeNotAssignable);
20782006

20792007
argumentExpression = argumentResultToCheck.expression;
20802008
if (namedArgumentExpression == null) {

0 commit comments

Comments
 (0)