Skip to content

Return a DirectoryName from every directory type's Name [major] - #500

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/498-directory-name-type
Oct 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/498-directory-name-type

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #498

Problem

AbsoluteDirectoryPath.Name and DirectoryPath.Name returned a FileName, but RelativeDirectoryPath.Name returned a DirectoryName. The / operator picks its result type from the right operand. So dir.Parent / dir.Name rebuilt an absolute directory as an AbsoluteFilePath.

Change

  • AbsoluteDirectoryPath.Name and DirectoryPath.Name now return DirectoryName. FileName and DirectoryName validate identically, so every name that was accepted before still is.
  • RelativeDirectoryPath gains operator /(RelativeDirectoryPath, DirectoryName). This corrects the issue: it says the expression already stayed a directory for RelativeDirectoryPath. In fact the operator was missing and dir.Parent / dir.Name failed with CS0019. The other two directory types already had this operator, so it is needed to meet the "every directory type" criterion.
  • The "as written, not as resolved" behaviour is unchanged: the name of /home/user/.. is still ...
  • Docs: added docs/migration-guide-6.0.md and listed it in CLAUDE.md.

On the CompatibilitySuppressions.xml entry the issue asked for

It isn't needed, and adding one would break the build. Package validation in this repo compares target frameworks against each other, not against a released baseline. This change applies to every target alike, and dotnet pack Semantics.Paths -c Release succeeds with no CP diagnostics. An unused suppression is itself an error; that is what stopped Containers#123 from releasing.

Overlap with #496

#496 also creates docs/migration-guide-6.0.md, with a section on PH.ToPOH. Both PRs use the same title line. Whichever merges second gets an add/add conflict, which is resolved by keeping both sections.

Tests

Semantics.Test/Paths/DirectoryNameRebuildTests.cs:

  • For AbsoluteDirectoryPath, DirectoryPath and RelativeDirectoryPath, dir.Parent / dir.Name is assigned to the same type as dir and is equal to dir.
  • The .. name is pinned as written.

Without the fix this file does not compile: CS0029 for the absolute and generic types, and CS0019 for the relative type. With the fix:

  • the path tests pass (256 total: 252 passed, 4 skipped);
  • the full Semantics.Test suite passes (1962 total: 1948 passed, 14 skipped, 0 failed);
  • dotnet pack of Semantics.Paths passes package validation.

Generated by Claude Code

AbsoluteDirectoryPath.Name and DirectoryPath.Name returned a FileName
while RelativeDirectoryPath.Name returned a DirectoryName. The '/'
operator picks its result type from the right operand, so
dir.Parent / dir.Name rebuilt an absolute directory as an
AbsoluteFilePath, walking a directory into the file side of the type
system.

Both now return a DirectoryName. RelativeDirectoryPath also gains the
'/ DirectoryName' operator the other two directory types already had:
without it, dir.Parent / dir.Name did not compile for a relative
directory at all. Now the expression has the same type as dir for every
directory type. The name is still the last component as written, so the
name of /home/user/.. is "..".

This changes the public return type of two properties, so the release is
[major] and docs/migration-guide-6.0.md describes the migration. Package
validation here compares target frameworks rather than a baseline
release, and every target changes alike, so no compatibility
suppression is needed.

Fixes #498

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW6XNeWiDxG4BVzYTra
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 4c17d23 into main Oct 30, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the fix/498-directory-name-type branch October 30, 2026 02:40
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.

AbsoluteDirectoryPath.Name and DirectoryPath.Name return FileName, so dir.Parent / dir.Name builds a file path

2 participants