Skip to content

Commit 561338d

Browse files
authored
Return [{mod, bin}] from Code.compile_file/2, require_file/2, load_file/2 (#9864)
This was the documented behaviour on 1.9 that was broken on v1.10: (version `git` is this branch) $ cat a.ex defmodule A, do: nil $ for v in 1.9.4-otp-22 1.10.2-otp-22 git; do asdf local elixir $v && echo $v; elixir -e 'IO.inspect Code.compile_file("a.ex")'; done 1.9.4-otp-22 [{A, <<70, 79, ...>>} 1.10.2-otp-22 [{A, %{attributes: [], ...}] git [{A, <<70, 79, ...>>} $ for v in 1.9.4-otp-22 1.10.2-otp-22 git; do asdf local elixir $v && echo $v; elixir -e 'IO.inspect Code.require_file("a.ex")'; done 1.9.4-otp-22 [{A, <<70, 79, ...>>}] 1.10.2-otp-22 [{A, %{attributes: [], ...}] git [{A, <<70, 79, ...>>}] $ for v in 1.9.4-otp-22 1.10.2-otp-22 git; do asdf local elixir $v && echo $v; elixir -e 'IO.inspect Code.load_file("a.ex")'; done 1.9.4-otp-22 [{A, <<70, 79, ...>>}] 1.10.2-otp-22 warning: Code.load_file/1 is deprecated. Use Code.require_file/2 or Code.compile_file/2 instead nofile:1 [{A, %{attributes: [], ...}] git warning: Code.load_file/1 is deprecated. Use Code.require_file/2 or Code.compile_file/2 instead nofile:1 [{A, <<70, 79, ...>>}]
1 parent 6963bc9 commit 561338d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/elixir/lib/code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,6 @@ defmodule Code do
14471447
defp verify_loaded(loaded) do
14481448
maps_binaries = Enum.map(loaded, fn {_module, map, binary} -> {map, binary} end)
14491449
Module.ParallelChecker.verify(maps_binaries, [])
1450-
Enum.map(loaded, fn {module, map, _binary} -> {module, map} end)
1450+
Enum.map(loaded, fn {module, _map, binary} -> {module, binary} end)
14511451
end
14521452
end

lib/elixir/test/elixir/code_test.exs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@ defmodule CodeTest do
103103
test "compile_file/1" do
104104
assert Code.compile_file(fixture_path("code_sample.exs")) == []
105105
refute fixture_path("code_sample.exs") in Code.required_files()
106+
107+
assert [{CompileSample, binary}] = Code.compile_file(fixture_path("compile_sample.ex"))
108+
assert is_binary(binary)
109+
after
110+
:code.purge(CompileSample)
111+
:code.delete(CompileSample)
106112
end
107113

108114
test "compile_file/1 also emits checker warnings" do
109115
output =
110116
ExUnit.CaptureIO.capture_io(:stderr, fn ->
111-
Code.compile_file(PathHelpers.fixture_path("checker_warning.exs"))
117+
Code.compile_file(fixture_path("checker_warning.exs"))
112118
end)
113119

114120
assert output =~ "incompatible types"
@@ -122,8 +128,13 @@ defmodule CodeTest do
122128
Code.unrequire_files([fixture_path("code_sample.exs")])
123129
refute fixture_path("code_sample.exs") in Code.required_files()
124130
assert Code.require_file(fixture_path("code_sample.exs")) != nil
131+
132+
assert [{CompileSample, binary}] = Code.require_file(fixture_path("compile_sample.ex"))
133+
assert is_binary(binary)
125134
after
126-
Code.unrequire_files([fixture_path("code_sample.exs")])
135+
Code.unrequire_files([fixture_path("code_sample.exs"), fixture_path("compile_sample.ex")])
136+
:code.purge(CompileSample)
137+
:code.delete(CompileSample)
127138
end
128139

129140
describe "string_to_quoted/2" do

0 commit comments

Comments
 (0)