[ivar assignment in class body] Issue 73: Mirah::InternalCompilerError: undefined method `aload' for nil:NilClass #122

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

Comments

Projects
None yet
2 participants
Contributor

consiliens commented Aug 26, 2011

"
Reported by rogerpack2005, May 31, 2011

class A

  @a = 3
end

maybe this meant "to declare class variables you must use @@ style" ?
"

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

Owner

baroquebobcat commented Nov 20, 2011

Reproduced.

$ bundle exec mirah -V -e 'class A

  @a = 3
end'

...

[Script
 body:
  Body
   ClassDefinition(A)
    body:
     Body
      FieldAssignment(a)
       value:
        Fixnum(3)]
DashE:3: undefined method `aload' for nil:NilClass
NoMethodError: undefined method `aload' for nil:NilClass
  field_assign at ~/mirah/lib/mirah/jvm/compiler/jvm_bytecode.rb:607
       compile at ~/mirah/lib/mirah/compiler/class.rb:49
       compile at ~/mirah/lib/mirah/jvm/compiler/base.rb:38
          body at ~/mirah/lib/mirah/jvm/compiler/jvm_bytecode.rb:446
          body at ~/mirah/lib/mirah/jvm/compiler/base.rb:212
          body at ~/mirah/lib/mirah/jvm/compiler/jvm_bytecode.rb:445
       compile at ~/mirah/lib/mirah/compiler/structure.rb:21
  define_class at ~/mirah/lib/mirah/jvm/compiler/base.rb:180
          with at ~/mirah/lib/mirah/jvm/compiler/base.rb:260
  define_class at ~/mirah/lib/mirah/jvm/compiler/base.rb:176
       compile at ~/mirah/lib/mirah/compiler/class.rb:20
       compile at ~/mirah/lib/mirah/jvm/compiler/base.rb:38
          body at ~/mirah/lib/mirah/jvm/compiler/jvm_bytecode.rb:446
          body at ~/mirah/lib/mirah/jvm/compiler/base.rb:212
          body at ~/mirah/lib/mirah/jvm/compiler/jvm_bytecode.rb:445
       compile at ~/mirah/lib/mirah/compiler/structure.rb:21
   define_main at ~/mirah/lib/mirah/jvm/compiler/base.rb:94
       compile at ~/mirah/lib/mirah/compiler/structure.rb:50
   compile_ast at ~/mirah/lib/mirah/compiler.rb:49
  compile_asts at ~/mirah/lib/mirah/compiler.rb:40
          each at org/jruby/RubyArray.java:1612
  compile_asts at ~/mirah/lib/mirah/compiler.rb:38
      generate at ~/mirah/lib/mirah/generator.rb:38
       execute at ~/mirah/lib/mirah/commands/run.rb:30
  execute_base at ~/mirah/lib/mirah/commands/base.rb:41
         catch at org/jruby/RubyKernel.java:1192
  execute_base at ~/mirah/lib/mirah/commands/base.rb:38
       execute at ~/mirah/lib/mirah/commands/run.rb:23
           run at ~/mirah/lib/mirah.rb:36
        (root) at ~/mirah/bin/mirah:27

The error is raised here: https://github.com/mirah/mirah/blob/3b06353a44cc1f090a4f5287065ef8227855c067/lib/mirah/jvm/compiler/jvm_bytecode.rb#L607

        def field_assign(name, type, expression, value, annotations, static_field)
          # ...
          method.aload 0 unless static || static_field

I'm guessing that method.aload is loading an instance reference.

incidentally, @@a = 1 doesn't work either but for a different reason:

[Script
 body:
  Body
   ClassDefinition(A)
    body:
     Body
      FieldAssignment(a)
       value:
        Fixnum(3)]
Compiling...
  DashE
DashE:3: undefined method `push_int' for nil:NilClass

@ribrdb ribrdb added a commit that referenced this issue May 25, 2013

@ribrdb ribrdb Fix field initialization in the new backend.
Fixes #76 and #122
7962d91
Owner

baroquebobcat commented Aug 4, 2013

The new backend has a fix for this--it moves field assigns into the constructor.

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