ash-project / spark

Tooling for building DSLs in Elixir
MIT License
105 stars 23 forks source link

Anonymous function works, function capture does not #16

Closed dantswain closed 1 year ago

dantswain commented 1 year ago

In an Ash resource:

actions do
  update :update do
    # this works
    change fn a, b -> change_fn(a, b) end
    # this does not work
    change &change_fn/2
  end
end

...

defp change_fn(a, b) do
  ...
end

The function capture version causes a compile-time error:

== Compilation error in file lib/my_app/ash/some_resource.ex ==
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:fn, [generated: true, generated: true], [{:->, [generated: true, generated: true], [[{:arg1, [counter: {MyApp.Resources.SomeResource, 333}], MyApp.Resources.SomeResource}, {:arg2, [counter: {MyApp.Resources.SomeResource, 334}], MyApp.Resources.SomeResource}], {{:., [generated: true, generated: true], [{:&, [line: 33], [{:/, [line: 33], [{:change_fn, [line: 33], nil}, 2]}]}]}, [generated: true, generated: true], [{:arg1, [counter: {MyApp.Resources.SomeResource, 333}], MyApp.Resources.SomeResource}, {:arg2, [counter: {MyApp.Resources.SomeResource, 334}], MyApp.Resources.SomeResource}]}]}]} of type Tuple
    (elixir 1.14.2) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.14.2) lib/enum.ex:166: Enumerable.reduce/3
    (elixir 1.14.2) lib/enum.ex:4307: Enum.reverse/1
    (ash 2.4.30) /home/dswain/src/elixir_poc/deps/spark/lib/spark/dsl/extension.ex:1544: Ash.Resource.Dsl.Actions.Update.Actions.Changes.Change."MACRO-change"/3
    (ash 2.4.30) expanding macro: Ash.Resource.Dsl.Actions.Update.Actions.Changes.Change.change/1
    lib/my_app/ash/some_resource.ex:33: MyApp.Resources.SomeResource (module)
    (ash 2.4.30) expanding macro: Ash.Resource.Dsl.Actions.Update.update/2
    lib/my_app/ash/some_resource.ex:27: MyApp.Resources.SomeResource (module)

(redacted stacktrace, let me know if anything doesn't make sense - it may have been a search/replace error)

zachdaniel commented 1 year ago

This should be fixed in main.

zachdaniel commented 1 year ago

Thanks for the report!