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

Fixing Crystal 1.13 regression issues #1900

Merged
merged 3 commits into from
Jun 28, 2024
Merged

Fixing Crystal 1.13 regression issues #1900

merged 3 commits into from
Jun 28, 2024

Conversation

jwoertink
Copy link
Member

Purpose

Fixes #1872

Description

Crystal 1.13 changes how Nil is written on the macro side. This broke some of the Lucky code because now ::Nil.id is not the same as Nil.id.

Checklist

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

@@ -89,7 +89,9 @@ module Lucky::Assignable
{% sorted_assigns = ASSIGNS.sort_by { |dec|
has_explicit_value =
dec.type.is_a?(Metaclass) ||
dec.type.types.map(&.id).includes?(Nil.id) ||
dec.type.types.any? { |t|
(t.is_a?(Metaclass) || t.is_a?(ProcNotation) || t.is_a?(Generic)) ? false : t.names.includes?(Nil.id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of doing this, but if we use type.resolve here we will have to force all Lucky apps to start adding a bunch of require statements at the top of all the files because of examples like..

class PostPage < MainLayout
   # in macro land, Crystal doesn't know what "User" is yet. If we resolve this type at compile time, we will have to require it at the top of this file.
  needs user : User

  # ...
end

This starts to compound when you're talking about hundreds of actions, models, queries, operations, pages, etc...

@@ -98,7 +100,7 @@ module Lucky::Assignable
{% var = declaration.var %}
{% type = declaration.type %}
{% value = declaration.value %}
{% value = nil if type.stringify.ends_with?("Nil") && !value %}
{% value = nil if type.stringify.ends_with?("Nil") && value.nil? %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this because if for some reason you did param thingable : Bool? = false it would default the value to nil. Probably a non-issue, but why not? 🤷‍♂️

!decl.value.is_a?(Nop) || decl.type.is_a?(Union) && decl.type.types.last.id == Nil.id
!decl.value.is_a?(Nop) || decl.type.is_a?(Union) && decl.type.resolve.nilable?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here resolve.nilable? should be ok 🤞 .... but if it starts blowing up apps, then we know where to come back to..

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.

Compile error using Crystal nightly
1 participant