Skip to content

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

Open
@zw963

Description

@zw963
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"

Activity

straight-shoota

straight-shoota commented on Mar 17, 2023

@straight-shoota
Member

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

zw963 commented on Mar 18, 2023

@zw963
ContributorAuthor

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

straight-shoota commented on Mar 21, 2023

@straight-shoota
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

zw963 commented on Mar 22, 2023

@zw963
ContributorAuthor

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

straight-shoota commented on Mar 22, 2023

@straight-shoota
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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @straight-shoota@zw963

      Issue actions

        There is no clear document for how `require "foo/bar/baz"` work. · Issue #677 · crystal-lang/crystal-book