Skip to content

Tighten stdlib typespecs to match implementations#15561

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-spec-tightening
Jul 9, 2026
Merged

Tighten stdlib typespecs to match implementations#15561
josevalim merged 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-spec-tightening

Conversation

@lukaszsamson

Copy link
Copy Markdown
Contributor

Split out of #15559 as requested. These specs declared strictly wider return types than the functions can produce, where the gap carries no intentional API room. Specs that are deliberately abstract (e.g. atom() covering future values) were left untouched per the review feedback there.

  • File.Stream.t/0: type the struct fields (mirrors IO.Stream.t/0)
  • Map.new/0: %{} instead of map()
  • Logger.levels/0: :logger.level() excludes :warn, which is only an accepted input alias and is never returned
  • Macro.Env.location/1 and Macro.Env.stacktrace/1: precise shapes derived from the module's own field types

Assisted-By: Claude Fable 5

🤖 Generated with Claude Code

Comment thread lib/logger/lib/logger.ex Outdated
"""
@doc since: "1.16.0"
@spec levels() :: [level(), ...]
@spec levels() :: [:logger.level(), ...]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this because of :warn? If so, we should update @type level to no longer include :warn!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed

Candidates found by cross-checking @specs against the type signatures
inferred by the compiler (see elixir-lang#15559): these specs declared strictly
wider return types than the functions can produce, where the gap
carries no intentional API room (deliberately abstract contracts, such
as atom() covering future values, are left untouched):

  * File.Stream.t/0: type the struct fields (mirrors IO.Stream.t/0)
  * Map.new/0: %{} instead of map()
  * Logger.levels/0: :logger.level() excludes :warn, which is only an
    accepted input alias and is never returned
  * Macro.Env.location/1 and Macro.Env.stacktrace/1: precise shapes

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@josevalim josevalim merged commit 1cb2089 into elixir-lang:main Jul 9, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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.

2 participants