Commit b3a34f08

b3a34f089b15Merged

Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

feat(parse): support NoKeywordsParameterNode (def f(**nil))

`def f(**nil)` declares the method explicitly rejects keyword arguments; in CRuby `f(k: 1)` raises ArgumentError. Spinel's keyword-arg handling is already conservative (only known keys accepted), so the explicit rejection marker is effectively a no-op at the codegen level -- but the parser must still recognize the node so Phase 0's UnsupportedNode loud-error doesn't fire on methods that use the marker.

Parser case has no fields beyond base:

case PM_NO_KEYWORDS_PARAMETER_NODE: {
  N("NoKeywordsParameterNode");
  break;
}

ParametersNode walks its keyword-rest slot and emits no codegen for this node type today; the existing slot is already nil-tolerant. No codegen arm needed.

Test exercises:

  • `def add(a, b, **nil); a + b; end` -- the method compiles and positional calls (`add(1, 2)`) work normally. Test does not assert the rejection of `add(1, 2, k: 1)` because Spinel's conservative kwarg handling already wouldn't accept that call shape, so the test would pass with or without the **nil marker.

Out of scope: actual ArgumentError on stray kwargs. Would require runtime kwarg-validation infra Spinel doesn't have.

Tests: 257 pass. Bootstrap: gen2.c == gen3.c.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
b3a34f089b15
Parent
1b82c20f5c96

spinel_parse.cmodifiedView file

@@ -410,6 +410,16 @@
410410 NAME("name", n->name);
411411 break;
412412 }
413+ case PM_NO_KEYWORDS_PARAMETER_NODE: {
414+ /* `def f(**nil)` -- explicit kwarg rejection. Spinel's keyword-arg
415+ handling is already conservative (only known keys accepted),
416+ so the explicit "no keywords" marker is effectively a no-op
417+ at the codegen level. We emit the node so a ParametersNode
418+ carrying it doesn't leave a NULL keyword slot, but the
419+ compile-time effect is nothing. */
420+ N("NoKeywordsParameterNode");
421+ break;
422+ }
413423 case PM_INTEGER_NODE: {
414424 pm_integer_node_t *n = (pm_integer_node_t *)node;
415425 N("IntegerNode");
@@ -658,6 +668,11 @@
658668 if (n->rest) R("rest", n->rest);
659669 if (n->block) R("block", n->block);
660670 A("posts", &n->posts);
671+ /* Surface keyword_rest so the new PM_NO_KEYWORDS_PARAMETER_NODE
672+ case below is reachable. Existing collect_params_str walker
673+ only acts on KeywordRestParameterNode (`**kw`), so the
674+ NoKeywordsParameter (`**nil`) marker passes through as a
675+ no-op which matches its compile-time semantics. */
661676 if (n->keyword_rest) R("keyword_rest", n->keyword_rest);
662677 break;
663678 }