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

Fix the termination issue of Document.Store caused by incomplete syntax errors. #528

Merged
merged 1 commit into from
Dec 28, 2023
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
7 changes: 6 additions & 1 deletion apps/common/lib/lexical/ast/analysis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ defmodule Lexical.Ast.Analysis do
end
end

defp fetch_alias_as(options) do
defp fetch_alias_as(options) when is_list(options) do
alias_as =
Enum.find_value(options, fn
{{:__block__, _, [:as]}, {:__aliases__, _, [alias_as]}} -> alias_as
Expand All @@ -345,4 +345,9 @@ defmodule Lexical.Ast.Analysis do
_ -> {:ok, alias_as}
end
end

# When the `as` section is incomplete, like: `alias Foo, a`
defp fetch_alias_as(_) do
:error
end
end
11 changes: 11 additions & 0 deletions apps/common/test/lexical/ast_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ defmodule Lexical.AstTest do
refute analysis.ast
assert {:error, _} = analysis.parse_error
end

test "creates an analysis from a document with incomplete `as` section" do
code = ~q[
defmodule Invalid do
alias Foo, a
end
]

assert %Analysis{} = analysis = analyze(code)
assert {:defmodule, _, _} = analysis.ast
end
end

defp ast(s) do
Expand Down
Loading