tjchambers

tjchambers

Erlang: OTP 20
Elixir 1.20.0-rc.3 (9b80ab5) (compiled with Erlang/OTP 28)

I am wondering whether 1.20 of Elixir is supposed to support type checking macro’s that use defoverridable. In rc.3 I am getting dozens of type check warnings for a construction that may be a bit offbeat but serves my purpose. Before I go and try to construct the approach differently, I wanted to see if it is a gap in type checking, or whether the warnings take into account overridden functions.

The warnings are all of this style:

warning: the following clause will never match:

 _ ->

because it attempts to match on the result of:

 ends = scheduled_end(sc)

which has type:

 dynamic(nil)

type warning found at:
│
188 │           _ →
│           ~~~~
│
└─ lib/sct/tasks/services/task_helper.ex:188: Sct.Tasks.AddThemeCloudExclusionsTask.remaining_time/1

Code snippet:

defmodule Sct.Tasks.TaskHelper do

defmacro using(_) do
quote location: :keep do

  @doc """
  Returns the remaining time for the task
  """
  @spec remaining_time(StrategicCollaboration.t() | DateTime.t() | nil) :: String.t()
  def remaining_time(%StrategicCollaboration{active: true} = sc) do
    case ends = scheduled_end(sc) do
      nil ->
        ""
      _ ->
        remaining_time(ends)
    end
  end
      
  def remaining_time(nil), do: ""

  def remaining_time(%DateTime{} = ends) do
        about_when =
          SctWeb.Formatter.relative_time(ends)

        if about_when =~ "ago" do
          " - ended #{about_when}"
        else
          " - ends in #{about_when}"
          |> String.replace(" in in ", " in ")
          |> String.replace("ends in tomorrow", "ends tomorrow")
        end
      end

  @doc """
  Returns the scheduled end time for the task - stub for override
  """
  @spec scheduled_end(StrategicCollaboration.t()) :: DateTime.t() | nil
  def scheduled_end(%StrategicCollaboration{}), do: nil


  defoverridable(
    remaining_time: 1,
    scheduled_end: 1
  )
end

end
end

Example usage:

use Sct.Tasks.TaskHelper


“”"
Returns the scheduled end date for the task. The enddate is
read from the DB.
“”"
def scheduled_end(%StrategicCollaboration{active: true} = sc) do
  Sct.Schedule.Query.outcome_reasoning_schedule(sc).enddate
end




It appears that the type checking is being done on the macro definition which always returns nil for the scheduled_end and therefore sees anything but nil as a type mismatch in the case statement for remaining_time. Of course when the macro is used in a module where schedule_end is overridden it is possible that the overridden return value is a DateTime but sometimes when it has not been established in the DB it returns nil.

The construction I have for the 100+ tasks that use this TaskHelper module work fine, but the type-checking is flagging it as a warning. With 100’s of warnings it is a lot of noise.

I believe I may be able to re-construct this is some other manner, but wanted to bring it to one’s attention in case I am (likely) missing something.

Showing Posts 1 to 3

tjchambers

tjchambers OP

I have been able to revamp my macro use in a manner that makes this issue above academic. It may be useful (or not…) to have an explanation about how macros that have functions that are overridden is handled (or not handled) by the type system as it evolves.

But for me this is a non-issue.

josevalim

josevalim

Creator of Elixir

The type checker always sees the final version of the code. So if in the final version the function returns nil because it is not overridden, then that’s what is type checked. A quick solution here is to mark the code as generated:

quote generated: true do

But generally speaking, if you can reorganize the code to no longer emit dead code, that would be indeed preferred!

tjchambers

tjchambers OP

Very good to know - I will keep that in mind.

FWIW I have resolved ALL of my warnings with rc.3 .

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews