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

Macros: undefined method `block' for nil:NilClass #185

Closed
jstepien opened this Issue Apr 25, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@jstepien
Contributor

jstepien commented Apr 25, 2012

$ cat Macros.mirah 
class Macros
  def initialize
    @foo = "It works."
  end

  macro def attr_reader(name_node)
    name = name_node.string_value
    quote {
      def `name`
        @`name`
      end
    }
  end

  attr_reader :foo
end

mirahc Macros.mirah with Mirah 0.0.11 and JRuby 1.6.7 works fine, however translating to Java causes a following error.

$ mirahc --java Macros.mirah 
Parsing...
  Macros.mirah
Inferring types...
Compiling...
  Macros.mirah
Macros.mirah:15: undefined method `block' for nil:NilClass
  attr_reader :foo
^^^^^^^^^^^^^^^^^^
Mirah::InternalCompilerError: undefined method `block' for nil:NilClass
             compile at mirah-0.0.11-java/lib/mirah/compiler/structure.rb:32
                send at org/jruby/RubyKernel.java:2084
  <Class:0x1de40494> at file:jruby-complete-1.6.7.jar!/META-INF/jruby.home/lib/ruby/1.8/delegate.rb:292
         maybe_store at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:351
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:357
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/base.rb:212
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:356
             compile at mirah-0.0.11-java/lib/mirah/compiler/structure.rb:21
         maybe_store at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:351
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:357
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/base.rb:212
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:356
             compile at mirah-0.0.11-java/lib/mirah/compiler/structure.rb:21
        define_class at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:65
                with at mirah-0.0.11-java/lib/mirah/jvm/compiler/base.rb:260
        define_class at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:61
             compile at mirah-0.0.11-java/lib/mirah/compiler/class.rb:20
         maybe_store at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:351
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:357
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/base.rb:212
                body at mirah-0.0.11-java/lib/mirah/jvm/compiler/java_source.rb:356
             compile at mirah-0.0.11-java/lib/mirah/compiler/structure.rb:21
         define_main at mirah-0.0.11-java/lib/mirah/jvm/compiler/base.rb:94
             compile at mirah-0.0.11-java/lib/mirah/compiler/structure.rb:50
         compile_ast at mirah-0.0.11-java/lib/mirah/compiler.rb:49
        compile_asts at mirah-0.0.11-java/lib/mirah/compiler.rb:40
                each at org/jruby/RubyArray.java:1615
        compile_asts at mirah-0.0.11-java/lib/mirah/compiler.rb:38
            generate at mirah-0.0.11-java/lib/mirah/generator.rb:38
             execute at mirah-0.0.11-java/lib/mirah/commands/compile.rb:26
        execute_base at mirah-0.0.11-java/lib/mirah/commands/base.rb:44
               catch at org/jruby/RubyKernel.java:1183
        execute_base at mirah-0.0.11-java/lib/mirah/commands/base.rb:42
             execute at mirah-0.0.11-java/lib/mirah/commands/compile.rb:23
             compile at mirah-0.0.11-java/lib/mirah.rb:40
              (root) at mirah-0.0.11-java/bin/mirahc:27
                load at org/jruby/RubyKernel.java:1058
              (root) at mirahc:19
@jstepien

This comment has been minimized.

Show comment
Hide comment
@jstepien

jstepien Apr 25, 2012

Contributor

The issue is present on current master, a86c365. Apparently the error is caused by calling @method.block in Mirah::JVM::Compiler::JavaSource#scoped_body with @method being nil.

Contributor

jstepien commented Apr 25, 2012

The issue is present on current master, a86c365. Apparently the error is caused by calling @method.block in Mirah::JVM::Compiler::JavaSource#scoped_body with @method being nil.

@baroquebobcat

This comment has been minimized.

Show comment
Hide comment
@baroquebobcat

baroquebobcat Apr 26, 2012

Member

Thanks for the report, I'll look at it this weekend if someone else doesn't get to it.

Member

baroquebobcat commented Apr 26, 2012

Thanks for the report, I'll look at it this weekend if someone else doesn't get to it.

@baroquebobcat

This comment has been minimized.

Show comment
Hide comment
@baroquebobcat

baroquebobcat Apr 29, 2012

Member

It appears to have something to do w/ how the AST is handled when there isn't an implicit main method. https://github.com/mirah/mirah/blob/master/test/jvm/macros_test.rb#L63 has the same error if you comment out the implicit main.

Member

baroquebobcat commented Apr 29, 2012

It appears to have something to do w/ how the AST is handled when there isn't an implicit main method. https://github.com/mirah/mirah/blob/master/test/jvm/macros_test.rb#L63 has the same error if you comment out the implicit main.

@baroquebobcat

This comment has been minimized.

Show comment
Hide comment
@baroquebobcat

baroquebobcat Apr 29, 2012

Member

Ah, maybe that's because when there's a main method, there's a @method in the generator the whole time.

Member

baroquebobcat commented Apr 29, 2012

Ah, maybe that's because when there's a main method, there's a @method in the generator the whole time.

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