You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require"spec"require"../../src/foo"# << This path is wrong and doesn't exist.# ...
The above code does not result in a compile time error but instead requires the file src/foo.cr.
This is highly confusing in my opinion and should be a compile time error.
If I understand correctly, the issue that require considers that ../../src/spec_helper could belong to a shard named .. and will search lib/../src/../src/spec_helper.cr but .. is a relative path, and require should only search for a relative ../../src/spec_helper.cr file.
I updated the issue to show the filestructure more clearly and removed the other unnecessary files. I want to require foo, but the path I entered is wrong (one .. too many) so I expect this to error, which it doesn't.
@ysbaddaden I think you understood correctly, that's what I'm seeing.
In a filesystem structure such as
where
spec_helper.cr
contains:The above code does not result in a compile time error but instead requires the file
src/foo.cr
.This is highly confusing in my opinion and should be a compile time error.
I can't quite catch this behaviour from https://crystal-lang.org/reference/syntax_and_semantics/requiring_files.html. I do believe the code is running into this https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/crystal_path.cr#L71 line and is effectively working because
../src/../src/foo.cr
is found, but still I think this shouldn't resolve, sincerequire "../../src/foo
from insidespec_helper
is simply plain wrong.I am running on macOS:
but obviously the code is still the same in HEAD.
The text was updated successfully, but these errors were encountered: