-
-
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
Give proper error when trying to instantiate Module #6735
Conversation
I'm not sure this is a good change. module Foo
def self.allocate
end
end
Foo.allocate` Failing to call a method I'd leave the error message as is and maybe add a note about being unable to instantiate a module. |
Perhaps we rather should make sure the call to |
@r00ster91 Can you change this to add a note to the original error instead? @jhass's suggestion can come later. |
Specs need updating |
@@ -100,6 +100,10 @@ class Crystal::Call | |||
end | |||
end | |||
|
|||
if def_name == "allocate" && owner.is_a?(ModuleType) && owner.is_a?(MetaclassType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition should check if onwer is a MetaclassType and owner.instance_type.module?
The current check reads well but makes no sense because a MetaclassType inherits from ModuleType. It just happens to work because the only metaclasses that don't have an allocate are modules, though I think this check will also trigger for enums
Fixes #3885
Now this:
gives:
instead of: