Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot declare macro for all Classs #4732

Open
bew opened this issue Jul 21, 2017 · 5 comments
Open

Cannot declare macro for all Classs #4732

bew opened this issue Jul 21, 2017 · 5 comments

Comments

@bew
Copy link
Contributor

bew commented Jul 21, 2017

class Class
  macro methods
    {{ @type.methods.map &.name.stringify }}
  end
end

pp String.methods

This works in 0.23.0 (https://carc.in/#/r/2ecc) but fails in 0.23.1 (https://carc.in/#/r/2ec8).

This has been introduced by 05a51a1 (from #4649). I don't why/how the changes broke that behavior.

@mverzilli mverzilli added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:macros labels Jul 21, 2017
@straight-shoota
Copy link
Member

This seems to apply only to special ancestor types like Class, not for general inhertance:

class Foo
  macro methods
    "hello"
  end
end

class Bar < Foo; end
class Baz < Bar; end

pp Bar.methods
pp Baz.methods

https://carc.in/#/r/2eou

/cc #4639

@bew
Copy link
Contributor Author

bew commented Sep 2, 2017

I think it's not a bug after all, defining a macro on Class makes no sense, I needed to define on Object:

class Object
  macro methods
    {{ @type.methods.map &.name.stringify }}
  end
end

puts Bool.methods

https://carc.in/#/r/2nh7

As macros needs to be called using the Type as receiver, it's not that strange to put it in Object so that all types can have it.

WDYT?

@straight-shoota
Copy link
Member

It doesn't make sense to have this method on any object instance.

@bew
Copy link
Contributor Author

bew commented Sep 6, 2017

@straight-shoota it's not a method, it's a macro

I'm just trying to have a macro on alll classes, so I can do Bool.my_macro or String.my_macro.

@asterite
Copy link
Member

Macros lookup go through the instance-type hierarchy, so it looks for macros in String, then in Object. This is because there's no way right now to distinguish instance macros and class macros. But instance macros don't make a lot of sense because you can't invoke macros from an instance. This needs more thought to be solved.

@asterite asterite added status:discussion and removed kind:bug A bug in the code. Does not apply to documentation, specs, etc. labels Sep 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants