Skip to content

Add support for record specs #150

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

brettbeatty
Copy link

@brettbeatty brettbeatty commented Mar 1, 2025

Records are a specialized tuple, and they have a typespec format that closely resembles that of tuples. They are not used frequently in Elixir, where structs are preferred, but they still come up. Notably, MapSet.t/1 builds upon :sets.set/1, which is a union of an old record-based type and a new map-based type. Even though MapSet always uses the map-based implementation under the hood, the typespec includes record typespecs. This is the underlying cause of #146 and #147.

Support for records requires two minor changes:

  • Match on records in TypeEngine. The type structure for records is the same as that of tuples, so we can just copy the tuple clauses and repurpose them for records.
  • Handle named elements in TypeMatchError. The existing type_to_string/1 assumes there will be at most one name in the spec and that it will be at the top level (for named args). Record typespecs, however, provide a name for each field. This PR preserves the existing format for named args but also allows named components within specs.

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