Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Alternation capture check rejects underscore names and captures from other scopes

Abierto
#4,235 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
c, ruby
Área
compilers

Línea de trabajo

Start in parse_pattern_primitives and inspect parse_pattern_alternation_error alongside parse_pattern_capture. Check the existing pattern-matching coverage in test/ruby/test_pattern_matching.rb and verify that underscore captures are accepted while captures from embedded statements, lambdas, and pin expressions do not affect the surrounding alternation check.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Since the parse-time check for captures inside alternative patterns (ruby/ruby#14923, ruby/ruby@8d0105824f), Prism rejects these once any capture exists earlier in the same pattern:

case [5, 1]
in [x, 1 | _a]                            # variable capture in alternative pattern
in [x, _a | 1]                            # same
in [x, 1 | _]                             # same, even for a bare `_`
in [x, "#{case 1; in y; y; end}" | 2]     # same
in [x, -> { case 1; in y; y; end } | 2]   # same
in [x, ^(case 0; in y; y; end) | 2]       # same
end

Without the sibling capture, the same alternations are accepted (in [1 | _a], in ["#{case 1; in y; y; end}" | 2]). Prism 3.4.9 accepts all of them, and so does parse.y with https://github.com/ruby/ruby/pull/18830 applied. doc/syntax/pattern_matching.rdoc in ruby/ruby says variables starting with _ are the one exception to the alternation rule, and test/ruby/test_pattern_matching.rb there already runs in _ | _a.

As far as I can tell, parse_pattern_primitives only runs parse_pattern_alternation_error on an operand when captures->size is non-zero, and that visitor flags every LocalVariableTargetNode it reaches. It does not skip underscore-prefixed targets the way parse_pattern_capture does, and it descends into embedded statements ("#{...}"), lambdas and pin expressions (^(...)), which are separate scopes as far as the surrounding pattern is concerned. I would expect only the non-underscore captures that belong to the alternation's own operands to be reported, which is what compile.c checks at runtime.

$ ruby -v
ruby 4.0.4 (2026-05-12 revision b89eb1bcbf) +PRISM [arm64-darwin25]
$ ruby --parser=prism -c t.rb      # errors above
$ ruby --parser=parse.y -c t.rb    # Syntax OK with ruby/ruby#18830, otherwise fails for the unrelated sibling reason in https://bugs.ruby-lang.org/issues/22310

I ran into this while testing https://bugs.ruby-lang.org/issues/22310. I have a fix with tests and can open a PR.

Lenguaje dominante
C
Estrellas
1k
Forks
194
Merge medio
2 d 9 h
PR fusionados (30 d)
15

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ruby/prism

Todos los issues de ruby/prism

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.