Add support for nillables with T | Nil syntax.

This commit is contained in:
Brian J. Cardiff 2017-03-06 12:18:04 -03:00
parent 0797ce72a3
commit 2886c207e0
2 changed files with 15 additions and 1 deletions

View file

@ -66,6 +66,11 @@ module DB
{% for key, value in properties %}
{% value[:nilable] = true if value[:type].is_a?(Generic) && value[:type].type_vars.map(&.resolve).includes?(Nil) %}
{% if value[:type].is_a?(Call) && value[:type].name == "|" &&
(value[:type].receiver.resolve == Nil || value[:type].args.map(&.resolve).any?(&.==(Nil))) %}
{% value[:nilable] = true %}
{% end %}
{% end %}
{% for key, value in properties %}
@ -103,7 +108,7 @@ module DB
{% if value[:converter] %}
{{value[:converter]}}.from_rs(%rs)
{% elsif value[:nilable] || value[:default] != nil %}
%rs.read(Union({{value[:type]}} | Nil))
%rs.read(::Union({{value[:type]}} | Nil))
{% else %}
%rs.read({{value[:type]}})
{% end %}