Skip to content

Instantly share code, notes, and snippets.

@TattdCodeMonkey
Last active February 26, 2016 11:52
Show Gist options
  • Save TattdCodeMonkey/2d634edabebd8d4cbf2e to your computer and use it in GitHub Desktop.
Save TattdCodeMonkey/2d634edabebd8d4cbf2e to your computer and use it in GitHub Desktop.
defmodule Nothing do
defstruct([])
@type t :: %__MODULE__{}
end
defmodule Name do
defstruct first: "", last: ""
@type t :: %__MODULE__{first: String.t, last: String.t}
end
defmodule Character do
@type t :: %__MODULE__{
name: Name.t | Nothing.t
}
defstruct name: %Nothing{}
# dialyzer return an error for this function
@spec return_test :: Name.t | Nothing.t
def return_test, do: "Dan"
# dialyzer does not give an error for this function event though
# name does is a string instead of Name.t | Nothing.t
@spec return_dan :: __MODULE__.t
def return_dan, do: %Character{name: "Dan"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment