Files
monkey/internal/object/errors.go
csmith fe33fda0ab
Some checks failed
Build / build (push) Successful in 10m45s
Publish Image / publish (push) Failing after 42s
Test / build (push) Successful in 11m9s
misc fixes
2024-04-01 17:44:15 -04:00

35 lines
926 B
Go

package object
import (
"fmt"
)
// BinaryOpError is an binary operation error usually resulting from mismatched types
type BinaryOpError struct {
left, right Object
op string
}
func (e BinaryOpError) Error() string {
return fmt.Sprintf("unsupported types for binary operation: %s %s %s %s %s", e.left.Type(), e.left.Inspect(), e.op, e.right.Type(), e.right.Inspect())
}
// NewBinaryOpError returns a new BinaryOpError
func NewBinaryOpError(left, right Object, op string) BinaryOpError {
return BinaryOpError{left, right, op}
}
// DivisionByZeroError is an error returned when dividing by zero
type DivisionByZeroError struct {
left Object
}
func (e DivisionByZeroError) Error() string {
return fmt.Sprintf("cannot divide %s by zero", e.left)
}
// NewDivisionByZeroError returns a new DivisionByZeroError
func NewDivisionByZeroError(left Object) DivisionByZeroError {
return DivisionByZeroError{left}
}