Crystal: Private top-level constants aren't private

Created on 2 Jun 2019  路  1Comment  路  Source: crystal-lang/crystal

Take these three files in Crystal 0.28.0:

main.cr:

require "./one.cr"
require "./two.cr"

one.cr:

private CONSTANT = 1;

two.cr:

private CONSTANT = 2;

Run crystal build main.cr, and you get the following error:

Error in main.cr:2: while requiring "./two.cr"

require "./two.cr"
^

in two.cr:1: already initialized constant CONSTANT

private CONSTANT = 2;
        ^~~~~~~~

This worked in an earlier version, and the docs specify that "private can be used with class, module, lib, enum, alias and constants". It seems to be a regression in a recent version.

bug topicsemantic

Most helpful comment

Mm that was a tough one, especially with the 2 hr long compile of LLVM 馃槄

yay -S llvm50
wget https://archive.org/download/archlinux_pkg_crystal/crystal-0.24.2-2-x86_64.pkg.tar.xz
sudo pacman -U crystal-0.24.2-2-x86_64.pkg.tar.xz
echo 'require "./one.cr"' > main.cr
echo 'require "./two.cr"' >> main.cr
echo 'private CONSTANT = 1;' > one.cr
echo 'private CONSTANT = 2;' > two.cr
git bisect start; git bisect good 0.24.2; git bisect bad 0.25.0
git bisect run bash -c 'make || (make clean; make) || return 125; ./bin/crystal build main.cr'

5cd78fa51284d22dcf5b485b0939e790d2f54f54 is the first bad commit

https://github.com/crystal-lang/crystal/pull/5883 "Allow a path to declare a constant"

>All comments

Mm that was a tough one, especially with the 2 hr long compile of LLVM 馃槄

yay -S llvm50
wget https://archive.org/download/archlinux_pkg_crystal/crystal-0.24.2-2-x86_64.pkg.tar.xz
sudo pacman -U crystal-0.24.2-2-x86_64.pkg.tar.xz
echo 'require "./one.cr"' > main.cr
echo 'require "./two.cr"' >> main.cr
echo 'private CONSTANT = 1;' > one.cr
echo 'private CONSTANT = 2;' > two.cr
git bisect start; git bisect good 0.24.2; git bisect bad 0.25.0
git bisect run bash -c 'make || (make clean; make) || return 125; ./bin/crystal build main.cr'

5cd78fa51284d22dcf5b485b0939e790d2f54f54 is the first bad commit

https://github.com/crystal-lang/crystal/pull/5883 "Allow a path to declare a constant"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lgphp picture lgphp  路  3Comments

pbrusco picture pbrusco  路  3Comments

relonger picture relonger  路  3Comments

grosser picture grosser  路  3Comments

ArthurZ picture ArthurZ  路  3Comments