Skip to content

Commit 7e1bf3b

Browse files
committed
Creating info map inside of __info__ function to prevent stack overflow
1 parent 76bb876 commit 7e1bf3b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

lib/elixir_script/passes/translate/module.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ defmodule ElixirScript.Translate.Module do
6161
_ ->
6262
{ compiled_functions, _ } = Enum.map_reduce(combined_defs, state, &Function.compile(&1, &2))
6363

64-
info_map = make_info_map(module, state)
65-
info_function = make_info_function()
66-
compiled_functions = [info_map, info_function] ++ compiled_functions
64+
info_function = make_info_function(module, state)
65+
compiled_functions = [info_function] ++ compiled_functions
6766

6867
js_ast = ElixirScript.ModuleSystems.Namespace.build(
6968
module,
@@ -208,7 +207,9 @@ defmodule ElixirScript.Translate.Module do
208207

209208
# Builds the __info__ function that Elixir modules
210209
# have.
211-
defp make_info_function do
210+
defp make_info_function(module, state) do
211+
info_map = make_info_map(module, state)
212+
212213
get_call = Helpers.call(
213214
J.member_expression(
214215
J.identifier("__info__map__"),
@@ -233,6 +234,7 @@ defmodule ElixirScript.Translate.Module do
233234
)
234235

235236
body = J.block_statement([
237+
info_map,
236238
value,
237239
body,
238240
J.throw_statement(

test/integration/integration_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ defmodule ElixirScript.Integration.Test do
66
val = call_compiled_function Atom, :to_string, [:atom]
77
assert val == "atom"
88
end
9+
10+
test "String interpolation with number" do
11+
val = call_compiled_function Integration, :test_string_interpolation, []
12+
assert val == "5"
13+
end
914
end

test/support/integration.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Integration do
2+
@moduledoc false
3+
4+
def test_string_interpolation do
5+
"#{5}"
6+
end
7+
end

0 commit comments

Comments
 (0)