Repository navigation
Nine syntax gaps that make 12 ruby/spec language files unparseable #27
Description
Twelve language/*_spec.rb files in the pinned ruby/spec corpus fail to parse at all, so they contribute zero to the rbgo conformance measurement — they are not counted as failures, they are simply invisible. That makes this the largest single unmeasured block left in that suite.
Each case below is reduced to a one-liner and compared against the installed MRI (ruby 4.0.5). rbgo here is go-embedded-ruby built on parser v0.1.9.
Parse errors
| # | source | MRI | parser |
|---|---|---|---|
| 1 | class C; def v; end; alias :"#{:a}" v; end |
parses | expected a method name |
| 2 | class C; def m; end; undef :"#{:m}"; end |
parses | expected a method name |
| 3 | (o).a, (o).a = 1, 2 |
parses | unexpected "," after statement |
| 4 | defined?($zz and true) |
"expression" |
expected ), got "and" |
| 5 | for i, in [[1,2]]; p i; end |
1 |
expected IDENT, got "in" |
| 6 | p({:a==>1}) |
{"a=": 1} |
unexpected token ">" |
| 7 | case [0,1,2]; in Array(0,1,2); p :ok; end |
:ok |
expected LABEL, got "0" |
| 8 | p $= |
false |
unexpected "$" after statement |
| 9 | def a; 1; end; p(-> a=a() { a }.call) |
1 |
expected {, got ")" |
Notes on a few:
- 1 and 2: a dynamic symbol (
:"#{…}") as the name given toalias/undef. A plain:symworks. - 3: a parenthesised receiver as a multiple-assignment target. The spec uses it to pin evaluation order:
(ScratchPad << :a; object).a, (…).a = …. - 6: a symbol key whose name ends in
=.{:a= =>1}(with a space) is the same value and may lex differently — worth covering both. - 7: an array pattern written with a constant and parentheses,
Array(0, 1, 2), rather than[0, 1, 2]. - 8:
$=is a real predefined global (the obsolete case-insensitivity flag). The file also uses other punctuation globals. - 9: a default argument that calls a method, followed by a brace body.
One mis-parse, which is worse than an error
o = Object.new
def o.s(x); yield; end
p o.s (:a){ 1 }MRI prints 1. The parser accepts this but binds the brace block to :a rather than to s, so rbgo raises LocalJumpError: no block given (yield). A space before an argument list does not detach a following brace block from the call. This one produces wrong behaviour silently rather than a diagnosable error.
Affected files
alias, assignments, block, class, defined, for, hash, lambda, metaclass, pattern_matching, predefined, string, undef — variables_spec.rb was the fourteenth and has just been fixed on the consumer side (it was a compiler gap, not a parser one).
Two of them — class_spec.rb and string_spec.rb — I could not reduce: my minimal reproductions of the line the error points at parse correctly under both engines, so their real cause is elsewhere in the file and still needs isolating. I am not claiming a cause for those two.
Activity
Close the nine syntax gaps of #27, the mis-parse, and the two unreduc…