Skip to content

Commit c39c42e

Browse files
committed
fix crash when suggesting specs on protocol defs with default args
1 parent 9bf6b2e commit c39c42e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

apps/language_server/lib/language_server/providers/code_lens/type_spec/contract_translator.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,16 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
144144
cond do
145145
Code.ensure_loaded?(mod) and function_exported?(mod, :__protocol__, 1) ->
146146
# defprotocol
147-
# defs in defprotocol do not have when and have at least 1 arg
148-
{:"::", [], [{:foo, [], [_ | rest_args]}, res]} = ast
149-
# first arg in defprotocol defs is always of type t
150-
{:"::", [], [{:foo, [], [{:t, [], []} | rest_args]}, res]}
147+
case ast do
148+
{:"::", [], [{:foo, [], [_ | rest_args]}, res]} ->
149+
# ordinary defs in defprotocol do not have when and have at least 1 arg
150+
# first arg in defprotocol defs is always of type t
151+
{:"::", [], [{:foo, [], [{:t, [], []} | rest_args]}, res]}
152+
153+
{:"::", [], [{:foo, [], []}, _]} ->
154+
# def with default arg
155+
ast
156+
end
151157

152158
Code.ensure_loaded?(mod) and function_exported?(mod, :__impl__, 1) ->
153159
# defimpl

0 commit comments

Comments
 (0)