Return existing builder from PathBuilder.Root() instead of creating a new one.#420
Open
tobb10001 wants to merge 3 commits intogoccy:masterfrom
Open
Return existing builder from PathBuilder.Root() instead of creating a new one.#420tobb10001 wants to merge 3 commits intogoccy:masterfrom
PathBuilder.Root() instead of creating a new one.#420tobb10001 wants to merge 3 commits intogoccy:masterfrom
Conversation
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #420 +/- ##
==========================================
+ Coverage 76.02% 76.03% +0.01%
==========================================
Files 13 13
Lines 4692 4694 +2
==========================================
+ Hits 3567 3569 +2
Misses 866 866
Partials 259 259 |
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.
This PR fixes a bug that I came across. It is triggered by a piece of code like this:
On the current
masterthis code causes a panic:The root cause is that the
PathBuilder.Root()method instanciates a newPathBuilderinstance instead of mutating and returning the reciever. This is inconsistent with the similar methodsIndexAll,Recursive,IndexandChildand with my understanding of the builder pattern.The given code sample assumes that the
.Root()call mutates the builder, but it doesn't. Therefore the resultingpathbuilt bybuilder.Build()does not have a root. This in turn causes the panic when callingpath.String().This is not caught by the existing tests, because the existing tests use method chaining, which executes the next call on the builder returned by
builder.Root(), which is a builder that has a root and therefore works as expected.The fact that
path.String()causes a panic in this case might be a separate issue that I didn't look into further.