Skip to content

Bring back the Duration helpers as disfavored overloads - #42

Open
Jeehut wants to merge 1 commit into
mainfrom
wip/restore-duration-helpers
Open

Jeehut wants to merge 1 commit into
mainfrom
wip/restore-duration-helpers

Conversation

@Jeehut

@Jeehut Jeehut commented Oct 12, 2026

Copy link
Copy Markdown
Member

Keeps the next ErrorKit release source-compatible with 1.2.1.

1.2.1 ships Duration.minutes(_:), Duration.hours(_:) and Duration.timeInterval as public API, and the README and DocC examples call the log APIs with them (ErrorKit.logAttachment(ofLast: .minutes(30))). On main, c9c2fe8 made timeInterval internal and removed the other two, because HandySwift defines the same three helpers: in a file that imports both modules – as everything built on FlineDevKit does – .minutes(30) was ambiguous. Releasing main as it is would turn that fix into a compile error for every app that uses ErrorKit without HandySwift, including the README's own sample.

This branch brings the three helpers back as public, marked @_disfavoredOverload. The attribute only lowers their rank when another candidate exists, so:

File imports .minutes(30) resolves to
ErrorKit only ErrorKit's helper (as in 1.2.1)
ErrorKit + HandySwift HandySwift's helper, no ambiguity

Alternatives considered: shipping the removal as 2.0.0 (a major release for three convenience helpers, while the docs keep needing a replacement for .minutes(30)), or removing the helpers from HandySwift instead (moves the break to HandySwift's users).

How this was verified

DurationHelperTests checks the three helpers from a plain import ErrorKit. Against the sources on main it fails to compile; on this branch the full suite passes:

# sources from main
error: type 'Duration' has no member 'minutes'
error: type 'Duration' has no member 'hours'
error: 'timeInterval' is inaccessible due to 'internal' protection level

# this branch
✔ Suite "Duration helpers" passed
✔ Test run with 21 tests in 5 suites passed.

The two-module case was checked with a throwaway package that has one executable importing ErrorKit and HandySwift (local checkouts) and one importing only ErrorKit, both calling .minutes(30), .hours(1).timeInterval and ErrorKit.loggedData(ofLast: .minutes(5)). Both built and ran. Without @_disfavoredOverload, the two-module target failed again:

Sources/Both/main.swift:4:20: error: ambiguous use of 'minutes'

1.2.1 shipped Duration.minutes(_:), .hours(_:) and .timeInterval as
public API, and the README's log examples use .minutes(30). They were
removed on main because HandySwift defines the same three helpers, which
made '.minutes(30)' ambiguous in any file importing both modules.

Removing them would break every ErrorKit-only user in the next release.
Marking them @_disfavoredOverload keeps both cases compiling: alone,
ErrorKit's helpers resolve; next to HandySwift, the compiler prefers
HandySwift's without an ambiguity error.
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.

1 participant