Skip to content

Add missing calendar key to Calendar.time() and fix NaiveDateTime.truncate/2 spec#15572

Open
lukaszsamson wants to merge 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-calendar-time-type
Open

Add missing calendar key to Calendar.time() and fix NaiveDateTime.truncate/2 spec#15572
lukaszsamson wants to merge 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-calendar-time-type

Conversation

@lukaszsamson

Copy link
Copy Markdown
Contributor

Found by re-running the type checker over stdlib function bodies with spec-derived argument domains (the spec-domain body check from #15559):

  • Calendar.time() is the only calendar-family type without a calendar: field (date, naive_datetime and datetime all declare it), yet virtually every Time function taking Calendar.time() destructures the field in its head (to_string/1, to_iso8601/2, add/3, compare/2, shift/2, diff/3). A map conforming to the declared type raises FunctionClauseError today: Time.to_string(%{hour: 1, minute: 2, second: 3, microsecond: {0, 0}}). Declare calendar: calendar like the sibling types.
  • NaiveDateTime.truncate/2's second clause deliberately accepts any naive-datetime-compatible map (e.g. a DateTime), the same convention as add/3, to_date/1 and compare/2 — but its spec said t(), making that clause unreachable per the spec. Now Calendar.naive_datetime() like its siblings.

The full stdlib recompiles with no new type-checker warnings under the tightened time() type, and all calendar test suites pass.

Assisted-By: Claude Fable 5

🤖 Generated with Claude Code

Found by re-running the type checker over function bodies with
spec-derived argument domains (elixir-lang#15559):

Calendar.time() was the only calendar-family type without a
calendar: field (date, naive_datetime and datetime all declare it),
yet virtually every Time function taking Calendar.time() destructures
the field in its head -- to_string/1, to_iso8601/2, add/3, compare/2,
shift/2, diff/3. A map conforming to the declared type therefore
raised FunctionClauseError. Declare calendar: calendar like the
sibling types.

NaiveDateTime.truncate/2's second clause deliberately accepts any
naive-datetime-compatible map (e.g. a DateTime), the same convention
as add/3, to_date/1 and compare/2 -- but its spec said t(), making
that clause unreachable per the spec. Accept Calendar.naive_datetime()
like its siblings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant