Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
namely(alias)stores parsers in a single module-globalaliasRegistry, and a reference by name (nest/array/choice/pointer/wrappedwithtype: "name") was only looked up again at compile time, which happens lazily on the firstparse(). If two independent modules (or two libraries that both depend on binary-parser) used the same alias name, the parser registered last silently replaced the other one, so already-defined parsers would parse with the wrong layout. Generated function names were also derived from the alias (___parser_<alias>), so two different parsers with the same alias in one compilation produced colliding functions.Repro
Fix
type,choices,defaultChoice) are resolved and theParserobject is captured on that field. Code generation uses the captured parser, and falls back to the registry only for names that were not registered at definition time (wrappeddoes not validate its type, so this keeps its old behavior).___parser_<id>and compile-time references are tracked byParserobject instead of by alias name.array/nest/choice/pointeralready required the alias to be registered when the field is defined, so the parser can always be captured. A self-reference resolves to the same parser object, which is marked resolved as before.The public API does not change. Re-registering an alias now only affects fields defined after that point (documented in the README under
namely). Side effect: alias strings no longer appear in generated code, since function names come from the id.Added a regression test in
test/composite_parser.ts. It fails on master and passes with this change. All existing tests pass, and the classfile/elf32/tar/mbr examples still run.