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

java superclass instance variables badly infered in subclass #151

Closed
moumar opened this Issue Oct 6, 2011 · 3 comments

Comments

Projects
None yet
3 participants
@moumar

moumar commented Oct 6, 2011

Master.java

public class Master {
  public int field;

  public Master() {
    field = 4;
  }
}

slave.mirah

class Slave < Master
  def testField
    field
  end
end

Slave.new.testField

gives:

Inference Error:
Cannot find instance method field() on Slave
slave.mirah:3: Cannot find instance method field() on Slave
field
^^^^^^^^^

@baroquebobcat

This comment has been minimized.

Show comment
Hide comment
@baroquebobcat

baroquebobcat Oct 7, 2011

Member

Two things. Mirah uses Ruby style instance variable syntax, so referring to them looks like this: @field.

Second, currently all instance variables are private. So,

class A
  def initialize
    @a = :a
  end
end

class B < A
  def cool
    puts @a
  end
end

will have an inference error, because Bs don't have access to @a. It'd be nice if instance variables either weren't private by default or at least Mirah would let you access instance variables that would be accessible based on the Java classes permissions.

Currently, if it's your Java code, you can work around this by adding a getter method and using that from the subclass. If it's not your code, Mirah won't work for you right now.

If you want to look into contributing a patch to add this functionality, I'm sure people would be willing to help (myself included).

Member

baroquebobcat commented Oct 7, 2011

Two things. Mirah uses Ruby style instance variable syntax, so referring to them looks like this: @field.

Second, currently all instance variables are private. So,

class A
  def initialize
    @a = :a
  end
end

class B < A
  def cool
    puts @a
  end
end

will have an inference error, because Bs don't have access to @a. It'd be nice if instance variables either weren't private by default or at least Mirah would let you access instance variables that would be accessible based on the Java classes permissions.

Currently, if it's your Java code, you can work around this by adding a getter method and using that from the subclass. If it's not your code, Mirah won't work for you right now.

If you want to look into contributing a patch to add this functionality, I'm sure people would be willing to help (myself included).

@moumar

This comment has been minimized.

Show comment
Hide comment
@moumar

moumar Oct 8, 2011

thanks for your response.

I'll be glad to write a patch to add this functionnality. However i think i will need a starting point ;)

moumar commented Oct 8, 2011

thanks for your response.

I'll be glad to write a patch to add this functionnality. However i think i will need a starting point ;)

@ribrdb

This comment has been minimized.

Show comment
Hide comment
@ribrdb

ribrdb Mar 23, 2012

Contributor

duplicate of #50

Contributor

ribrdb commented Mar 23, 2012

duplicate of #50

@ribrdb ribrdb closed this Mar 23, 2012

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