From 01974543a09a722ca0deb2b29ef21216bc7ed91a Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Thu, 21 Apr 2022 03:01:09 +0200 Subject: [PATCH] Fix dialyzer --- lib/json/ld/compaction.ex | 5 ++++- lib/json/ld/encoder.ex | 4 ++-- lib/json/ld/expansion.ex | 2 +- lib/json/ld/flattening.ex | 3 +-- lib/json/ld/options.ex | 2 +- lib/json_ld.ex | 16 ++++------------ 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/json/ld/compaction.ex b/lib/json/ld/compaction.ex index 25d30c8..1ed1459 100644 --- a/lib/json/ld/compaction.ex +++ b/lib/json/ld/compaction.ex @@ -5,7 +5,10 @@ defmodule JSON.LD.Compaction do alias JSON.LD.{Context, Options} - @spec compact(map | [map], map | nil, Options.convertible()) :: map + # TODO: Why is dialyzer ignoring the spec of context as a potential binary and + # complains about the is_binary(context) in the final cond to never match? + @dialyzer {:nowarn_function, compact: 3} + @spec compact(map | [map], map | binary | nil, Options.convertible()) :: map def compact(input, context, options \\ %Options{}) do options = Options.new(options) active_context = JSON.LD.context(context, options) diff --git a/lib/json/ld/encoder.ex b/lib/json/ld/encoder.ex index 257f885..56e7ab7 100644 --- a/lib/json/ld/encoder.ex +++ b/lib/json/ld/encoder.ex @@ -52,7 +52,7 @@ defmodule JSON.LD.Encoder do @rdf_list to_string(RDF.uri(RDF.NS.RDF.List)) @impl RDF.Serialization.Encoder - @spec encode(RDF.Data.t(), Options.t() | Enum.t()) :: {:ok, String.t()} | {:error, any} + @spec encode(RDF.Data.t(), keyword) :: {:ok, String.t()} | {:error, any} def encode(data, opts \\ []) do with {:ok, json_ld_object} <- from_rdf(data, opts), {:ok, json_ld_object} <- maybe_compact(json_ld_object, opts) do @@ -62,7 +62,7 @@ defmodule JSON.LD.Encoder do # TODO: unless we find a way to allow more optimized encode! versions, remove this since it's never used (see the respective warning) @impl RDF.Serialization.Encoder - @spec encode!(RDF.Data.t(), Options.t() | Enum.t()) :: String.t() + @spec encode!(RDF.Data.t(), Options.convertible()) :: String.t() @dialyzer {:nowarn_function, encode!: 1} def encode!(data, opts \\ []) do case encode(data, opts) do diff --git a/lib/json/ld/expansion.ex b/lib/json/ld/expansion.ex index 2edcd23..954a41c 100644 --- a/lib/json/ld/expansion.ex +++ b/lib/json/ld/expansion.ex @@ -6,7 +6,7 @@ defmodule JSON.LD.Expansion do alias JSON.LD.{Context, Options} alias JSON.LD.Context.TermDefinition - @spec expand(map, Options.t() | Enum.t()) :: [map] + @spec expand(map | [map], Options.convertible()) :: [map] def expand(input, options \\ %Options{}) do options = Options.new(options) active_context = Context.new(options) diff --git a/lib/json/ld/flattening.ex b/lib/json/ld/flattening.ex index 65b2d48..dbbe33e 100644 --- a/lib/json/ld/flattening.ex +++ b/lib/json/ld/flattening.ex @@ -5,8 +5,7 @@ defmodule JSON.LD.Flattening do alias JSON.LD.{NodeIdentifierMap, Options} - @dialyzer {:nowarn_function, flatten: 3} - @spec flatten(map | [map], map | nil, Options.t() | Enum.t()) :: [map] + @spec flatten(map | [map], map | nil, Options.convertible()) :: [map] def flatten(input, context \\ nil, options \\ %Options{}) do options = Options.new(options) expanded = JSON.LD.expand(input, options) diff --git a/lib/json/ld/options.ex b/lib/json/ld/options.ex index 86b0527..bf9f2c0 100644 --- a/lib/json/ld/options.ex +++ b/lib/json/ld/options.ex @@ -16,7 +16,7 @@ defmodule JSON.LD.Options do processing_mode: String.t() } - @type convertible :: t | Enum.t() + @type convertible :: t | keyword | Enum.t() defstruct base: nil, compact_arrays: true, diff --git a/lib/json_ld.ex b/lib/json_ld.ex index 6b1e496..b2cba86 100644 --- a/lib/json_ld.ex +++ b/lib/json_ld.ex @@ -57,9 +57,7 @@ defmodule JSON.LD do Details at """ - @spec expand(map, Options.t() | Enum.t()) :: [map] - defdelegate expand(input, options \\ %Options{}), - to: Expansion + defdelegate expand(input, options \\ %Options{}), to: Expansion @doc """ Compacts the given input according to the steps in the JSON-LD Compaction Algorithm. @@ -74,9 +72,7 @@ defmodule JSON.LD do Details at """ - @spec compact(map | [map], map | nil, Options.t() | Enum.t()) :: map - defdelegate compact(input, context, options \\ %Options{}), - to: Compaction + defdelegate compact(input, context, options \\ %Options{}), to: Compaction @doc """ Flattens the given input according to the steps in the JSON-LD Flattening Algorithm. @@ -90,9 +86,7 @@ defmodule JSON.LD do Details at """ - @spec flatten(map | [map], map | nil, Options.t() | Enum.t()) :: [map] - defdelegate flatten(input, context \\ nil, options \\ %Options{}), - to: Flattening + defdelegate flatten(input, context \\ nil, options \\ %Options{}), to: Flattening @doc """ Generator function for `JSON.LD.Context`s. @@ -112,7 +106,5 @@ defmodule JSON.LD do @doc """ Generator function for JSON-LD node maps. """ - @spec node_map([map], pid | nil) :: map - defdelegate node_map(input, node_id_map \\ nil), - to: Flattening + defdelegate node_map(input, node_id_map \\ nil), to: Flattening end