Fix importC struct scoping issue #20999
Open
+4
−0
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.
This PR fixes an issue in ImportC where struct definitions inside block scopes were not correctly handled. Previously, redefining a struct inside a nested scope led to incorrect scoping behavior, causing conflicts when accessing struct members. This fix ensures that block-scoped struct definitions work independently without interfering with outer scope structs.
Problem Description
Consider the following C code:
Issue:
Before this fix, the compiler incorrectly assumed that the inner struct
ABC
conflicted with the outer structABC
, leading to scoping errors.Fix Applied
ABC
can be used independently inside the block without affecting the outer struct pointerp
.Changes Made
test.c
) to verify correct behavior.Example of Correct Behavior After Fix
With this fix, compiling and running
test.c
produces correct output:Related Issue
Fixes #<issue_number> (if applicable).
Testing & Validation
test.c
successfully.Checklist ✅
✔ My PR includes full test coverage (checked via Codecov).
✔ My PR is minimal and focused (only fixes struct scoping).
✔ I have provided a clear explanation of the issue and fix.
✔ Modified functions include Ddoc comments (
Params:
andReturns:
).