Skip to content

Commit b565c8c

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Don't serialize not serializable constant variable initializers.
[email protected] Change-Id: If5287b11293391d8620b9843880b95f725efc5fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114800 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent ce12a27 commit b565c8c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,10 @@ class AstBinaryWriter extends ThrowingAstVisitor<LinkedNodeBuilder> {
13671367
}
13681368
}
13691369

1370+
if (!_isSerializableExpression(initializer)) {
1371+
initializer = null;
1372+
}
1373+
13701374
var builder = LinkedNodeBuilder.variableDeclaration(
13711375
informativeId: getInformativeId(node),
13721376
variableDeclaration_initializer: initializer?.accept(this),

pkg/analyzer/test/generated/invalid_code_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ void f({a = [for (@b c = 0;;)]}) {}
152152
''');
153153
}
154154

155+
test_fuzz_13() async {
156+
// `x is int` promotes the type of `x` to `S extends int`, and the
157+
// underlying element is `TypeParameterMember`, which by itself is
158+
// questionable. But this is not a valid constant anyway, so we should
159+
// not even try to serialize it.
160+
await _assertCanBeAnalyzed(r'''
161+
const v = [<S extends num>(S x) => x is int ? x : 0];
162+
''');
163+
}
164+
155165
test_genericFunction_asTypeArgument_ofUnresolvedClass() async {
156166
await _assertCanBeAnalyzed(r'''
157167
C<int Function()> c;

0 commit comments

Comments
 (0)