diff --git a/lib/spitfire.ex b/lib/spitfire.ex index 534dd58..8c8942e 100644 --- a/lib/spitfire.ex +++ b/lib/spitfire.ex @@ -2180,7 +2180,7 @@ defmodule Spitfire do {ast, parser} = cond do - current_token(parser) == :-> and peek_token(parser) == :end -> + current_token(parser) == :-> and peek_token(parser) in [:")", :end, :eof] -> parser = next_token(parser) {ast, parser} diff --git a/test/spitfire_test.exs b/test/spitfire_test.exs index a746909..a0b921d 100644 --- a/test/spitfire_test.exs +++ b/test/spitfire_test.exs @@ -2348,6 +2348,14 @@ defmodule SpitfireTest do end) end + # https://github.com/elixir-lang/expert/issues/461 + test "fn -> followed by closing delimiter does not hang" do + assert {:error, _ast, _errors} = Spitfire.parse("fn ->)") + assert {:error, _ast, _errors} = Spitfire.parse("fn ->") + assert {:error, _ast, _errors} = Spitfire.parse("Enum.map(fn ->)") + assert {:error, _ast, _errors} = Spitfire.parse("fn ->\n)") + end + test "missing bitstring brackets" do code = """ <