Missing inherited static methods #134

Closed
abscondment opened this Issue Aug 31, 2011 · 4 comments

3 participants

@abscondment

Example

Some simple class inheritance, saved as Test.mirah:

class Parent
  def self.my_method
    'ran my method'
  end
end

class Child < Parent
end

puts Parent.my_method
puts Child.my_method

Expected

It should compile and function as the equivalent Java would, with Child.my_method() running the Parent method.

Actual

Compilation of this file will fail during inference by complaining about the last line.

brendan@flask:~/code/mirahtest$ mirahc Test.mirah 
Parsing...
   Test.mirah
Inferring types...
Inference Error:
Cannot find static method my_method() on Child
Test.mirah:11: Cannot find static method my_method() on Child
puts Child.my_method
    ^^^^^^^^^^^^^^^^

This is observed with 0.0.8/master.

@consiliens

Thanks for reporting this!

The issue also occurs with the alternative static method syntax.

class Parent
  class << self
    def my_method
      'ran my method'
    end
  end
end

class Child < Parent
end

puts Parent.my_method
puts Child.my_method
@ribrdb

This is somewhat intentional. Static methods belong to a class, they are not inherited. Child.my_method() is allowed in Java, but this is confusing since it's really calling Parent.my_method() and I think this generates a warning in Java.

@abscondment

It doesn't generate a warning in Java, as far as I can tell. I'm sort of indifferent about whether Mirah winds up supporting this, but it's definitely a little 'gotcha' if you're expecting the Java behavior.

@consiliens

I also expected the Java behavior. There's no warning generated in Java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment