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 StaticArray#to_json #14104

Merged

Conversation

Vendicated
Copy link
Contributor

@Vendicated Vendicated commented Dec 17, 2023

StaticArray.to_json currently results in a compiler error coming from the crystal stdlib:

In /usr/share/crystal/src/json/to_json.cr:10:15

 10 | to_json(json)
              ^---
Error: expected argument #1 to 'StaticArray(Int32, 1)#to_json' to be IO, not JSON::Builder

Overloads are:
 - Object#to_json(io : IO)
 - Object#to_json()

Minimal Reproduction Example:

require "json"

StaticArray[1].to_json

This seems to be caused by it using the generic Object.to_json. This PR fixes it by overwriting to_json for StaticArray to be the same as for normal arrays

@straight-shoota straight-shoota added this to the 1.11.0 milestone Dec 18, 2023
@straight-shoota straight-shoota changed the title Fix StaticArray.to_json Fix StaticArray#to_json Dec 19, 2023
@straight-shoota straight-shoota merged commit 667fbf1 into crystal-lang:master Dec 19, 2023
55 checks passed
@straight-shoota
Copy link
Member

Thanks @Vendicated and congrats on your first contribution to Crystal!

@Vendicated Vendicated deleted the fix-staticarray-to_json branch December 19, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants