Skip to content

fix: use map update to avoid struct type warning in add_namespace/3#110

Open
l1x wants to merge 1 commit intokbrw:masterfrom
l1x:fix/struct-update-warning
Open

fix: use map update to avoid struct type warning in add_namespace/3#110
l1x wants to merge 1 commit intokbrw:masterfrom
l1x:fix/struct-update-warning

Conversation

@l1x
Copy link
Copy Markdown

@l1x l1x commented Jan 9, 2026

Elixir 1.19+ type checker warns when using struct update syntax with a dynamic type. Since the function head already pattern matches on %SweetXpath{}, we can safely use map update syntax instead.

Elixir 1.19+ type checker warns when using struct update syntax with a
dynamic type. Since the function head already pattern matches on
%SweetXpath{}, we can safely use map update syntax instead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Shakadak
Copy link
Copy Markdown
Member

Shakadak commented Jan 9, 2026

Hello, the warning was removed before releasing elixir 1.19, they might come back in 1.20 though.
Considering this uncertainty, I would rather hold off removing assertions in the code that could help for tools like dialyzer and language servers when using older versions of Elixir (and we do have a lot of our projects at work in this situation).

@hooch
Copy link
Copy Markdown

hooch commented Mar 22, 2026

Still seeing the above warning in current Elixir 1.19.5

The following fix is required in 1.20.0-rc.3 to resolve for the warning below:

lib/sweet_xml.ex
╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
 934
 935    defp split_last_whitespace(size, bin) do
 936      case bin do
 937 -      <<_::binary-size(size), h>> <> tail when h == ?\s or h == ?\n or h == ?\r or h == ?\t ->
 937 +      <<_::binary-size(^size), h>> <> tail when h == ?\s or h == ?\n or h == ?\r or h == ?\t ->
 938          {head, _} = :erlang.split_binary(bin, size + 1)
 ==> sweet_xml
     Compiling 2 files (.ex)
          warning: the variable "size" is accessed inside size(...) of a bitstring but it was defined outside of the match. You
      must precede it with the pin operator
          │
      937 │       <<_::binary-size(size), h>> <> tail when h == ?\s or h == ?\n or h == ?\r or h == ?\t ->
          │                        ~
          │
          └─ lib/sweet_xml.ex:937:24: SweetXml.split_last_whitespace/2

@hooch hooch mentioned this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants