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

Remove double .cr.cr extension in require path lookup #13749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions spec/compiler/crystal_path/crystal_path_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,33 @@ describe Crystal::CrystalPath do
it "foo.cr" do
assert_iterates_yielding [
"x/foo.cr",
"x/foo.cr/foo.cr.cr",
"x/foo.cr/src/foo.cr.cr",
"x/foo.cr/foo.cr",
"x/foo.cr/src/foo.cr",
], path.each_file_expansion("foo.cr", "x")
end

it "foo.cr/bar" do
assert_iterates_yielding [
"x/foo.cr/bar.cr",
"x/foo.cr/src/bar.cr",
"x/foo.cr/src/foo.cr/bar.cr",
"x/foo.cr/bar/bar.cr",
"x/foo.cr/src/bar/bar.cr",
"x/foo.cr/src/foo.cr/bar/bar.cr",
], path.each_file_expansion("foo.cr/bar", "x")
end

it "foo.cr/bar.cr" do
assert_iterates_yielding [
"x/foo.cr/bar.cr",
"x/foo.cr/src/bar.cr",
"x/foo.cr/src/foo.cr/bar.cr",
"x/foo.cr/bar.cr/bar.cr",
"x/foo.cr/src/bar.cr/bar.cr",
"x/foo.cr/src/foo.cr/bar.cr/bar.cr",
], path.each_file_expansion("foo.cr/bar.cr", "x")
end

it "foo" do
assert_iterates_yielding [
"x/foo.cr",
Expand All @@ -134,7 +156,7 @@ describe Crystal::CrystalPath do
it "./foo.cr" do
assert_iterates_yielding [
"x/./foo.cr",
"x/./foo.cr/foo.cr.cr",
"x/./foo.cr/foo.cr",
], path.each_file_expansion("./foo.cr", "x")
end

Expand Down
29 changes: 14 additions & 15 deletions src/compiler/crystal/crystal_path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -138,34 +138,33 @@ module Crystal

if !filename_is_relative && shard_path
shard_src = "#{relative_to}/#{shard_name}/src"
shard_path_stem = shard_path.rchop(".cr")

# If it's "foo/bar/baz", check if "foo/src/bar/baz.cr" exists (for a shard, non-namespaced structure)
yield "#{shard_src}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_path_stem}.cr"

# Then check if "foo/src/foo/bar/baz.cr" exists (for a shard, namespaced structure)
yield "#{shard_src}/#{shard_name}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_name}/#{shard_path_stem}.cr"

# If it's "foo/bar/baz", check if "foo/bar/baz/baz.cr" exists (std, nested)
basename = File.basename(relative_filename)
basename = File.basename(relative_filename, ".cr")
yield "#{relative_filename}/#{basename}.cr"

# If it's "foo/bar/baz", check if "foo/src/foo/bar/baz/baz.cr" exists (shard, non-namespaced, nested)
yield "#{shard_src}/#{shard_path}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_path}/#{shard_path_stem}.cr"

# If it's "foo/bar/baz", check if "foo/src/foo/bar/baz/baz.cr" exists (shard, namespaced, nested)
yield "#{shard_src}/#{shard_name}/#{shard_path}/#{shard_path}.cr"

return nil
end

basename = File.basename(relative_filename)
yield "#{shard_src}/#{shard_name}/#{shard_path}/#{shard_path_stem}.cr"
else
basename = File.basename(relative_filename, ".cr")

# If it's "foo", check if "foo/foo.cr" exists (for the std, nested)
yield "#{relative_filename}/#{basename}.cr"
# If it's "foo", check if "foo/foo.cr" exists (for the std, nested)
yield "#{relative_filename}/#{basename}.cr"

unless filename_is_relative
# If it's "foo", check if "foo/src/foo.cr" exists (for a shard)
yield "#{relative_filename}/src/#{basename}.cr"
unless filename_is_relative
# If it's "foo", check if "foo/src/foo.cr" exists (for a shard)
yield "#{relative_filename}/src/#{basename}.cr"
end
end
end

Expand Down
Loading