From 0114184659d330ee5550af94293de85690bcd196 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Sun, 8 Mar 2026 14:18:27 +0900 Subject: [PATCH] Warn when defining @type record(), fixes CI on OTP29 --- lib/elixir/lib/kernel/typespec.ex | 17 ++++++++++++++--- lib/elixir/test/elixir/typespec_test.exs | 20 +++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index 1f3539bcf93..f37a5c30590 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -255,9 +255,20 @@ defmodule Kernel.Typespec do case type_to_signature(expr) do {name, arity} = type_pair -> - if built_in_type?(name, arity) do - message = "type #{name}/#{arity} is a built-in type and it cannot be redefined" - compile_error(env, message) + cond do + # This is a built-in type since OTP 29 but it just generates a warning for now + {name, arity} == {:record, 0} -> + IO.warn("type #{name}/#{arity} is overriding a built-in type", + file: file, + line: line + ) + + built_in_type?(name, arity) -> + message = "type #{name}/#{arity} is a built-in type and it cannot be redefined" + compile_error(env, message) + + true -> + :ok end if Map.has_key?(type_pairs, type_pair) do diff --git a/lib/elixir/test/elixir/typespec_test.exs b/lib/elixir/test/elixir/typespec_test.exs index ab24ce5e115..2643c1d4392 100644 --- a/lib/elixir/test/elixir/typespec_test.exs +++ b/lib/elixir/test/elixir/typespec_test.exs @@ -681,15 +681,17 @@ defmodule TypespecTest do end end - test "@type can be named record" do - bytecode = - test_module do - @type record :: binary - @spec foo?(record) :: boolean - def foo?(_), do: true - end - - assert [type: {:record, {:type, _, :binary, []}, []}] = types(bytecode) + test "@type named record/0 warns" do + assert ExUnit.CaptureIO.capture_io(:stderr, fn -> + bytecode = + test_module do + @type record :: binary + @spec foo?(record) :: boolean + def foo?(_), do: true + end + + assert [type: {:record, {:type, _, :binary, []}, []}] = types(bytecode) + end) =~ "type record/0 is overriding a built-in type" end test "@type with an invalid map notation" do