goby-lang / goby

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

Bug: `break` is unstable in REPL #629

Closed hachi8833 closed 6 years ago

hachi8833 commented 6 years ago
def foo(tail)
  (5..tail).each do |t|
    if t % 2 == 0 && t % 5 == 0
      puts "ouch!"
      break
    else
      puts t
    end
  end
  puts "out of the block"
end

The code above works fine in normal run within a file, trailing foo 20 several times.

When you first run foo 20 on REPL, it works, too. But if you run foo 20 again on REPL, you receive the following panic.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x43cdad5]

goroutine 1 [running]:
github.com/goby-lang/goby/vm.(*VM).REPLExec(0xc420180000, 0xc420240fc0, 0x6, 0x8)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/repl.go:38 +0x435
github.com/goby-lang/goby/igb.StartIgb(0x4560268, 0x7)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/igb/repl.go:225 +0xbff
main.main()
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/goby.go:29 +0x8fc

Note that this is the same on REPL even when you wrap foo in a class:

class Foo
  def foo(tail)
    (5..tail).each do |t|
      if t % 2 == 0 && t % 5 == 0
        puts "ouch!"
        break
        else
        puts t
      end
    end
    puts "out of the block"
  end
end

Foo.new.foo 20
st0012 commented 6 years ago

@hachi8833 doesn't this relate/be identical with #584?

hachi8833 commented 6 years ago

You're right. I should be closing this...