Skip to content

Commit e565488

Browse files
osa1Commit Queue
authored andcommitted
[dart2wasm] Improve ClassInfo field validation error messages
Change-Id: Ie19c932b3e84c272b5e2d0f683bca74a0cf838ea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394080 Commit-Queue: Ömer Ağacan <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent 22833d5 commit e565488

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

pkg/dart2wasm/lib/class_info.dart

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,30 @@ class FieldIndex {
6060

6161
static void validate(Translator translator) {
6262
void check(Class cls, String name, int expectedIndex) {
63-
assert(
64-
translator.fieldIndex[
65-
cls.fields.firstWhere((f) => f.name.text == name)] ==
66-
expectedIndex,
67-
"Unexpected field index for ${cls.name}.$name");
63+
Field? field;
64+
65+
for (Field clsField in cls.fields) {
66+
if (clsField.name.text == name) {
67+
field = clsField;
68+
break;
69+
}
70+
}
71+
72+
if (field == null) {
73+
throw AssertionError("$cls doesn't have field $name");
74+
}
75+
76+
final actualIndex = translator.fieldIndex[field];
77+
78+
if (actualIndex == null) {
79+
throw AssertionError("$cls field $name doesn't have an index assigned");
80+
}
81+
82+
if (actualIndex != expectedIndex) {
83+
throw AssertionError(
84+
"$cls field $name expected index = $expectedIndex, "
85+
"actual index = $actualIndex");
86+
}
6887
}
6988

7089
check(translator.asyncSuspendStateClass, "_resume",
@@ -510,7 +529,10 @@ class ClassInfoCollector {
510529
}
511530

512531
// Validate that all internally used fields have the expected indices.
513-
FieldIndex.validate(translator);
532+
assert((() {
533+
FieldIndex.validate(translator);
534+
return true;
535+
})());
514536
}
515537
}
516538

0 commit comments

Comments
 (0)