# Parsing bug with 'return not' (was, Syntax bug)

**URL:** <https://www.ruby-forum.com/t/parsing-bug-with-return-not-was-syntax-bug/110084>\
**Category:** Ruby\
**Created:** [July 22, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/parsing-bug-with-return-not-was-syntax-bug/110084 "2007-07-22T22:31:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Good\_Night\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@Good\_Night\_M](https://www.ruby-forum.com/u/Good_Night_M)\
**Post date:** [July 22, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/parsing-bug-with-return-not-was-syntax-bug/110084/1 "2007-07-22T22:31:29Z")

</div>

On Sun, 22 Jul 2007 03:50:01 -0400, Bil K. wrote:

> > myrect.rb:8: syntax error, unexpected kNOT, expecting kEND  
> > return not ((other.x1 \< self.x0 or self.x1 \< other.x0) and
> 
> You need to use the ‘!’ operator instead of the ‘not’ “conjunction”.  
> It’s a precedence thing – the parser is seeing ‘return not’ – see  
> parse.y in the source.

Thanks, maybe I’ll look. It’s not just precedence though, or else  
‘return’ itself is part of it:

def ok  
return (not true)  
end

def fails  
return not true  
end

And note that within an ‘if’, it works as you’d expect:

def with\_parens\_ok  
if (not true)  
puts “not true”  
end  
end

def no\_parens\_ok  
if not true  
puts “not true”  
end  
end

---

<div class="post-metadata">

**Author:** ![Good\_Night\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@Good\_Night\_M](https://www.ruby-forum.com/u/Good_Night_M)\
**Post date:** [July 23, 2007, 3:17am UTC](https://www.ruby-forum.com/t/parsing-bug-with-return-not-was-syntax-bug/110084/2 "2007-07-23T03:17:49Z")

</div>

On 7/22/07, Good Night M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sun, 22 Jul 2007 03:50:01 -0400, Bil K. wrote:
> 
> > > myrect.rb:8: syntax error, unexpected kNOT, expecting kEND  
> > > return not ((other.x1 \< self.x0 or self.x1 \< other.x0) and
> > 
> > You need to use the ‘!’ operator instead of the ‘not’ “conjunction”.  
> > It’s a precedence thing – the parser is seeing ‘return not’ – see  
> > parse.y in the source.
> 
> Thanks, maybe I’ll look. It’s not just precedence though, or else  
> ‘return’ itself is part of it:

if binds differently than return. It is precedence.

---

<div class="post-metadata">

**Author:** ![Good\_Night\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d9b06d/32.png) [@Good\_Night\_M](https://www.ruby-forum.com/u/Good_Night_M)\
**Post date:** [July 25, 2007, 6:53pm UTC](https://www.ruby-forum.com/t/parsing-bug-with-return-not-was-syntax-bug/110084/3 "2007-07-25T18:53:19Z")

</div>

On 7/22/07, Gregory B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ‘return’ itself is part of it:
> 
> if binds differently than return. It is precedence.

Except that return isn’t an operator. As far as I can tell, looking  
at parse.y for ruby1.8.6 the parse tree for the original statement  
which raised the question

return not true

should be:

command\_call  
kRETURN expr  
kNOT expr  
primary  
var\_ref  
variable  
kTRUE

There definitely looks to be something strange here.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
