Elixir v1.10.0-rc.0 released

Greate update!

4 Likes

@josevalim

Would there be an is_struct/2 version?

defmodule Example do
  defstruct […]

  def sample(struct) when is_struct(struct, __MODULE__), do: {:ok, struct}
  def sample(_), do: :error
end

if not is there any naming convention for it (like we have @type t spec)?

defmodule Example do
  defstruct […]

  @type t :: %__MODULE__{…}

  defguard is_t(struct) when is_struct(struct) and :erlang.map_get(:__struct__, struct) === __MODULE__

  def sample(struct) when is_t(struct), do: {:ok, struct}
  def sample(_), do: :error
end

Would be added also other features discussed in this topic?

Looks like Bob actually sleeps more than a typical human. :smiley:

For sure generally I don’t mind, but if I remember correctly Bob had exactly same problem with at least one previous release as well, so it does not a single standalone edge-case.

Also there are some extra warnings when building elixir at tests step:

2 Likes

Pelemay 0.0.5 works well on Elixir v1.10.0-rc.0.

Try them!

9 Likes

Unfortunately no. There were some complexities in implementing it. Those interested can dig the discussion on GitHub and link it back here please. :slight_smile:

Haha, we are looking into it. Bob is like conference wifi, when it works, nobody notices. When it fails, everyone does! :smiley:

Thanks, we had already noticed it and we are on it. The warnings are correct in being emitted, but their content is partially wrong.

4 Likes

Maybe make checking https://bobs-list.kobrakai.de/ part of the rc release todo list :slight_smile:

2 Likes

Bob is good now and the archives and docs for 1.10.0-rc.0 are available.

6 Likes

cc @Eiji

However there was a proposed solution on Erlang issue tracker and I need to check if this will pass the Dialyzer and will emit no warnings.

EDIT: It will not work, at least not without deep changes to the Modules.Types.Infer as currently adding or :fail to the guard generates hell lot of warnings.

3 Likes

I’m not sure if this is intended as a breaking change, but I guess at least it should be added to the changelog: URI error on getting gravatar elixir v1.10.0-rc.0

1 Like

Pattern matching works great here without needing is_struct/2.

def sample(%__MODULE__{} = struct), do: {:ok, struct}

Actually not sure in what situations I should use the new guard since is_struct/1 could also be written as:

def sample(%_{} = struct), do: {:ok, struct}

The guard reads intent more explicitly to me but AFAIK the pattern matching works as well.

1 Like

That doesn’t work. I get this error when trying to pass a function to mix xref callers:

** (Mix) xref callers MODULE expects a MODULE, got: XXX.Import.Jobs.process_job

sure, it’s more useful in defguard and defguardp

Imagine you want to write is_t guard like:

defmodule Example do
  defstruct […]

  @type t :: %__MODULE__{…}

  defguard is_t(struct) when is_struct(struct, __MODULE__) …
end
2 Likes

Oh, neat. Please open up a new issue so we can discuss how to address this!

Wlll do, thanks.

1 Like

I’m also wondering what the use case for is_struct/1 is because pattern matching can already do The same thing with an underscore like you said.

I guess that using it inside of defining a new guard is the only new thing really?

In my case it would be readability. %_{} isn’t exactly something that immediately catches your eye while is_struct is readily noticeable.

All subjective tastes of course. But to me is_struct has a very valid place.

is_struct/1 allows things that are not possible with pattern matches, e.g.: when is_struct(term) or is_integer(term) and when not is_struct(term).

10 Likes

Even better! Thanks for the clarification.

Not sure if this is useful, but here is how erl_expand_records forces an exception in a guard:

Here is how warnings are suppressed (for both the Erlang compiler and Dialyzer):

9 Likes

2 posts were split to a new topic: Getting no such file or directory’, ‘ssl.app’ error after upgrading Elixir

It does not work correctly any more. https://github.com/elixir-lsp/elixir_sense, the library behind https://github.com/elixir-lsp/elixir-ls uses Mix.Tasks.Xref.calls/0 and it does not properly register some function calls. I know that it is now deprecated but it should not be broken.

This was never public interface of Mix, so there were no guarantees that this will work. This function was never safe to call.

1 Like