Fix type specs to accept structs and atom-keyed maps#14
Merged
Conversation
The Toon.Encoder protocol normalizes input before encoding, so the public API should accept any term() - not just pre-normalized types. Changes: - Add Toon.Types.input() type as term() for encoder parameters - Update encode/1,2 and encode!/1,2 specs to use input() - Keep encodable() for normalized output (string-keyed maps) - Add tests for struct and atom-key encoding via public API This fixes Dialyzer warnings when calling Toon.encode!/1 with: - Ecto schemas (structs with atom keys) - Maps with atom keys - Any type implementing the Toon.Encoder protocol Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pull Request Test Coverage Report for Build 45581c8dffdd6a4b56077620d5c1a98ec683ef47-PR-14Details
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Dialyzer warnings when calling
Toon.encode!/1with structs or maps with atom keys.Problem
The
Toon.Types.encodable()type only accepted:%{optional(String.t()) => encodable()}(string-keyed maps)But users commonly pass:
%Screentour.Festivals.Edition{})%{name: "Alice"})The
Toon.Encoderprotocol handles normalization, but Dialyzer didn't know this.Solution
Toon.Types.input()asterm()- the Encoder protocol accepts any type with an implementationencode/1,2andencode!/1,2specs to useinput()for parametersencodable()for documenting the normalized output formatTDD Process
RED: Created
lib/toon/type_check.exthat callsToon.encode!/1with a struct. Dialyzer failed:GREEN: Added
input()type and updated specs. Dialyzer passes.REFACTOR: Removed temporary test module, kept behavioral tests in
encoder_test.exs.Test plan
mix quality.cipasses (credo, dialyzer, format)🤖 Generated with Claude Code