Skip to content

v0.9.0 — HashLit.Braced and Call.Paren

Choose a tag to compare

@tannevaled tannevaled released this 28 Sep 20:01
· 10 commits to main since this release
8490e30

Two bits of written form that the AST was discarding. Both are additive fields with a false zero value, so every existing consumer compiles and behaves exactly as before; only a consumer that reads them changes.

HashLit.Braced (#42, closes #40)

f({k: 1}) and f(k: 1) produced the same node, so nothing downstream could tell a positional Hash from keywords.

The field mirrors MRI, which carries the same bit in the same place: primary: tLBRACE assoc_list '}' sets RNODE_HASH($$)->nd_brace = TRUE, while rb_node_hash_new leaves it 0 for hashes the grammar assembles, and aryset_check reads it back for exactly this question.

As in MRI it is not conditional on being an argument — x = {a: 1} is Braced too. A { that opens a block never reaches the hash-literal production, so obj.m {} builds no HashLit to misread.

Call.Paren (#43, closes #41)

foo and foo() produced the same node, so nothing downstream could tell MRI's VCALL from its FCALL — a difference that is observable: nope raises NameError, nope() raises NoMethodError.

Paren is written form and nothing else: true for an empty list foo(), false for puts 1, obj.m, and a[0] (brackets are not parentheses).

Deciding VCALL takes more than this one bit. foo! and foo? are FCALLs without parentheses (primary: tFID), and a literal block makes an FCALL too. The full rule, documented on the field:

Recv == nil && !Paren && len(Args) == 0 && Block == nil &&
    name is a plain identifier (no trailing ! or ?)

Notes

Both fields were derived from parse.y and checked against the running ruby 4.0.5 oracle. One case is worth knowing: the value-omitted shorthand {x:} is a VCALL under --parser=parse.y and an FCALL under Prism, which is the default on a +PRISM build. These changes follow parse.y.