Fix union

dev
Alberto Restifo 2020-04-25 18:26:06 +02:00
parent 14c52208a3
commit 41cc5f082b
1 changed files with 2 additions and 3 deletions

View File

@ -182,15 +182,14 @@ def Union.new(decoder : CBOR::Decoder)
{% if non_primitives.size == 1 %} {% if non_primitives.size == 1 %}
return {{non_primitives[0]}}.new(decoder) return {{non_primitives[0]}}.new(decoder)
{% else %} {% else %}
string = pull.read_raw
{% for type in non_primitives %} {% for type in non_primitives %}
begin begin
return {{type}}.from_json(string) return {{type}}.new(decoder)
rescue CBOR::ParseError rescue CBOR::ParseError
# Ignore # Ignore
end end
{% end %} {% end %}
raise CBOR::ParseError.new("Couldn't parse #{self} from #{string}", *location) raise CBOR::ParseError.new("Couldn't parse #{self}")
{% end %} {% end %}
{% end %} {% end %}
end end