Skip to content

Commit

Permalink
Add a catch for Nilable ProcNotations. Fixes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Jun 15, 2024
1 parent 2b4ee9e commit b0f076f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/habitat_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ end
class ASettingForEverything
alias Dot = Int32
Habitat.create do
setting proc_notation : String -> Nil
setting proc_notation : (String -> Nil)?
setting alias_setting : Dot = 3
setting point : Point = Point.new(x: 3, y: 4)
setting mod : SuperMod
Expand Down
4 changes: 2 additions & 2 deletions src/habitat.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Habitat
{% 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.any?(&.names.includes?(Nil.id))) %}
(setting[:decl].type.is_a?(Union) && !setting[:decl].type.types.any? { |t| t.is_a?(ProcNotation) ? false : t.names.includes?(Nil.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 @@ -231,7 +231,7 @@ class Habitat
# 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.any?(&.names.includes?(Nil.id)) %}
{% if decl.type.is_a?(Union) && decl.type.types.any? { |t| t.is_a?(ProcNotation) ? false : t.names.includes?(Nil.id) } %}
{% nilable = true %}
{% else %}
{% nilable = false %}
Expand Down

0 comments on commit b0f076f

Please sign in to comment.