-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fixup for JSON::Serializable
on certain recursively defined types
#13430
Conversation
This essentially reverts part of #13344 which apparently wasn't necessary? I suppose the relevant part of that PR was casting the type of the default nil value? It's not exactly clear why this fixes things. The compiler is doing some weird stuff here. |
yes looks like compiler bug when using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is typeof(@source).new(pull)
somehow instantiates Base+.new
which breaks things, while Union(typeof(@source))
devirtualizes the metaclass type.
YAML would be nice.
src/json/serialization.cr
Outdated
@@ -202,9 +203,9 @@ module JSON | |||
# recursively defined serializable types | |||
{% for name, value in properties %} | |||
%var{name} = {% if value[:has_default] || value[:nilable] %} | |||
nil.as(::Nil | typeof(@{{name}})) | |||
nil.as(::Nil | Union({{value[:type]}})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil.as(::Nil | Union({{value[:type]}})) | |
nil.as(::Union(::Nil, typeof(@{{name}}))) |
For the others simply wrap the typeof
alone inside ::Union
(also note the leading ::
)
I am also observing some JSON bug, possibly slightly different, in Crystal 1.8.1. |
JSON::Serializable
on certain recursively defined types
i don't know, correct this or not, but if fixes, and all specs seems pass. fixes: #13429