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

Fixes Crystal 1.13 regression issue #89

Merged
merged 5 commits into from
Jun 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/habitat.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ class Habitat
# Habitat.raise_if_missing_settings!
# ```
def self.raise_if_missing_settings!
{% # https://github.com/crystal-lang/crystal/pull/14490

if compare_versions(Crystal::VERSION, "1.13.0-dev") >= 0
nil_type_id = "::Nil".id
jwoertink marked this conversation as resolved.
Show resolved Hide resolved
else
nil_type_id = "Nil".id
end %}
jwoertink marked this conversation as resolved.
Show resolved Hide resolved
{% for type in TYPES_WITH_HABITAT %}
{% for setting in type.constant(:HABITAT_SETTINGS) %}
{% if !setting[:decl].type.is_a?(Union) ||
(setting[:decl].type.is_a?(Union) && !setting[:decl].type.types.map(&.id).includes?(Nil.id)) %}
(setting[:decl].type.is_a?(Union) && !setting[:decl].type.types.map(&.id).includes?(nil_type_id)) %}
if {{ type }}.settings.{{ setting[:decl].var }}?.nil?
raise MissingSettingError.new {{ type }}, setting_name: {{ setting[:decl].var.stringify }}, example: {{ setting[:example] }}
end
Expand Down Expand Up @@ -226,12 +233,19 @@ class Habitat
{% end %}
{% end %}

{% # https://github.com/crystal-lang/crystal/pull/14490
if compare_versions(Crystal::VERSION, "1.13.0-dev") >= 0
jwoertink marked this conversation as resolved.
Show resolved Hide resolved
nil_type_id = "::Nil".id
else
nil_type_id = "Nil".id
end %}

{% for opt in type_with_habitat.constant(:HABITAT_SETTINGS) %}
{% decl = opt[:decl] %}
# NOTE: We can't use the macro level `type.resolve.nilable?` here because
# there's a few declaration types that don't respond to it which would make the logic
# more complex. Metaclass, and Proc types are the main, but there may be more.
{% if decl.type.is_a?(Union) && decl.type.types.map(&.id).includes?(Nil.id) %}
{% if decl.type.is_a?(Union) && decl.type.types.map(&.id).includes?(nil_type_id) %}
{% nilable = true %}
{% else %}
{% nilable = false %}
Expand Down
Loading