Repository navigation
fix: Read match arm members from the current section - #267
Open
scottanderson wants to merge 1 commit into
Open
scottanderson wants to merge 1 commit into
scottanderson wants to merge 1 commit into
Conversation
A primitive in a match arm read its value from the main section. This occurred when its struct was placed in a custom section. The match statement did not set the section on its patterns. The if and try/catch statements already do this.
This branch has not been deployed
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
A primitive declared in a match arm reads its value from the main section. This occurs when its struct is placed in a custom section with
@ ... in section. Members in anifbody, in atry/catchbody, and structs in a match arm read from the correct section.Here
s.plainands.inIfread fromsection, buts.inMatchreads from the main section at the same offset. The value is wrong during evaluation (for examplestd::print) and afterwards (for example the JSON formatter).This breaks
palworld.hexpatin ImHex-Patterns. It inflates a save into a section and parses it withgvas.hexpat. EachIntProperty,FloatPropertyand similar property there is a primitive in a match arm.Summary
ASTNodeConditionalStatement::createPatternsandASTNodeTryCatchStatement::createPatternsset the current section on each new pattern before they push it into the scope.ASTNodeMatchStatement::createPatternsdid not. This PR adds the same line:for (auto &pattern : newPatterns) { + pattern->setSection(evaluator->getSectionId()); scope.push_back(std::move(pattern)); }No other statement node has this gap. Compound statements and multi-variable declarations do not push into the scope. They return their patterns to the enclosing struct or union, which sets the section.
The new
SectionStatementstest places a struct in a section whose bytes differ from the main data. It asserts that each of these reads from the section: a plain member, a primitive in a match arm, anifbody, atrybody, acatchbody, a nested struct, and a struct in a match arm.Evidence
SectionStatementsfails withassertion failed "Match arm member did not read from section". All other tests pass.Merge Danger
Door: two-way
A primitive in a match arm in a custom section now reads from that section. Reverting gives back the old behavior.
Blast Radius: small
Only patterns that place a struct in a custom section and declare a primitive directly in a match arm see a change. Those patterns read wrong values today.