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

Fix breakages caused by Crystal 1.13 #231

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mloughran
Copy link

Description

There were 2 issues:

  1. The first, 653c74c, was causing compilation to fail. I didn't investigate further because this module was clearly incorrectly (it was defining Clear::Migration::Clear::Migration::Helper).

  2. The second issues only affected has_many and belongs_to associations which were nilable (and defined using the ? shorthand). The reason for the breakage and a minimal fix is included in 0aa9beb. A more robust fix is then added in 8cc27f7, but with the caveat that some code may need to be updated with additional requires (so that the union type can be resolved in the macro). I would be happy to remove 8cc27f7 from this PR in order to get the minimal fix merged and then to suggest the refactoring later.

Motivation and Context

Clear can't currently be used on Crystal 1.13.0 or above. Closes #230.

How Has This Been Tested?

Tests have been run, and the code has been tested against a production codebase.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Manual of usage of the new feature.

Checklist:

  • My code follows the code style of this project. bin/ameba ran without alert.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

This causes `require "clear"` to fail using crystal 1.13.0
I've not been able to determine whether this was an intentional change of not, but Crystal 1.13.0 changed the way nil is represented in the case that a nilable type was defined with the `?` shorthand:

    macro print_types(name)
      {{ p name.type.types }}
    end

    print_types foo : String?
    # => [String, ::Nil]

    print_types foo : String | Nil
    # => [String, Nil]

This broke the nilable computation in the `has_one` and `belongs_to` macros, resulting in having to define associations thus as as a workaround:

    belongs_to foo : Foo | Nil

instead of

    belongs_to foo : Foo?
Note that since this approach requires that the associated type is resolvable when the association macro is called, it may necessitate adding some additional `require`s, and is probably therefore not a change to be included in a patch release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doesn't work.
1 participant