goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

`include()` does not work well only in REPL #294

Closed hachi8833 closed 7 years ago

hachi8833 commented 7 years ago

The following works well in Ruby(run from file & REPL) and Goby(run from file).

class Baz
  module Foo
    def ten
      10
    end
  end

  module Bar
    def five
      5
    end
  end

  include(Bar)
  include(Foo)

  def eight
    five * ten
  end
end

a = Baz.new
puts(a.eight) # => 50

In Goby REPL, the following error occurs after returning 50.

» puts(a.eight) # => 50
UndefinedMethodError: Undefined Method 'five' for <Instance of: Baz>
UndefinedMethodError: Undefined Method 'five' for <Instance of: Baz>
#=> ERROR: UndefinedMethodError: Undefined Method 'five' for <Instance of: Baz>

Looks like include does not work well only in REPL.

hachi8833 commented 7 years ago

FYI: this works in all cases:

module Foo
  def ten
    10
  end
end

module Bar
  def twenty
    20
  end
end

class Baz
  include(Bar)
  include(Foo)
end

a = Baz.new
puts(a.ten)    #=> 10
puts(a.twenty) #=> 20
st0012 commented 7 years ago

@hachi8833 This seems to be fixed on current master branch, can you confirm it?

hachi8833 commented 7 years ago

Confirmed the issue has been fixed on current master. Closing issue...