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

Issue 64: class level variables are inaccessible somehow #113

Closed
consiliens opened this Issue Aug 26, 2011 · 2 comments

Comments

Projects
None yet
3 participants
@consiliens
Contributor

consiliens commented Aug 26, 2011

"
Reported by rogerpack2005, May 30, 2011

import java.util.ArrayList

class Go < ArrayList
  @@b = 'hi'

  def initialize
    @@b
  end

  def self.go
    puts @@b
  end

end
Go.go # fails
Go.new() # fails

related perhaps to #44

testy.mr:4:in `main': java.lang.IllegalAccessError: tried to access field Go.b from class Testy

apparently it declares it as private so...I'm not sure what should happen here...easy fix would be to make it public :)
"

http://code.google.com/p/mirah/issues/detail?id=64

@baroquebobcat

This comment has been minimized.

Show comment
Hide comment
@baroquebobcat

baroquebobcat Sep 18, 2011

Member

I think that this is related to the discussion around how to initialize "class" variables. The current way to do it looks like this.

  class Go
    def self.initialize : void
      @@b = 'hi'
    end
    def self.go
      puts @@b
    end
  end
  Go.go

There was some discussion on the mailing list about it last year http://groups.google.com/group/mirah/browse_thread/thread/61ca5f5cb41e48fa

What's currently going on here is that the @@b = 1 is considered to be part of the main method of the outer class for some reason, instead of part of a static initializer

So it generates code like

  // Generated from DashE
  public class DashE extends java.lang.Object {
    public static void main(java.lang.String[] argv) {
      this.b = 1;
      Go.go();
    }
  }
  // Generated from DashE
  public class Go extends java.lang.Object {
    private static int b;
    public static java.io.PrintStream go() {
      java.io.PrintStream temp$1 = java.lang.System.out;
      temp$1.println(Go.b);
      return temp$1;
    }
  }

which doesn't work.

Member

baroquebobcat commented Sep 18, 2011

I think that this is related to the discussion around how to initialize "class" variables. The current way to do it looks like this.

  class Go
    def self.initialize : void
      @@b = 'hi'
    end
    def self.go
      puts @@b
    end
  end
  Go.go

There was some discussion on the mailing list about it last year http://groups.google.com/group/mirah/browse_thread/thread/61ca5f5cb41e48fa

What's currently going on here is that the @@b = 1 is considered to be part of the main method of the outer class for some reason, instead of part of a static initializer

So it generates code like

  // Generated from DashE
  public class DashE extends java.lang.Object {
    public static void main(java.lang.String[] argv) {
      this.b = 1;
      Go.go();
    }
  }
  // Generated from DashE
  public class Go extends java.lang.Object {
    private static int b;
    public static java.io.PrintStream go() {
      java.io.PrintStream temp$1 = java.lang.System.out;
      temp$1.println(Go.b);
      return temp$1;
    }
  }

which doesn't work.

@ribrdb

This comment has been minimized.

Show comment
Hide comment
@ribrdb

ribrdb May 23, 2013

Contributor

Duplicate of #76

Contributor

ribrdb commented May 23, 2013

Duplicate of #76

@ribrdb ribrdb closed this May 23, 2013

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