Allow Path.is_descendant to work on external paths.#14382
Conversation
Leonidas-from-XIV
left a comment
There was a problem hiding this comment.
Looks like a solid improvement. I have one question that would be good to have an answer to, besides that it gets a solid 👍 from me.
There was a problem hiding this comment.
Pull request overview
This PR updates Stdune.Path.is_descendant so that it correctly handles External paths (instead of always returning false), aligning behavior with the other Path.t variants and updating tests accordingly.
Changes:
- Delegate
Path.is_descendanttoPath.External.is_descendantwhen both arguments areExternal. - Adjust
Path.External.is_descendantto consider equality (a = b) as a descendant relationship. - Update
stduneexpect tests to assert the newExternaldescendant behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| otherlibs/stdune/src/path.ml | Adds an External/External case to Path.is_descendant. |
| otherlibs/stdune/src/path_external.ml | Updates external descendant logic to include equality and prefix-based checks. |
| otherlibs/stdune/test/path_tests.ml | Updates expectations to reflect the new External descendant semantics. |
56ed740 to
887de1d
Compare
Alizter
left a comment
There was a problem hiding this comment.
There are a lot of consumers of this function so I would like to conduct a thorough review. This will take time to do so I will block this PR in the meantime so there are no misunderstandings.
|
We took a quick look at the users of
|
Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
…in sandbox Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
887de1d to
06b6160
Compare
|
After having a look through the consumers of I think our best course of action here would be to understand its usage at each call site. Instead use the correct variant-specific version or remove the check entirely, and finally remove this function and its confusing nature. If you want to work on this further, I would suggest you make a table of all the call sites and see if we have an idea of what we can replace each site with. |
Extracted from #13792.
Right now,
Path.is_descendantcan be called on twoPath.t, whatever their subtype, but if at least one of them is anExternal, it will always returnfalse.This is surprising, you'd expect
is_descendant (e "/foo/bar") ~of_:(e "/");to returntrue, to quote one test.This PR extends
Path.is_descendantto use the already existingPath.External.is_descendant, mirroring other type variants.To further mirror other variants,
Path.External.is_descendantis patched to include... || a = b.