Skip to content

Allow Path.is_descendant to work on external paths.#14382

Open
ElectreAAS wants to merge 1 commit intoocaml:mainfrom
ElectreAAS:push-zsxyzmpmuztq
Open

Allow Path.is_descendant to work on external paths.#14382
ElectreAAS wants to merge 1 commit intoocaml:mainfrom
ElectreAAS:push-zsxyzmpmuztq

Conversation

@ElectreAAS
Copy link
Copy Markdown
Collaborator

Extracted from #13792.
Right now, Path.is_descendant can be called on two Path.t, whatever their subtype, but if at least one of them is an External, it will always return false.
This is surprising, you'd expect is_descendant (e "/foo/bar") ~of_:(e "/"); to return true, to quote one test.

This PR extends Path.is_descendant to use the already existing Path.External.is_descendant, mirroring other type variants.
To further mirror other variants, Path.External.is_descendant is patched to include ... || a = b.

Copy link
Copy Markdown
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread otherlibs/stdune/src/path_external.ml Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_descendant to Path.External.is_descendant when both arguments are External.
  • Adjust Path.External.is_descendant to consider equality (a = b) as a descendant relationship.
  • Update stdune expect tests to assert the new External descendant 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.

Comment thread otherlibs/stdune/src/path_external.ml Outdated
Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
Copy link
Copy Markdown
Collaborator

@Alizter Alizter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alizter Alizter self-requested a review April 30, 2026 11:53
@Alizter Alizter self-assigned this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants