Skip to content

Invalid infix causes panic #100

@kaidesu

Description

@kaidesu

When running the following:

1 + * 2

A panic is thrown by the evaluator:

Ghost (1.0-beta.1)
Press Ctrl + C to exit

>> 1 + * 2
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x42db55b]

goroutine 1 [running]:
ghostlang.org/x/ghost/evaluator.evaluateInfix(0xc000154120, 0xc0001406a0)
	/Users/kai/Code/Ghost/ghost/src/evaluator/infix.go:24 +0x1bb
ghostlang.org/x/ghost/evaluator.Evaluate({0x430d1a0, 0xc000154120}, 0x43e80f0)
	/Users/kai/Code/Ghost/ghost/src/evaluator/evaluator.go:54 +0x617
ghostlang.org/x/ghost/evaluator.Evaluate({0x430cf20, 0xc000140620}, 0xc00016a480)
	/Users/kai/Code/Ghost/ghost/src/evaluator/evaluator.go:36 +0x4c9
ghostlang.org/x/ghost/evaluator.evaluateProgram(0x4318480, 0x43e80f0)
	/Users/kai/Code/Ghost/ghost/src/evaluator/program.go:12 +0x77
ghostlang.org/x/ghost/evaluator.Evaluate({0x430d360, 0xc0001205e8}, 0x40cfec5)
	/Users/kai/Code/Ghost/ghost/src/evaluator/evaluator.go:18 +0xc8
ghostlang.org/x/ghost/ghost.(*Ghost).Execute(0xc00013dd90)
	/Users/kai/Code/Ghost/ghost/src/ghost/ghost.go:76 +0x18a
ghostlang.org/x/ghost/repl.evaluate(0xc00013dd90, {0xc00012c370, 0x7})
	/Users/kai/Code/Ghost/ghost/src/repl/repl.go:59 +0xb9
ghostlang.org/x/ghost/repl.Start({0x43ebd60, 0xc000128008}, {0x437eabd, 0x18})
	/Users/kai/Code/Ghost/ghost/src/repl/repl.go:45 +0x2e6
main.main()
	/Users/kai/Code/Ghost/ghost/src/cmd/ghost.go:64 +0x677
exit status 2
make: *** [run] Error 1

This seems to be because in the main evaluator loop, we're expecting it to pick up on any ast node that comes through. In the event that we don't find a match, the closing statement is simply returning nil. We should instead throw a runtime error so it can be properly caught and reported back to the end user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions