Skip to content

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

Closed

Description

@matt-edmondson

What's wrong

The three directory path types disagree on what a directory's name is:

Type Name type Location
AbsoluteDirectoryPath FileName Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs:80
DirectoryPath FileName Semantics.Paths/Primitives/DirectoryPath.cs:44
RelativeDirectoryPath DirectoryName Semantics.Paths/Implementations/RelativeDirectoryPath.cs:75

The / operator picks its result type from the right operand. AbsoluteDirectoryPath / DirectoryName gives an AbsoluteDirectoryPath (line 185), and AbsoluteDirectoryPath / FileName gives an AbsoluteFilePath (line 201). DirectoryPath works the same way at lines 115 and 131. So rebuilding a directory from its own parts changes its kind:

var dir = AbsoluteDirectoryPath.Create<AbsoluteDirectoryPath>("/home/user/docs");
var rebuilt = dir.Parent / dir.Name;               // AbsoluteFilePath "/home/user/docs"
AbsoluteDirectoryPath d2 = dir.Parent / dir.Name;  // CS0029: no implicit conversion

For RelativeDirectoryPath, the same expression stays a directory.

Why it matters

The library's purpose is to keep "file" and "directory" apart in the type system. Here a directory's own name walks it into the file side, and callers have to round-trip through WeakString to get back. Walking up and rebuilding a tree, or mapping a directory into another root (otherRoot / dir.Name), is exactly where this goes wrong.

Suggested fix / acceptance criteria

  • AbsoluteDirectoryPath.Name and DirectoryPath.Name return DirectoryName, matching RelativeDirectoryPath. This changes the public API, so add a CompatibilitySuppressions.xml entry and a migration-guide note.
  • For every directory type, dir.Parent / dir.Name has the same type as dir. Add a test for each.
  • The documented "as written, not as resolved" behaviour for .. / . names stays unchanged.

Activity

  1. added
    bug
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions