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

Hash creation via {} can't use methods for values #146

Closed
abscondment opened this Issue Sep 8, 2011 · 1 comment

Comments

Projects
None yet
2 participants
@abscondment
Contributor

abscondment commented Sep 8, 2011

Example:

class Test
  def initialize
    bar = 'bar'
    h = {
      'foo' => 'foo',     # fine
      'bar' => bar,       # fine
      'baz' => baz_method # ouch
    }
    puts "#{h}"
  end

  def baz_method
    'baz'
  end
end
Test.new

Expected:

The hash should be created with 'baz' => 'baz'.

Actual:

  • mirahc compiles just fine, but java dies:

    brendan@flask:~/code/mirah$ java Test
    Exception in thread "main" java.lang.VerifyError: (class: Test, method: <init> signature: ()V) Accessing value from uninitialized register 4
    
  • mirahc -j produces java source (gist), but javac dies:

    brendan@flask:~/code/mirah$ javac Test.java 
    Test.java:19: cannot find symbol
    symbol  : variable self$2000
    location: class Test
      map$2000.put("baz", self$2000.baz_method());
                          ^
    Note: Test.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    
Bonus
brendan@flask:~/code/readabl/paperkarma/android/PaperKarma$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)

@ghost ghost assigned baroquebobcat Sep 25, 2011

@baroquebobcat

This comment has been minimized.

Show comment
Hide comment
@baroquebobcat

baroquebobcat Sep 25, 2011

Member

looks like it's a self problem. the generated code is calling the method on the wrong (read: non-existent) variable. Note that this doesn't happen with static methods.

Member

baroquebobcat commented Sep 25, 2011

looks like it's a self problem. the generated code is calling the method on the wrong (read: non-existent) variable. Note that this doesn't happen with static methods.

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