Skip to content

Commit 599d608

Browse files
alexmarkovathomas
authored andcommitted
[vm/aot/tfa] More robust handling of annotations in TFA
Apparently it is possible for annotations to contain InvalidExpression AST nodes, not just ConstantExpression (see flutter/flutter#83466 (comment)). This change improves robustness of TFA by ignoring (and cleaning) all annotations which are not ConstantExpression, instead of crashing on them. TEST=none (I wasn't able to reproduce the problem and replicate the situation where front-end generates InvalidExpression nodes.) Change-Id: I1dbd55515f1e861488f6cc46eea50a2ef31ab564 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203283 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent bd5cd8a commit 599d608

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/vm/lib/transformations/type_flow/transformer.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ class CleanupAnnotations extends RecursiveVisitor {
154154
}
155155

156156
bool _keepAnnotation(Expression annotation) {
157-
final constant = (annotation as ConstantExpression).constant;
158-
if (constant is InstanceConstant) {
159-
final cls = constant.classNode;
160-
return (cls == externalNameClass) ||
161-
(cls == pragmaClass) ||
162-
(protobufHandler != null && protobufHandler.usesAnnotationClass(cls));
157+
if (annotation is ConstantExpression) {
158+
final constant = annotation.constant;
159+
if (constant is InstanceConstant) {
160+
final cls = constant.classNode;
161+
return (cls == externalNameClass) ||
162+
(cls == pragmaClass) ||
163+
(protobufHandler != null &&
164+
protobufHandler.usesAnnotationClass(cls));
165+
}
163166
}
164167
return false;
165168
}

0 commit comments

Comments
 (0)