From 00f8b1e0e5ab22d0d7b89c9615b635e41ca283ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Aug 2024 13:05:21 +0200 Subject: [PATCH] Raise clearer error message if struct is missing on type checker --- lib/elixir/lib/module/types/of.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/elixir/lib/module/types/of.ex b/lib/elixir/lib/module/types/of.ex index a512594e976..ab6c2a17a47 100644 --- a/lib/elixir/lib/module/types/of.ex +++ b/lib/elixir/lib/module/types/of.ex @@ -176,10 +176,15 @@ defmodule Module.Types.Of do # TODO: Use the struct default values to define the default types. def struct(struct, args_types, default_handling, meta, stack, context) do context = remote(struct, :__struct__, 0, meta, stack, context) + + info = + struct.__info__(:struct) || + raise "expected #{inspect(struct)} to return struct metadata, but got none" + term = term() defaults = - for %{field: field} <- struct.__info__(:struct), field != :__struct__ do + for %{field: field} <- info, field != :__struct__ do {field, term} end