Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no clear document for how require "foo/bar/baz" work. #677

Open
zw963 opened this issue Mar 17, 2023 · 5 comments
Open

There is no clear document for how require "foo/bar/baz" work. #677

zw963 opened this issue Mar 17, 2023 · 5 comments

Comments

@zw963
Copy link
Contributor

zw963 commented Mar 17, 2023

require "foo/bar/baz"

After i test it, it seem like the lookup path is: (assume CRYSTAL_PATH is lib)

      lib/foo/bar/baz.cr
      lib/foo/bar/baz/baz.cr
      lib/foo/src/bar/baz.cr

But, i never saw any document mention it.

I consider this is a really important concept for the crystal user, but i understood it until now because there no document.

Before this, i have to use absolute path from the lib. e.g. require "foo/src/bar/baz"

@straight-shoota
Copy link
Member

straight-shoota commented Mar 17, 2023

Here you go: https://crystal-lang.org/reference/1.7/syntax_and_semantics/requiring_files.html#other-forms
I think that should be sufficient documentation?

@zw963
Copy link
Contributor Author

zw963 commented Mar 18, 2023

Here you go: https://crystal-lang.org/reference/1.7/syntax_and_semantics/requiring_files.html#other-forms I think that should be sufficient documentation?

Oops, sorry, i don't know why i missing it!

BTW: the explain in other-forms is not accurate, because require "foo/bar/baz" seem like never search foo/src/bar/baz/baz.cr.

@straight-shoota
Copy link
Member

Indeed that seems to be the case. I figure this might be an unintended omission. So we probably need to change the implementation, not the documentation.

I think this might've eventually been lost in crystal-lang/crystal#10820.

I created crystal-lang/crystal#13210 to address the issues with require paths.

@zw963
Copy link
Contributor Author

zw963 commented Mar 22, 2023

Oops, i thought i see it before, but i lose completely now for how require search file.

Let us not think about our implementation(it probably wrong, right?)

What is the expected search path for following requires? (for lib only)

require "foo"

# lib/foo.cr
# lib/foo/foo.cr
# lib/foo/src/foo.cr
# ???
require "foo/bar/baz"

# lib/foo/bar/baz.cr
# lib/foo/bar/baz/baz.cr
# lib/foo/src/bar/baz.cr
# ???

I remember when i first use Crystal (1.4), i read document somewhere said require "foo" will search lib/foo/src/foo/foo.cr, i even try it, it works. but, obviously, it not work anymore now for 1.7.2.

@straight-shoota
Copy link
Member

No, lib/foo/src/foo/foo.cr was ever looked up, neither in Crystal 1.0 nor 1.4. I checked that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants