Skip to content

Add OsChar conversions#158

Merged
tfausak merged 1 commit into
mainfrom
gh-155-os-char
Jun 5, 2026
Merged

Add OsChar conversions#158
tfausak merged 1 commit into
mainfrom
gh-155-os-char

Conversation

@tfausak

@tfausak tfausak commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Add TryFrom Char OsChar and From OsChar Char instances, mirroring the existing OsString conversions. TryFrom Char OsChar is partial because a Char may not fit in a platform OsChar (one byte on POSIX, two on Windows); it is guarded by a round trip through toChar so it never silently truncates. From OsChar Char is total. Covered by unit tests and a hedgehog round-trip property.

This follows up on #156.

Add `TryFrom Char OsChar` and `From OsChar Char` instances, mirroring the
existing `OsString` conversions. `TryFrom Char OsChar` is partial because a
`Char` may not fit in a platform `OsChar` (one byte on POSIX, two on Windows);
it is guarded by a round trip through `toChar` so it never silently truncates.
`From OsChar Char` is total. Covered by unit tests and a hedgehog round-trip
property.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 extends Witch’s conversion coverage for OsString.OsChar by adding TryFrom Char OsChar and From OsChar Char instances, aligning the API with existing OsString conversions while preventing silent truncation via a round-trip guard.

Changes:

  • Add TryFrom Char OsString.OsChar with a toChar round-trip check to reject out-of-range Char values.
  • Add total From OsString.OsChar Char using OsString.toChar.
  • Add unit tests plus a Hedgehog round-trip property for the new conversions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
source/library/Witch/Instances.hs Adds the new TryFrom/From instances for CharOsChar, including documentation about platform bounds.
source/test-suite/Main.hs Adds unit tests covering the new conversions.
source/hedgehog/Main.hs Adds a property test to validate tryFrom/from round-tripping (within the generated input domain).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/test-suite/Main.hs
Comment on lines +2486 to +2490
it "works" $ do
f 'a' `shouldBe` Just (OsString.unsafeFromChar 'a')
f '\xFF' `shouldBe` Just (OsString.unsafeFromChar '\xFF')
-- Above @0xFFFF@, so it fails on both POSIX and Windows.
f '\x10000' `shouldBe` Nothing
@tfausak tfausak merged commit db1d349 into main Jun 5, 2026
11 checks passed
@tfausak tfausak deleted the gh-155-os-char branch June 5, 2026 19:12
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.

2 participants