Project

General

Profile

Actions

Bug #21946

closed

`and?` predicate confused for leading `and` keyword

Bug #21946: `and?` predicate confused for leading `and` keyword

Added by Earlopain (Earlopain _) about 11 hours ago. Updated about 7 hours ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]
[ruby-core:124935]

Description

Originally reported at https://github.com/ruby/prism/pull/3337#issuecomment-4004880188

$ ruby -ce $'foo\nand?'
ruby: -e:2: syntax errors found (SyntaxError)
  1 | foo
> 2 | and?
    |    ^ expected an expression after `?` in the ternary operator
    |    ^ unexpected '?'; expected an expression after the operator
    |     ^ unexpected end-of-input, assuming it is closing the parent ternary expression

Same for and! and or . parse.y is not impacted

Fix in https://github.com/ruby/prism/pull/3966

Updated by Earlopain (Earlopain _) about 7 hours ago Actions #1

  • Status changed from Open to Closed

Applied in changeset git|54eb330f8cc9f5a5b67ccfa5247cd8b98fb1ef44.


[ruby/prism] Correctly handle and? and similar on ruby 4.0

It gets confused for syntax introduced in https://bugs.ruby-lang.org/issues/20925
But it actually should be a plain method call.
!/? are not valid as part of an identifier, methods
however allow them as the last character.

Fixes [Bug #21946]

https://github.com/ruby/prism/commit/5d80bc5e1a

Actions

Also available in: PDF Atom