Skip to content

Fix Elixir 1.20 compile warnings#1865

Merged
Flo0807 merged 11 commits intonaymspace:developfrom
mitchellhenke:elixir-1-20-compile-warnings
Mar 27, 2026
Merged

Fix Elixir 1.20 compile warnings#1865
Flo0807 merged 11 commits intonaymspace:developfrom
mitchellhenke:elixir-1-20-compile-warnings

Conversation

@mitchellhenke
Copy link
Contributor

@mitchellhenke mitchellhenke commented Mar 11, 2026

Apologies in advance as the diff is larger than I'd hoped, though it is mostly one core issue. There are a handful of redundant requires/use statements that I've removed. The bulk of the changes are because when compiling an app that uses Backpex and Elixir 1.20, a number of compile warnings will be returned:

    warning: the following clause is redundant:

        def confirm_label(assigns)

    it has type:

        term()

    previous clauses have already matched on the following types:

        term()

    │
  1 │ defmodule Backpex.ItemActions.Delete do
    │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ (backpex 0.17.4) lib/backpex/item_actions/delete.ex:1: Backpex.ItemActions.Delete.confirm_label/1

     warning: this clause for render_resource_slot/3 cannot match because a previous clause at line 97 always matches
     │
 102 │   def render_resource_slot(assigns, :new, :main) do
     │       ~
     │
     └─ lib/app_web/admin/live_resources/user_live.ex:102:7

     warning: this clause for render_resource_slot/3 cannot match because a previous clause at line 97 always matches
     │
 117 │   def render_resource_slot(assigns, action, position) do
     │       ~
     │
     └─ lib/app_web/admin/live_resources/user_live.ex:117:7

It seems to mostly be due to Backpex defining the methods in before_compile, which results in the dependent module potentially defining conflicting functions and the warning. This applies to Backpex.Field, Backpex.ItemAction, and Backpex.LiveResource. To try to address it, I've moved the default function definitions out of __before_compile__ and into __using__ with corresponding defoverridable additions so the methods can be overridden. There is a wrinkle to this for functions that need to fall back to the default. They would need to add a fallback function definition that calls super(). Ex:

  @impl Backpex.LiveResource
  def render_resource_slot(assigns, :index, :actions) do
    ~H"""
    <div :if={can_sync?(@current_scope)}>
      <button class="btn btn-sm btn-secondary" phx-click="sync">
        Sync
      </button>
    </div>
    """
  end

  def render_resource_slot(assigns, action, position) do
    super(assigns, action, position)
  end

I'm not sure if this would be the preferred approach, but am happy to make changes to accommodate the best path here.

The tests also fail under Elixir 1.20 due to the test macros always evaluating conditionals as true or false, so I've tried to address that as well:

Example Warning
    type warning found at:
    │
 12 │       test_delete_from_index(
    │       ~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ test/demo_web/live/address/delete_item_action_live_test.exs:12: DemoWeb.Live.Address.DeleteItemActionLiveTest."test delete item action on index view deletes item successfully"/1

    warning: the following conditional expression:

        success_message

    will always evaluate to:

        binary()

    where "success_message" (context Demo.Support.LiveResourceTests) was given the type:

        # type: binary()
        # from: test/demo_web/live/address/delete_item_action_live_test.exs:27
        success_message = "Address has been deleted successfully."

The finch commit is mostly unrelated, but addresses an issue with diverged dependencies in the demo app:

Example Warning
Dependencies have diverged:
* finch (Hex package)
  the dependency finch 0.20.0

  > In deps/req/mix.exs:
    {:finch, "~> 0.17", [env: :prod, hex: "finch", repo: "hexpm", optional: false]}

  does not match the requirement specified

  > In deps/sentry/mix.exs:
    {:finch, "~> 0.21", [env: :prod, hex: "finch", repo: "hexpm", optional: true]}

  Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies

Thanks again!

@mitchellhenke mitchellhenke changed the title Elixir 1.20 compile warnings Fix Elixir 1.20 compile warnings Mar 11, 2026
@mitchellhenke mitchellhenke force-pushed the elixir-1-20-compile-warnings branch 3 times, most recently from d8ca20b to 63f9583 Compare March 11, 2026 14:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets Elixir 1.20 compile-time warnings in Backpex consumers by changing how Backpex injects default callback implementations, and by cleaning up a few redundant module directives. It also updates the demo app to address Elixir 1.20 test-macro type warnings and a Finch dependency divergence.

Changes:

  • Move several default callback implementations from __before_compile__ into __using__, and mark them defoverridable (Backpex.LiveResource / Backpex.Field / Backpex.ItemAction).
  • Remove redundant require / use statements that are no longer needed.
  • Update demo LiveResources/tests to work cleanly under Elixir 1.20 and add a direct Finch dependency to address dependency divergence.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/backpex_web.ex Removes redundant use Phoenix.Component from the :field helper.
lib/backpex/live_resource/show.ex Removes unused require Backpex.
lib/backpex/live_resource.ex Moves default LiveResource callback implementations into __using__ and adds defoverridable to support overrides without redundant-clause warnings.
lib/backpex/item_actions/item_action.ex Moves default ItemAction callback implementations into __using__ and adds defoverridable; keeps __before_compile__ for validation.
lib/backpex/html/core_components.ex Removes unused require Backpex.
lib/backpex/field.ex Moves default Field callback implementations into __using__ and adds defoverridable; leaves render injection in __before_compile__.
demo/test/support/live_resource_tests.ex Reworks success-message branching in test macros to avoid Elixir 1.20 type warnings.
demo/mix.exs Adds a direct Finch dependency intended to address diverged dependency requirements.
demo/lib/demo_web/live/user_live.ex Adds a translate/1 fallback clause delegating to super/1 to preserve defaults while customizing translations.
demo/lib/demo_web/live/short_link_live.ex Adds a return_to/5 fallback clause delegating to super/5 to preserve defaults alongside a specific override.
demo/lib/demo_web/live/film_review_live.ex Adds a render_resource_slot/3 fallback clause delegating to super/3 to preserve defaults alongside a specific slot override.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Flo0807 Flo0807 added the enhancement Changes that are not breaking label Mar 27, 2026
@Flo0807 Flo0807 added this pull request to the merge queue Mar 27, 2026
Merged via the queue into naymspace:develop with commit 9a98fb2 Mar 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Changes that are not breaking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants