Skip to content

Commit

Permalink
Fixes Crystal 1.13 regression issue (#89)
Browse files Browse the repository at this point in the history
* Due to a change in the upcoming Crystal version, Nil has to be checked differently in macros. Fixes #88

* CI wasn't actually using nightly

* each version needs to specify experimental

* this has to be an array

* Applying suggestion for better compatibility
  • Loading branch information
jwoertink authored Jun 15, 2024
1 parent 5fd8d7b commit 2b4ee9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
crystal_version: [latest]
experimental: [false]
include:
- os: ubuntu-latest
crystal_version: 1.4.0
experimental: false
- os: ubuntu-latest
crystal_version: nightly
experimental: true
runs-on: ${{ matrix.os }}
continue-on-error: false
continue-on-error: ${{ matrix.experimental }}
steps:
- uses: actions/checkout@v3
- uses: crystal-lang/install-crystal@v1
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.map(&.id).includes?(Nil.id)) %}
(setting[:decl].type.is_a?(Union) && !setting[:decl].type.types.any?(&.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.map(&.id).includes?(Nil.id) %}
{% if decl.type.is_a?(Union) && decl.type.types.any?(&.names.includes?(Nil.id)) %}
{% nilable = true %}
{% else %}
{% nilable = false %}
Expand Down

0 comments on commit 2b4ee9e

Please sign in to comment.