Skip to content
New issue

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

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

Already on GitHub? # to your account

bug: MethodBuilder disposes CodeWriter after writing first method closing the class and namespace prematurely #42

Closed
niklasstich opened this issue Oct 9, 2022 · 1 comment · Fixed by #43
Labels
bug Something isn't working

Comments

@niklasstich
Copy link
Contributor

niklasstich commented Oct 9, 2022

MethodBuilder obtains an IDisposable handle on the currently being used CodeWriter at the end of its write method by calling writer.Block on it in a using statement (see here), before invoking _methodBodyWriter and ultimately disposing the CodeWriter afterwards. Because of the changes introduced to the Dispose method of CodeWriter in 9963d78, this immediately closes off not only the currently being written to method block, but also the class and namespace blocks. This means that all following Writers write outside of the namespace block, leading to incorrect code.

I can share a minimum reproducible example if necessary, but it should be immediately obvious when trying to generate any class with a method. It would probably be prudent to add a test case with multiple methods to check for this in the future.

Example diff from my project after updating:
image

@dansiegel dansiegel added the bug Something isn't working label Oct 9, 2022
@dansiegel
Copy link
Owner

Thanks for the report. I've unlisted the package and will try to get a fix out shortly

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants