Dialyxir.Warnings.OpaqueUnion (Dialyxir v1.4.8)

Copy Markdown View Source

A function body yields a type whose opacity is broken by other clauses, or vice versa.

This is a new warning type introduced in OTP 28 as part of the nominal types (EEP-69) rework of opaque type checking.

Example

defmodule OpaqueStruct do
  defstruct [:opaque]

  @opaque t :: %OpaqueStruct{}
end

defmodule Example do
  @spec bad_union(boolean()) :: OpaqueStruct.t()
  def bad_union(true), do: %OpaqueStruct{}
  def bad_union(false), do: OpaqueStruct.new()
end