crystal-lang / crystal

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

Using `include` with a `module` with a `private macro` exposes it #14578

Closed sol-vin closed 2 months ago

sol-vin commented 2 months ago

Issue:

Using include with a module that has a private macro exposes the macro publicly

Code:

module A
  private macro test(t)
    {% puts "HI #{t}" %}
  end
end

A.test(1)

include A

test(2)

throws an Error: private macro 'test' called for A

module A
  private macro test(t)
    {% puts "HI #{t}" %}
  end
end

include A

test(2)

Produces:

HI 2

What it should do:

Throw an Error: private macro 'test' called for A

straight-shoota commented 2 months ago

This seems to work as expected. include A makes all features in A available in the parent namespace. A private macro is still visible from the same namespace, so it makes sense that you can call it after include A.

Note that the visibility of test does not change. Calling it from a different namespace is still prohibited.

module A
  private macro test(t)
    {% puts "HI #{t}" %}
  end
end

module B
  include A
  test(2)
end

B.test(3) # Error: private macro 'test' called for B
sol-vin commented 2 months ago

Ah, my bad, closed