Skip to content

Surface.Formatter.Plugin incompatible with Elixir 1.19.0-rc.0 - Enumerable protocol error for keyword lists #766

@neilberkman

Description

@neilberkman

Describe the bug

The Surface formatter plugin (v0.12.1) is incompatible with Elixir 1.19.0-rc.0. When running mix format on .sface files, the formatter fails with a protocol error, incorrectly treating keyword list expressions in attributes as BitStrings.

Error message

mix format failed for file: lib/enaia_web/surface/forms/landlord_deal/steps/details_form.sface
** (Protocol.UndefinedError) protocol Enumerable not implemented for BitString. 

Got value:
    "[for: for_id]"

    (elixir 1.19.0-rc.0) lib/enum.ex:5: Enumerable.impl_for!/1
    (elixir 1.19.0-rc.0) lib/enum.ex:234: Enumerable.slice/1
    (elixir 1.19.0-rc.0) lib/enum.ex:4713: Enum.slice_count_and_fun/2
    (elixir 1.19.0-rc.0) lib/enum.ex:3031: Enum.slice_range/4
    (surface 0.12.1) lib/surface/formatter/phases/render.ex:451: Surface.Formatter.Phases.Render.format_attribute_expression/2
    (surface 0.12.1) lib/surface/formatter/phases/render.ex:374: Surface.Formatter.Phases.Render.render_attribute/2
    (elixir 1.19.0-rc.0) lib/enum.ex:1688: Enum."-map/2-lists^map/1-1-"/2

How to reproduce

  1. Use Elixir 1.19.0-rc.0
  2. Have Surface 0.12.1 in your project
  3. Create a .sface file with a slot that uses :let with keyword list syntax:
    <:company_name_label :let={for: for_id}>
    
  4. Run mix format

Root cause

The Surface formatter at lib/surface/formatter/phases/render.ex:451 (in format_attribute_expression/2) appears to be receiving keyword list expressions as strings (BitStrings) instead of proper AST structures when running under Elixir 1.19.0-rc.0.

Fix

PR #767 fixes this by using IO.iodata_to_binary and String.slice instead of Enum.slice.

Workaround

Temporarily disable the Surface.Formatter.Plugin in .formatter.exs:

plugins: [
  # Surface.Formatter.Plugin, # Temporarily disabled due to Elixir 1.19.0-rc.0 incompatibility
  Phoenix.LiveView.HTMLFormatter,
  # ... other plugins
]

Environment

  • Surface: v0.12.1
  • Elixir: v1.19.0-rc.0
  • Phoenix LiveView: v1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions