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 %}
return {{non_primitives[0]}}.new(decoder)
{% else %}
string = pull.read_raw
{% for type in non_primitives %}
begin
return {{type}}.from_json(string)
return {{type}}.new(decoder)
rescue CBOR::ParseError
# Ignore
end
{% end %}
raise CBOR::ParseError.new("Couldn't parse #{self} from #{string}", *location)
raise CBOR::ParseError.new("Couldn't parse #{self}")
{% end %}
{% end %}
end