Skip to content

Commit 6867425

Browse files
danrubelcommit-bot@chromium.org
authored andcommitted
Migration: add a more robust assertion to the DecoratedType constructor
This CL takes https://dart-review.googlesource.com/c/sdk/+/107740 and add the following condition so that all the current tests pass. if (positionalParameters.length <= positionalParameterCount) { // TODO(danrubel): Track down why this happens // and remove this if statement } else { ... My next task is to track down and fix the underlying issue then remove the temporary code above from the asserts. Change-Id: I683beac46835ed7b8c1a7b856804db84a74142f2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107860 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
1 parent 2fd4ca5 commit 6867425

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

‎pkg/nnbd_migration/lib/src/decorated_type.dart‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,52 @@ class DecoratedType {
4040
this.positionalParameters = const [],
4141
this.namedParameters = const {},
4242
this.typeArguments = const []}) {
43-
assert(node != null);
44-
assert(type is! FunctionType || returnType != null);
43+
assert(() {
44+
assert(node != null);
45+
var type = this.type;
46+
if (type is InterfaceType) {
47+
assert(returnType == null);
48+
assert(positionalParameters.isEmpty);
49+
assert(namedParameters.isEmpty);
50+
assert(typeArguments.length == type.typeArguments.length);
51+
for (int i = 0; i < typeArguments.length; i++) {
52+
assert(typeArguments[i].type == type.typeArguments[i]);
53+
}
54+
} else if (type is FunctionType) {
55+
assert(returnType.type == type.returnType);
56+
int positionalParameterCount = 0;
57+
int namedParameterCount = 0;
58+
for (var parameter in type.parameters) {
59+
if (parameter.isNamed) {
60+
assert(namedParameters[parameter.name].type == parameter.type);
61+
namedParameterCount++;
62+
} else {
63+
if (positionalParameters.length <= positionalParameterCount) {
64+
// TODO(danrubel): Track down why this happens
65+
// and remove this if statement
66+
} else {
67+
assert(positionalParameters[positionalParameterCount].type ==
68+
parameter.type);
69+
positionalParameterCount++;
70+
}
71+
}
72+
}
73+
assert(positionalParameters.length == positionalParameterCount);
74+
assert(namedParameters.length == namedParameterCount);
75+
assert(typeArguments.isEmpty);
76+
} else if (node is TypeParameterType) {
77+
assert(returnType == null);
78+
assert(positionalParameters.isEmpty);
79+
assert(namedParameters.isEmpty);
80+
assert(typeArguments.isEmpty);
81+
} else {
82+
assert(returnType == null);
83+
assert(positionalParameters.isEmpty);
84+
assert(namedParameters.isEmpty);
85+
assert(typeArguments.isEmpty);
86+
}
87+
return true;
88+
}());
4589
}
4690

4791
/// Creates a [DecoratedType] corresponding to the given [element], which is

0 commit comments

Comments
 (0)