Skip to content

Implement RFC 0028: make untyped R functions callable - #30

Merged
fabriceHategekimana merged 1 commit into
developfrom
implement-rfc-0028-untyped-r-functions
Sep 12, 2026
Merged

fabriceHategekimana merged 1 commit into
developfrom
implement-rfc-0028-untyped-r-functions

Conversation

@fabriceHategekimana

Copy link
Copy Markdown
Collaborator

Summary

Implements the accepted RFC 0028 (tracking: #29): an untyped R function (function(a, b) { ... }) becomes callable, checked on arity only, with its result typed Any.

  • Lang::RFunction now types as a real (Any, ..., Any) -> Any function with n parameters (parameters.len()), instead of the 0-ary Type::UnknownFunction placeholder that rejected any call with arguments.
  • Type::UnknownFunction (preloaded untyped base-R builtins — Position, t, Reduce, …) becomes variadic for the same reason: fixing only RFunction would leave the same bug reachable through every untyped base-R name (the RFC calls this "the load-bearing half").
  • New TypeError::UntypedFunctionArity (T044) replaces the old confusing No signature of function 'x' matches this call ... () -> UnknownFunction message with the RFC's proposed wording when an untyped call's arity is wrong:
    Type error: 'my_addition' is an untyped R function taking 2 argument(s), called with 3.
      help: its body is not type-checked; only the number of arguments is.
    
  • Emitted R is unchanged, as the RFC predicts — verified by hand and by cases/0062's R/main.R rule.
  • Three cases/ entries per the RFC's implementation checklist: the callable case, the arity error message, and the preloaded-builtin case.

Test plan

  • cargo test --workspace — 869 tests pass (0 failures)
  • typr case run — 47 PASS, 0 REGRESS (3 new cases added, all PASS)
  • Manually verified the RFC's Motivation example (docs/philosophy/intro.md's my_addition) now compiles
  • Manually verified Position(1, 2) now compiles
  • Manually verified the arity-error wording matches the RFC's Reference-level explanation
  • Verified emitted R for the canonical example is unchanged (my_addition(num1, num2) |> as.Integer())

Not in scope here (left for follow-up, per the RFC checklist): syntaxe.md and the typr.github.io documentation update (docs/philosophy/intro.md's noplayground removal) — no syntax changed, and the docs live in a separate repo.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ETPqhgWqDMt7UaUQXdxJmN

`Lang::RFunction` (`function(a, b) { ... }`) now types as a real
`(Any, ..., Any) -> Any` function with n parameters, instead of the
0-ary `Type::UnknownFunction` placeholder that made any call with
arguments a type error. `Type::UnknownFunction` (used for preloaded
untyped base-R builtins like `Position`, `t`, `Reduce`) becomes
variadic for the same reason — fixing only `RFunction` would leave
the bug reachable through every untyped base-R name.

- `processes/type_checking/mod.rs`: `Lang::RFunction`'s typing rule
  builds a `Type::Function` with n `Any` params -> `Any`.
- `components/type/mod.rs` and `components/type/function_type.rs`:
  `Type::UnknownFunction`'s conversion to `FunctionType` is now a
  single variadic `Any` parameter -> `Any`.
- `components/error_message/type_error.rs`: new `TypeError::
  UntypedFunctionArity` (T044) replaces the confusing "no signature
  matches () -> UnknownFunction" message with the RFC's proposed
  wording when an untyped function is called with the wrong arity.
- `processes/type_checking/function_application.rs`: wires the new
  error in, using `FunctionType::is_r_function()` to detect the
  untyped-function shape.
- `cases/0062-0064`: regression cases for the callable case, the
  arity error message, and the preloaded-builtin case.

Bumps the `guard_any_type_call_count_is_tracked` baseline 19 -> 21:
two new `any_type()` calls in the `RFunction` typing arm, which is
the RFC's whole point, not a silent degradation.

Tracking issue: #29

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETPqhgWqDMt7UaUQXdxJmN
@fabriceHategekimana
fabriceHategekimana merged commit 303004e into develop Sep 12, 2026
5 checks passed
@fabriceHategekimana
fabriceHategekimana deleted the implement-rfc-0028-untyped-r-functions branch September 12, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant