goby-lang / goby

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

Assignment surrounded by parenthesis, inside a method, crashes the interpreter #624

Closed 64kramsystem closed 6 years ago

64kramsystem commented 6 years ago

An expression of the form:

def test
  (@instance = 1)
end

crashes the interpreter.

If the parenthesis are removed, or the code is expressed in a single line, the interpreter won't crash.

This is the crash message/stack:

panic: interface conversion: ast.Expression is *ast.InstanceVariable, not *ast.Identifier

goroutine 1 [running]:
github.com/goby-lang/goby/compiler/bytecode.(*Generator).compileDefStmt(0xc4201d2d80, 0xc4201d6910, 0xc4201d9bc0, 0xc420177878)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/statement_generation.go:203 +0x12fe
github.com/goby-lang/goby/compiler/bytecode.(*Generator).compileStatement(0xc4201d2d80, 0xc4201d6910, 0x1091d80, 0xc4201d9bc0, 0xc420177878, 0xc4201bfb00)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/statement_generation.go:47 +0x50f
github.com/goby-lang/goby/compiler/bytecode.(*Generator).compileCodeBlock(0xc4201d2d80, 0xc4201d6910, 0xc4201bf9c0, 0xc420177878, 0xc4201bfb00)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/generator.go:73 +0x7e
github.com/goby-lang/goby/compiler/bytecode.(*Generator).compileClassStmt(0xc4201d2d80, 0xc4201d67d0, 0xc4201d9b80, 0xc4201d2e10, 0xc4201bf640)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/statement_generation.go:149 +0x42e
github.com/goby-lang/goby/compiler/bytecode.(*Generator).compileStatement(0xc4201d2d80, 0xc4201d67d0, 0x1091cc0, 0xc4201d9b80, 0xc4201d2e10, 0xc4201bf640)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/statement_generation.go:49 +0x10b
github.com/goby-lang/goby/compiler/bytecode.(*Generator).compileStatements(0xc4201d2d80, 0xc4201c7ce0, 0x1, 0x1, 0xc4201d2e10, 0xc4201bf640)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/statement_generation.go:22 +0xd0
github.com/goby-lang/goby/compiler/bytecode.(*Generator).GenerateInstructions(0xc4201d2d80, 0xc4201c7ce0, 0x1, 0x1, 0x3, 0xc4201d0da0, 0xf)
  /path/to/workspace/go/src/github.com/goby-lang/goby/compiler/bytecode/generator.go:54 +0x5b
github.com/goby-lang/goby/igb.StartIgb(0xbd4e34, 0x7)
  /path/to/workspace/go/src/github.com/goby-lang/goby/igb/repl.go:224 +0xcd8
main.main()
  /path/to/workspace/go/src/github.com/goby-lang/goby/goby.go:29 +0x954
st0012 commented 6 years ago

@saveriomiroddi thanks for report, I'll looking into it

st0012 commented 6 years ago

@shes50103 here's another case that'll crash the parser

shes50103 commented 6 years ago

got it I will fix it