refactor(internal/librarian): dispatch fillDefaults by language instead of type switch - #6624
Closed
JoeWang1127 wants to merge 2 commits into
Closed
refactor(internal/librarian): dispatch fillDefaults by language instead of type switch#6624JoeWang1127 wants to merge 2 commits into
fillDefaults by language instead of type switch#6624JoeWang1127 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the fillDefaults function in internal/librarian/library.go to use a map lookup (languageDefaultFillers) instead of a large switch statement. To prevent nil pointer dereferences, safety checks have been added to each language-specific filler function. Additionally, the unit tests in internal/librarian/library_test.go have been refactored into language-specific test functions and updated to pass the new language parameter. There are no review comments, and I have no feedback to provide.
fillDefaults by language instead of type switch
JoeWang1127
marked this pull request as ready for review
July 6, 2026 14:27
Contributor
Author
|
Talked with @ianthehat, this change doesn't solve the design issue of |
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.
Replace the type switch in
fillDefaultsthat inferred the language from whichDefaultfield was non-nil with alanguageDefaultFillersmap keyed by the explicit language string fromConfig.Language.This eliminates the implicit priority ordering between languages (e.g. Java before Rust) and the fragile dispatch based on data rather than the known language identifier.
Each language-specific fill function now guards against its default field being nil, since the type switch no longer prevents calls when the language-specific default is absent.
Motivated by #6554 (comment)