Having hard time trying to maintain my library

Hello everyone,

I’m running into some serious issues keeping my library compatible with the latest version of Crystal (1.13). Specifically, I’m talking about Clear, which no longer compiles.

After spending a couple of hours trying to diagnose the problem, it looks like there have been changes to scope resolution that are causing numerous issues.

For example:

class Clear::Migration::Table < Clear::Migration::Operation
  include Clear::Migration::FullTextSearchableTableHelpers
end

This no longer compiles, throwing an error that Clear::Migration::FullTextSearchableTableHelpers doesn’t exist.

However, these variations do work:

class Clear::Migration::Table < Clear::Migration::Operation
  include ::Clear::Migration::FullTextSearchableTableHelpers
end
class Clear::Migration::Table < Clear::Migration::Operation
  include FullTextSearchableTableHelpers
end

This is just one of many issues cropping up, and I’ve been unable to get everything running. I’m also encountering strange symbols like Clear::Migration::Clear::Migration, which suggests that objects are being referenced within nested modules incorrectly. This is confusing, especially since all my require statements are within the program’s scope.

I haven’t opened an issue on GitHub yet because I haven’t been able to distill the bug into a simple, reproducible form. I would really appreciate it if someone could clone the project, try running the specs, and help me troubleshoot these problems.

In the meantime, does anyone know the best way to revert to an older version of Crystal? The Snap install doesn’t offer channels for older versions. The last time I did any maintenance was in April 2023, and I used the latest Crystal build available at that time. Unfortunately, the shard.yml doesn’t specify an exact version, so I’m unsure which version was used.

I’m under a bit of pressure to do some maintenance builds for a client and am stuck until I can resolve this. Any help would be greatly appreciated!

Update: I was able to compile on crystal v1.8.0. So I guess one or a few breaking changes in the last 5 versions caused this problem. I wasn’t able to pin-point in the changelog.

I tried to replace every Clear::* to ::Clear::* instance in the library to force absolute path resolution but other problems arose, which seem unrelated (or at least confusing).
I think it relates to the macro used to build stuff in the library.
I’m puzzled about the issue, and would love to know what is going on exactly.

How to reproduce that?

shards build for d588bbd on my laptop is works

I’m fairly sure you’re being hit by:

  1. Undefined const regression on master · Issue #14489 · crystal-lang/crystal · GitHub
  2. Namespaced type with nested name reopens type in parent namespace · Issue #11181 · crystal-lang/crystal · GitHub

These were both bugs that were fixed that caused usages that were dependent on that faulty behavior to break. I’m not familiar enough with the codebase to know where to point you, but will likely have to ensure 2 things:

  1. Calls to macros with the global prefix previously were ignored. So like if you have a macro that is passed ::Foo then does something with it by calling .id on it, previously it would be Foo, but is now properly ::Foo. This can lead to issues, esp when creating a hash of values as ::Foo would not match Foo in a hash lookup. So will need to normalize them in some way either on add or on read.
  2. Ensure that you’re not like duplicating paths within modules. I had to make a similar, albeit smaller fix in Athena: Do not nest module definitions by Blacksmoke16 · Pull Request #402 · athena-framework/athena · GitHub. Before it just worked and Athena::Serializer::Model was added as if it was just Model, but now properly is interpreted as Athena::Serializer::Athena::Serializer::Model which is no good.
1 Like

Here’s my fix for jennifer.cr:

Thanks for the prompt replies, I truly appreciate!

Indeed, as for Jennifer.cr, I tried to use global scope as much as possible but hit other issues. Well, I guess it’s the way to go.
I will try to find some time this week to dive into it and fix it.

1 Like