-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Can't infer the type of class variable in extend-ed module #4066
Comments
I think |
What do mean? Having |
@asterite removing http://stackoverflow.com/a/42053962/117298 (I mean until I would like to know more why Thank you. |
I think include + extend in Ruby aren't very intuitive. For example: module Moo
def self.moo
end
def moo
end
end
class Foo
include Moo
end
p Foo.new.moo # OK
p Foo.moo # Error I understand why the second line is an error, but when I use I personally never use I think the issue mentioned in stack overflow can still be implemented, I'm not sure it's related to include vs. extend. |
Thank you @asterite for your response, indeed This decision will require solve things like Merging both concepts will definitely reduce that confusion area. Looking forward read the proposal. Cheers. |
module Moo
abstract def self.moo
end
# Nothing prevents me from doing this:
Moo.moo So abstract class methods probably don't make sense. In fact in no statically typed language there's such concept, only abstract instance methods. |
I hear you, valid points and something that needs to be solved since can be done right now: module Interface
module ClassMethods
abstract def call
end
macro included
extend ClassMethods
end
end
class Action
include Interface
# uncomment this for compile to succeed
# def self.call
# end
end
I have a few other cases where |
For reference: This has come up in another question on Stack Overflow: https://stackoverflow.com/questions/45631130/defining-class-vars-in-modules-in-crystal-causes-error |
I had a similar issue, wanted to be able to call a method referencing a A workaround that makes the compiler happy: in the parent module, define a method on
|
Maybe I don't fully understand how class variables work at module level but it seems to me that above code should work, instead it fails with error:
Might be related to #4039?
The text was updated successfully, but these errors were encountered: