Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent writing empty annotations sequences #781

Merged
merged 2 commits into from
Jun 3, 2024
Merged

Conversation

zslayton
Copy link
Contributor

@zslayton zslayton commented Jun 2, 2024

Prior to this change, when a ValueWriter explicitly called with_annotations() and provided an empty array, the writer would write an empty annotations sequence which is not legal. This change detects that case and skips writing any sequence at all. It also adds a has_annotations() convenience method to the LazyRawValue trait.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@zslayton zslayton requested a review from popematt June 3, 2024 11:30
Copy link
Contributor

@popematt popematt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add test cases to verify that the other encodings do not have the same issue? (Or do they already exist?)

@zslayton
Copy link
Contributor Author

zslayton commented Jun 3, 2024

Can you add test cases to verify that the other encodings do not have the same issue? (Or do they already exist?)

The Binary 1.1 writer already had a test for this:

// Explicitly empty annotations set with a type hint the compiler can use in a generic context.
const NO_ANNOTATIONS: [SymbolId; 0] = [];
// === Symbol ID annotations ===
case(
0.annotated_with(NO_ANNOTATIONS),
&[
// Integer 0
0x50,
],
)?;

I'll add one for the text writers though.

@zslayton zslayton requested a review from popematt June 3, 2024 13:00
@zslayton zslayton merged commit 1c22df0 into main Jun 3, 2024
32 checks passed
@zslayton zslayton deleted the empty-annotations branch June 3, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants