Skip to content

Conversation

@ianko
Copy link
Contributor

@ianko ianko commented Oct 17, 2025

Description

This PR fixes warnings that appear when running on Elixir 1.17+ and 1.19+, addressing both deprecated syntax and new type system checks.

Issues Fixed

1. Elixir 1.17+ Charlist Deprecation Warnings

In Elixir v1.17, single-quoted charlists were hard deprecated. The warning states:

"using single-quoted strings to represent charlists is deprecated. Use ~c"" if you indeed want a charlist or use "" instead."

Changes:

  • Updated test/xpeg_test.exs and test/examples_test.exs to use ~c sigil
  • Replaced patterns like 'a'~c"a" and {'a'..'z'}{~c"a"..~c"z"}

2. Elixir 1.19 Type System Warnings (Arity Mismatch)

Elixir v1.19 introduced enhanced type inference for anonymous functions, which detected an arity mismatch in the code generator:

     warning: expected a 2-arity function on call:

         func.(captures, ctx)

     but got function with arity 1:

         (non_empty_list(term(), term()) -> dynamic(non_empty_list(term(), term())))

     where "func" (context Xpeg.Codegen) was given the type:

         # type: (non_empty_list(term(), term()) -> dynamic(non_empty_list(term(), term())))
         # from: deps/xpeg/lib/codegen.ex:181
         func = fn [date, op | cs] -> [[date, op] | cs] end

     typing violation found at:
185true -> func.(captures, ctx)~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     │
     └─ deps/xpeg/lib/codegen.ex:185: :"{:__aliases__, [counter: {Policy.Engine.PolicyParser, 2}, line: 21, column: 16], [:Policy]}-#Reference<0.4023179176.3650617345.76900>".parse/8

Root Cause:
The code was conditionally calling functions with different arities at runtime based on the userdata option, but generating the same call site.

Solution:
Split code generation into separate branches at compile-time (commit bab109d). Now the compiler generates the correct function call for each case:

  • With userdata: true → generates func.(captures, ctx) (2-arity)
  • Without userdata → generates func.(captures) (1-arity)

This eliminates the runtime conditional and allows the type system to correctly verify each path.

Testing

  • ✅ All 24 tests pass
  • ✅ Zero compilation warnings on Elixir 1.19
  • ✅ Type system correctly verifies function arities
  • ✅ Functionality preserved - all existing behavior maintained

@ianko ianko marked this pull request as draft October 17, 2025 22:31
@ianko ianko marked this pull request as ready for review October 17, 2025 22:48
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.

1 participant