OvermindDL1/protocol_ex

More alias fun

jjl opened this issue · 10 comments

jjl commented
defimplEx ClientSimple, %Simple{}, for: Client do
  alias Bricks.{Connector, Socket}
  def connect(client), do: Connector.connect(client.connector)
  def done(_, socket), do: Socket.close(socket)
  def error(_, socket), do: Socket.close(socket)
end

I get errors to the tune of 'Connector doesn't exist' (and for Socket), so the aliases are being ignored.

On the bright side, I do not get errors about the new short use of %Simple{}, so looks like the last fix worked :)

Woooo more 'fun'!

Heh, thanks for the test-case though, I'm unsure why that would be breaking actually as I should not be touching the inner body setups. Let me make a test-case right quick and test...

Ah wait I know why, I'm lowering all aliases, regardless of scoping, easy fix, sec... ^.^;

jjl commented

Another good one!

  defimplEx TcpConnector, %Bricks.Connector.Tcp{}, for: Connector do
    alias Bricks.Socket.Tcp
    def connect(tcp) do
      case :gen_tcp.connect(tcp.host, tcp.port, tcp.tcp_opts, tcp.op_timeout) do
	{:ok, socket} -> {:ok, Tcp.new(socket)}
	{:error, reason} -> {:error, {:tcp_connect, reason}}
      end
    end
  end

Here, the 'Tcp' inside is actually expanded to the alias from the enclosing scope!

I released 0.3.18 that only processes alias names internally if it exists externally at all, leaving ones that don't exist externally alone, can you give it a try? If that doesn't cover everything that I might just need to start manually injecting external aliases into internal bodies, which definitely becomes more messy and could (though unlikely to) mess with macro's.

Closed in 1378a32. Please re-open if that does not fix it, preferably with a test case to make sure I don't miss anything else. ^.^;

jjl commented

I can't reopen, apparently, but you're gonna love this one :)
From a stacktrace:
lib/connectors/tcp.ex:18: Bricks.Connector.Tcp.Bricks.Connector.Bricks.Connector.Tcp.TcpConnector.connect/1

Fixes neither of the two examples i gave

Fixes neither of the two examples i gave

Lol, I would love complete reproduceable testcases. ;-)

Let me go ahead and just inject the aliases then, that should fix it regardless even though it pollutes the scope (and I doubt any macro's will be screwy enough to break with it anyway). :-)

jjl commented

Well, I tell you what, I'm about ready to release the library as open source, so I can simply point you at it in a minute and you can test about it as you wish until you're satisfied the problems are no longer with protocol_ex ? :)

Can you try 0.3.19 now? It should be fixed in 1f13d7f, I'm just injecting the ENTIRE caller environment now. Like I said some macro's might get unhappy, but honestly if they do they might be wrongly made to begin with. I might want to take out the globalization of the matcher as well so if something new breaks now then please say. ^.^;

OP confirmed it is fixed in IRC. :-)