Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

String.slice(str, 0, -1) raises FunctionClauseError

未關閉
#496 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
elixir, javascript
領域
compilers

研究方向

重現 String.slice(str, 0, -1) 的情況,並從 lib/elixir_script/passes/translate/form.ex:28 開始,接著檢查 lib/elixir_script/passes/translate/forms/map.ex 中的 map 處理,以及 lib/elixir_script/passes/translate/function.ex 中的編譯路徑。完成的條件是:該表達式能在不出現所回報的 FunctionClauseError 的情況下編譯,且產生的 JavaScript 行為已被涵蓋或驗證。

由索引模型根據 Issue 內容生成。

描述

This snippet of Elixir:

String.slice(str, 0, -1)

Started with slice/2 form of this call, but swapped to slice/3 to confirm the error wasn't being generated by the Elixir range.

Raises the following exception

** (EXIT from #PID<0.95.0>) an exception was raised:
** (FunctionClauseError) no function clause matching in ElixirScript.Translate.Form.compile/2
lib/elixir_script/passes/translate/form.ex:28: ElixirScript.Translate.Form.compile(&Inspect.inspect/2, %{anonymous_fn: false, function: {:struct, nil}, in_guard: false, module: Inspect.Opts, pid: #PID<0.200.0>, vars: %{}})
lib/elixir_script/passes/translate/form.ex:16: ElixirScript.Translate.Form.compile!/2
lib/elixir_script/passes/translate/forms/map.ex:37: anonymous fn/2 in ElixirScript.Translate.Forms.Map.compile/2
(elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
(elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
lib/elixir_script/passes/translate/forms/map.ex:32: ElixirScript.Translate.Forms.Map.compile/2
lib/elixir_script/passes/translate/form.ex:16: ElixirScript.Translate.Form.compile!/2
lib/elixir_script/passes/translate/function.ex:170: ElixirScript.Translate.Function.compile_block/2

Modified Transcript.Form.compile! as follows:

  @spec compile!(any, map) :: ESTree.Node.t()
  def compile!(ast, state) do
    {js_ast, _} = compile(ast, state)
    js_ast
  rescue
    e -> Logger.debug inspect({:compile!, ast, state})
         raise RuntimeError, message: inspect({"compile!/2", e})
  end

Which revealed the following debugging info:

03:45:21.580 [debug] {:compile!, &Inspect.inspect/2, %{anonymous_fn: false, function: {:struct, nil}, in_guard: false, module: Inspect.Opts, pid: #PID<0.200.0>, vars: %{}}}

03:45:21.696 [debug] {:compile!, {:%{}, [line: 74], [struct: Inspect.Opts, base: :decimal, binaries: :infer, char_lists: :infer, charlists: :infer, custom_options: [], inspect_fun: &Inspect.inspect/2, limit: 50, pretty: false, printable_limit: 4096, safe: true, structs: true, syntax_colors: [], width: 80]}, %{anonymous_fn: false, function: {:struct, nil}, in_guard: false, module: Inspect.Opts, pid: #PID<0.200.0>, vars: %{}}}

Thoughts

Not too familiar with this codebase, but I'm working from the premise that inspect_fun: &Inspect.inspect/2 might be malformed, for it to be promoted into the ast parameter of compile!.

主要語言
Elixir
星號
1.6k
分支
69
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

elixirscript/elixirscript 的其他 Issue

查看 elixirscript/elixirscript 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。