-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Dialyzer warnings on opaque protocol calls (#5286)
Prior to this change, calling a protocol function with an opaque type would yield a warning, as Dialyzer concludes that the impl_for/1 function can't handle opaque arguments, since all clauses would destructure their arguments in some way. By adding a catch-all clause that does not destructure its argument, Dialyzer no longer draws this conclusion, and the warnings go away. As noted in the protocol.ex comment, this is technically a hack as it relies on Dialyzer not being smart enough. However, I would not expect it to break soon, if ever. Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/elixir/test/elixir/fixtures/dialyzer/protocol_opaque.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Dialyzer.ProtocolOpaque do | ||
def circus() do | ||
Dialyzer.ProtocolOpaque.Entity.speak(Dialyzer.ProtocolOpaque.Duck.new) | ||
end | ||
end | ||
|
||
defprotocol Dialyzer.ProtocolOpaque.Entity do | ||
def speak(entity) | ||
end | ||
|
||
defmodule Dialyzer.ProtocolOpaque.Duck do | ||
@opaque t :: %__MODULE__{} | ||
defstruct feathers: :white_and_grey | ||
|
||
@spec new :: t | ||
def new(), do: %__MODULE__{} | ||
|
||
defimpl Dialyzer.ProtocolOpaque.Entity do | ||
def speak(%Dialyzer.ProtocolOpaque.Duck{}), do: "Quack!" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters