Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spec for to_timeout/1 #13755

Merged
merged 2 commits into from
Aug 2, 2024
Merged

Fix spec for to_timeout/1 #13755

merged 2 commits into from
Aug 2, 2024

Conversation

fuelen
Copy link
Contributor

@fuelen fuelen commented Aug 2, 2024

Otherwise, dialyzer always fails:

defmodule MyTest do
  def test_function(expires_in_seconds) do
    to_timeout(second: expires_in_seconds)
  end
end

Error

lib/mytest.ex:2:no_return
Function test_function/1 has no local return.
________________________________________________________________________________
lib/mytest.ex:3:call
The function call will not succeed.

Kernel.to_timeout([{:second, _}, ...])

breaks the contract
([:component, ...] | timeout() | Duration.t()) :: timeout()
when component: [{:unit, non_neg_integer()}, ...],
     unit: :week | :day | :hour | :minute | :second | :millisecond

Copy link
Contributor

@sabiwara sabiwara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fuelen ! 💜

Comment on lines 6214 to 6215
@spec to_timeout([component, ...] | timeout() | Duration.t()) :: timeout()
when component: [{unit, non_neg_integer()}, ...],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can just remove component and inline the tuple, might be easier to read actually?

when component: [{unit, non_neg_integer()}, ...],
unit: :week | :day | :hour | :minute | :second | :millisecond
@spec to_timeout([{unit, non_neg_integer()}] | timeout() | Duration.t()) :: timeout()
when unit: :week | :day | :hour | :minute | :second | :millisecond
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inlined it and I also removed .... An empty list should be fine and it already means a timeout of zero.

@josevalim josevalim merged commit 1b73c49 into elixir-lang:main Aug 2, 2024
9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

josevalim pushed a commit that referenced this pull request Aug 2, 2024
@fuelen fuelen deleted the patch-1 branch August 2, 2024 10:26
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.

3 participants