Skip to content

Conversation

whatyouhide
Copy link
Member

This is a WIP PR that I'd really like to collect feedback on; it's a possible partial fix for #4830 as it fixes super() and defoverridable for public macros but not private macros.

Is this a good way to approach this? :)

@@ -32,6 +32,13 @@ name(_Module, {Name, _} = Function, Overridable) ->
{Count, _, _, _} = maps:get(Function, Overridable),
elixir_utils:atom_concat([Name, " (overridable ", Count, ")"]).

%% Returns the kind (def, defp, and so on) of the given overridable function.

kind(Module, FunctionOrMacro) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can rename the name function to kind_and_name and return both kind and name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to return the FinalArgs as well (cause we want to add the '_@CALLER' arg), this is why I didn't go with kind_and_name (which is what I wanted to go with for the record 😄). Wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could still calculate the args later on. The benefit of kind_and_name is just to avoid doing multiple lookups both in this module and in the translator. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I see what you mean now. Updated, let me know how it looks :)

@josevalim
Copy link
Member

It looks great to me, just one tiny comment left.

@@ -1,6 +1,6 @@
% Holds the logic responsible for defining overridable functions and handling super.
-module(elixir_def_overridable).
-export([setup/1, overridable/1, overridable/2, name/2, super/2, store_pending/1,
-export([setup/1, overridable/1, overridable/2, name/2, kind_and_name/2, super/2, store_pending/1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to export name/2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't, good catch! We don't need name/2 at all, I just removed it. We could go even further and make name/3 take a Count instead of the whole Overridable map because we always have that count available, but I think for now it's fine like this, name/2 is nice and scoped like this. Wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whatyouhide
Copy link
Member Author

@josevalim aaaand done! 👍

@josevalim
Copy link
Member

Ship it.

@whatyouhide whatyouhide changed the title [WIP] Support macros with defoverridable/super Support (exported) macros with defoverridable/super Jun 22, 2016
@whatyouhide whatyouhide merged commit 881c2d6 into elixir-lang:master Jun 22, 2016
@whatyouhide whatyouhide deleted the super-macro branch June 22, 2016 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants