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
NAME("name", n->name); break; } case PM_NO_KEYWORDS_PARAMETER_NODE: { /* `def f(**nil)` -- explicit kwarg rejection. Spinel's keyword-arg handling is already conservative (only known keys accepted), so the explicit "no keywords" marker is effectively a no-op at the codegen level. We emit the node so a ParametersNode carrying it doesn't leave a NULL keyword slot, but the compile-time effect is nothing. */ N("NoKeywordsParameterNode"); break; } case PM_INTEGER_NODE: { pm_integer_node_t *n = (pm_integer_node_t *)node; N("IntegerNode"); if (n->rest) R("rest", n->rest); if (n->block) R("block", n->block); A("posts", &n->posts); /* Surface keyword_rest so the new PM_NO_KEYWORDS_PARAMETER_NODE case below is reachable. Existing collect_params_str walker only acts on KeywordRestParameterNode (`**kw`), so the NoKeywordsParameter (`**nil`) marker passes through as a no-op which matches its compile-time semantics. */ if (n->keyword_rest) R("keyword_rest", n->keyword_rest); break; }test/no_keywords_param.rbaddedView file
Loading diff…
test/no_keywords_param.rb.expectedaddedView file
Loading diff…