Issue 64: class level variables are inaccessible somehow #113

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

Projects

None yet

3 participants

@consiliens
Contributor

"
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
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.

@ribrdb
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