crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.51k stars 1.62k forks source link

Undefined const regression on master #14489

Closed Blacksmoke16 closed 7 months ago

Blacksmoke16 commented 7 months ago

It seems #11208 caused a regression in master, for example from nightly CI:

src/components/framework
  Showing last frame. Use --error-trace for full trace.

  In src/components/framework/spec/controllers/query_param_controller.cr:74:7

   74 | @[ATHR::Time::Format(format: "%Y--%m//%d  %T")]
          ^-----------------
  Error: Error: undefined constant ATHR::Time::Format

https://github.com/athena-framework/athena/actions/runs/8682447817/job/23806982620

Best I can tell its because the annotation is defined via a nested macro?

macro configuration_annotation(name, *args, &)
  annotation {{name.id}}; end
end

struct MyApp::ValueResolvers::Time
  macro configuration(name, *args)
    configuration_annotation ::{{@type}}::{{name.id}}
  end

  configuration Format
end

class MyClass
  @[MyApp::ValueResolvers::Time::Format(format: "%Y--%m//%d  %T")]
  def time
    {{pp @def.annotations}}
  end
end

pp MyClass.new.time

On 0efbf53cc2762431146eb028de95691cac7db039:

$ ccrystal test.cr
Using compiled compiler at .build/crystal
Showing last frame. Use --error-trace for full trace.

In test.cr:14:5

 14 | @[MyApp::ValueResolvers::Time::Format(format: "%Y--%m//%d  %T")]
        ^----------------------------------
Error: undefined constant MyApp::ValueResolvers::Time::Format

On commit before that:

$ crystal test.cr
[@[MyApp::ValueResolvers::Time::Format(format: "%Y--%m//%d  %T")]]
nil
straight-shoota commented 7 months ago

The issue seems to be that name.id drops the global prefix.

macro foo(path)
  {% p path.id %} # => Foo
end

foo ::Foo
straight-shoota commented 7 months ago

So I guess running athena CI against Crystal nightly has already payed off šŸš€ šŸ˜„

crysbot commented 3 months ago

This issue has been mentioned on Crystal Forum. There might be relevant details there:

https://forum.crystal-lang.org/t/having-hard-time-trying-to-maintain-my-library/7118/4