Skip to content

Commit 48b0d08

Browse files
committed
Fix warnings
1 parent b4915b5 commit 48b0d08

2 files changed

Lines changed: 19 additions & 27 deletions

File tree

lib/elixir/lib/module/types/expr.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ defmodule Module.Types.Expr do
762762

763763
cond do
764764
stack.mode != :infer and previous != none() and subtype?(clause_type, previous) ->
765+
stack = %{stack | meta: meta}
765766
{previous, Pattern.badpattern_error(clause, 0, info, stack, context)}
766767

767768
precise? ->

lib/elixir/lib/protocol.ex

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ defmodule Protocol do
816816
# Set up a clear slate to store defined functions
817817
@__functions__ []
818818
@fallback_to_any false
819+
@undefined_impl_description ""
819820

820821
# Invoke the user given block
821822
_ = unquote(block)
@@ -935,12 +936,7 @@ defmodule Protocol do
935936
nil
936937
end
937938

938-
# Disable Dialyzer checks - before and after consolidation
939-
# the types could be more strict
940-
@dialyzer {:nowarn_function, __protocol__: 1, impl_for: 1, impl_for!: 1}
941-
942939
@doc false
943-
@spec impl_for(term) :: atom | nil
944940
Kernel.def(impl_for(data))
945941

946942
# Define the implementation for structs.
@@ -976,35 +972,34 @@ defmodule Protocol do
976972
unquote(any_impl_for)
977973
end
978974

979-
undefined_impl_description =
980-
Module.get_attribute(__MODULE__, :undefined_impl_description, "")
975+
# Internal handler for Structs
976+
Kernel.defp struct_impl_for(struct) do
977+
case Code.ensure_compiled(Protocol.__concat__(__MODULE__, struct)) do
978+
{:module, module} -> module
979+
{:error, _} -> unquote(any_impl_for)
980+
end
981+
end
981982

982983
@doc false
983-
@spec impl_for!(term) :: atom
984984
if any_impl_for do
985985
Kernel.def impl_for!(data) do
986986
impl_for(data)
987987
end
988988
else
989989
Kernel.def impl_for!(data) do
990-
impl_for(data) ||
991-
raise(Protocol.UndefinedError,
992-
protocol: __MODULE__,
993-
value: data,
994-
description: unquote(undefined_impl_description)
995-
)
996-
end
997-
end
998-
999-
# Internal handler for Structs
1000-
Kernel.defp struct_impl_for(struct) do
1001-
case Code.ensure_compiled(Protocol.__concat__(__MODULE__, struct)) do
1002-
{:module, module} -> module
1003-
{:error, _} -> unquote(any_impl_for)
990+
unquote(
991+
quote generated: true do
992+
impl_for(data) ||
993+
raise(Protocol.UndefinedError,
994+
protocol: __MODULE__,
995+
value: data,
996+
description: @undefined_impl_description
997+
)
998+
end
999+
)
10041000
end
10051001
end
10061002

1007-
# Inline struct implementation for performance
10081003
@compile {:inline, struct_impl_for: 1}
10091004

10101005
if not Module.defines_type?(__MODULE__, {:t, 0}) do
@@ -1020,10 +1015,6 @@ defmodule Protocol do
10201015
@__protocol__ [fallback_to_any: !!@fallback_to_any]
10211016

10221017
@doc false
1023-
@spec __protocol__(:module) :: __MODULE__
1024-
@spec __protocol__(:functions) :: [{atom(), arity()}]
1025-
@spec __protocol__(:consolidated?) :: boolean()
1026-
@spec __protocol__(:impls) :: :not_consolidated | {:consolidated, [module()]}
10271018
Kernel.def(__protocol__(:module), do: __MODULE__)
10281019
Kernel.def(__protocol__(:functions), do: unquote(:lists.sort(@__functions__)))
10291020
Kernel.def(__protocol__(:consolidated?), do: false)

0 commit comments

Comments
 (0)