Anyolite / anyolite

Embedded mruby/Ruby for Crystal
https://anyolite.github.io/anyolite
MIT License
162 stars 10 forks source link

Using "colorize" breaks builds #19

Closed mgomes closed 2 years ago

mgomes commented 2 years ago

When using the "colorize" standard lib, it seems to cause a compilation error:

There was a problem expanding macro 'resolve_from_ruby_to_crystal'

Code in macro 'resolve_from_ruby_to_crystal'

 5 | Anyolite::Macro.resolve_from_ruby_to_crystal(_rb, __temp_984.values[0], Anyolite::HelperClasses::Color, Color, options: {:context => Anyolite::HelperClasses, :return_nil => false, :block_arg_number => nil, :block_return_type => nil, :store_block_arg => false, :type_vars => [] of ::NoReturn, :type_var_names_annotation => nil, :type_var_names => nil, :empty_regular => true}, debug_information: "colorize - [fore : Color]")
     ^
Called macro defined in lib/anyolite/src/macros/ArgConversions.cr:187:5

 187 | macro resolve_from_ruby_to_crystal(rb, arg, arg_type, raw_arg_type, options = {} of Symbol => NoReturn, debug_information = nil)

Which expanded to:

 > 3 |           
 > 4 |           
 > 5 |           Anyolite::Macro.resolve_from_ruby_to_crystal(_rb, __temp_984.values[0], Anyolite::Color, Color, options: {:context => Anyolite, :return_nil => false, :block_arg_number => nil, :block_return_type => nil, :store_block_arg => false, :type_vars => [] of ::NoReturn, :type_var_names_annotation => nil, :type_var_names => nil, :empty_regular => true}, debug_information: "colorize - [fore : Color]")
                 ^
Error: Could not resolve type Color, which is a Path (colorize - [fore : Color])

Reproduce

Adding:

require "colorize"

somewhere in your project will trigger this.

mgomes commented 2 years ago

I think I see why this gets put in scope: https://github.com/crystal-lang/crystal/blob/master/src/colorize.cr#L200-L202.

I didn't realize colorize injected itself like that.

Hadeweka commented 2 years ago

Yeah, Colorize makes things a bit weird, since the colorize method is not directly compatible with Anyolite (unless the user modifies it specifically).

If you don't need to wrap the colorize method, you can simply use the following snippet in your code:

module Colorize 
  @[Anyolite::ExcludeInstanceMethod("colorize")] 
  module ObjectExtensions 
  end 
end

This should technically prevent the problematic method from being wrapped, without disabling it in Crystal.

Maybe I will put this into the Wiki soon, this seems to be a not too uncommon special case.

mgomes commented 2 years ago

I removed it from my project as a workaround since I only use it in a few spots. The problem I realized is that a lot of other shards use it. So far “teeplate” and “crest” are ones I’ve found.

I’ll see if I can do anything as a workaround.

On Sep 3, 2022, at 4:19 PM, Philipp Schulz @.***> wrote:

 Yeah, Colorize makes things a bit weird, since the colorize method is not directly compatible with Anyolite (unless the user modifies it specifically).

If you don't need to wrap the colorize method, you can simply use the following snippet in your code:

module Colorize @[Anyolite::ExcludeInstanceMethod("colorize")] module ObjectExtensions end end This should technically prevent the problematic method from being wrapped, without disabling it in Crystal.

Maybe I will put this into the Wiki soon, this seems to be a not too uncommon special case.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

mgomes commented 2 years ago

My apologies, I read your suggested workaround more closely and this definitely works for me. Thank you! 🙏

Hadeweka commented 2 years ago

Fixing the problem completely (except for special cases) is not possible with Anyolite (since this is technically intended behavior), so I added a short comment on how to fix this to the wiki (https://github.com/Anyolite/anyolite/wiki/Limitations-and-solutions).