Skip to content

Commit

Permalink
Also short circuit prefix when there is an error already/so we get a …
Browse files Browse the repository at this point in the history
…single error (#187)
  • Loading branch information
ldemailly authored Aug 28, 2024
1 parent 506048a commit 8d2834a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *State) evalPostfixExpression(node *ast.PostfixExpression) object.Object
}

// Doesn't unwrap return - return bubbles up.
func (s *State) evalInternal(node any) object.Object { //nolint:funlen,gocyclo // quite a lot of cases.
func (s *State) evalInternal(node any) object.Object { //nolint:funlen,gocyclo,gocognit // quite a lot of cases.
switch node := node.(type) {
// Statements
case *ast.Statements:
Expand All @@ -176,6 +176,9 @@ func (s *State) evalInternal(node any) object.Object { //nolint:funlen,gocyclo /
return s.evalPrefixIncrDecr(node.Type(), node.Right)
default:
right := s.evalInternal(node.Right)
if right.Type() == object.ERROR {
return right
}
return s.evalPrefixExpression(node.Type(), right)
}
case *ast.PostfixExpression:
Expand Down
5 changes: 5 additions & 0 deletions main_test.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ grol -quiet -c 'f=()=>{{"k":"v"}}; println(json_go(f))'
!stdout 'json: unsupported type'
stdout '^"\(\)=>{{\\"k\\":\\"v\\"}}"$'

# prefix operator single error (used to be <err: bitwise not of <err: bitwise not of <err: bitwise not of 1.1>>>)
!grol -quiet -c '~~~1.1'
stderr 'Total 1 error'
stderr '^<err: bitwise not of 1.1>$'

-- json_output --
{
"63": 63,
Expand Down

0 comments on commit 8d2834a

Please sign in to comment.