Using alias inside resource code blocks triggers warning in new versions

So, normally I like to restrict my alias scopes as little as possible, so instead of adding an alias in the top of a file, I prefer to do it inside a code block.

On older versions of Ash, adding the following code:

  policies do
    alias Marketplace.Markets.Checks, as: MarketsChecks

    policy action([:place_offer]) do
      forbid_if MarketsChecks.NotConfirmedYet
      forbid_unless MarketsChecks.IsInvestor
      authorize_if always()
    end
  end

Will work fine, but using the latest version, now it gives me the following warning during compilation:

warning: unused alias MarketsChecks
  lib/marketplace/markets/offer.ex:80

Note that even with the warning, the policy above still works fine.

Is it a easy fix to make this warning go away? I do the same in other code blocks (relationships, calculations, attributes, etc) and they all work fine, I’m only seeing this on the policies block

:thinking: that is very strange. I was pretty sure we had fixed this issue ages ago. Does it work if you put the alias at the top of the file?

No, got the same warning putting it at the top

Let’s double check your spark version. Do mix deps.update spark and see if that helps :slight_smile:

I’m already in the latest version (1.1.48)

Hmm…oh, could you perhaps try and remove the as option to the alias and see if the warning goes away?

Removing the as option fixed it. But, if possible, I would like to keep it since I added that because it conflicts with another alias that has the same name Checks

Yeah, that makes sense. We made a special thing to avoid these issues, and I suspect it isn’t properly handling as aliases :frowning:. Can you open an issue in spark? In the meantime, you can use the alias you want but add , warn: false option.

Was that a recent change? Because, weirdly enough, not so old version worked just fine :thinking:

I will create a ticket in spark ASAP

I don’t think it was a recent change but its possible…

1 Like