sasa1977 / boundary

Manage and restrain cross-module dependencies in Elixir projects
MIT License
825 stars 22 forks source link

Phoenix.Param.Any not implicitly imported as dependency #39

Closed pzingg closed 2 years ago

pzingg commented 2 years ago

When using the @derive {Phoenix.Param, :param_key} macro to implement the Phoenix.Param protocol for an Ecto.Schema module inside a top-level MySystemSchemas boundary module, I get this boundary compile-time warning:

Error: (references from MySystemSchemas to Phoenix.Param.Any are not allowed)

Here's the boundary definition in the MySystemSchemas top-level module. I could not add Phoenix.Param.Any to the list of deps.

use Boundary, deps: [Ecto, Phoenix.Param], exports: [...]

The workaround is to actually write out the defimpl Phoenix.Param instead of using the @derive macro. But I'm hoping there's a solution that would let me use the macro.

sasa1977 commented 2 years ago

Could you please provide a minimal working example? I just tried the following locally:

defmodule MySystem do
  use Boundary,
    deps: [Phoenix.Param],
    type: :strict
end

defmodule MySystem.MySchema do
  @derive {Phoenix.Param, :param_key}
end

And this works as expected: the code above emits no warnings (unless the dep to param is removed).

pzingg commented 2 years ago

If I use type: :strict it only gets worse.

Here's the example: https://github.com/pzingg/boundary_mwp

Boundary 0.8 Phoenix 1.6 Elixir 1.12

sasa1977 commented 2 years ago

Thanks! This was a bug in boundary. I've pushed a fix to the branch fix-dep-to-protocol-impl. Could you please give it a try?

pzingg commented 2 years ago

That branch works fine now in my original project, with or without type: :strict.

sasa1977 commented 2 years ago

This is now pushed to hex in version 0.9.0