Skip to content

fix: read client-synced control state like event.control.value - #71

Merged
AdamMusa merged 31 commits into
mainfrom
fix/control-value-readers
Nov 20, 2026
Merged

AdamMusa merged 31 commits into
mainfrom
fix/control-value-readers

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Problem

Seven documented examples read the user's choice off the control: event.control.value in an on_change / on_select handler (control_date_picker__1, control_time_picker__1, control_dropdown__1, control_slider__1, control_switch__1), and field.value / toggle.value afterwards (control_dropdown__3, control_switch__2). Controls only had control.props["value"], so every one of these reads raises NoMethodError on v0.0.23 and on main.

Fix

51 public readers on 42 control classes, only for the state the Flutter client writes back to Ruby after user interaction, and only on the classes that declare that property. Each returns props[name] exactly as props store it (the wire value, normalized when it was set: Ruflet.dropdown(value: :apple).value is "apple"). After a client change it returns what the client sent, as Page#apply_client_update stored it. No engine change is needed, because the renderers already send update_control before the event.

The readers are defined once, at the end of ruflet_ui.rb, from the explicit table in Ruflet::UI::ClientStateReaders (new file packages/ruflet_core/lib/ruflet_ui/ruflet/ui/client_state_readers.rb). Each table class includes a reader module of its own (ClientStateReaders::RufletComponentsSwitchControl, ...). There is no method_missing or respond_to_missing? override, so CRuby and the embedded mruby VM define the same methods.

Wire type Classes (readers)
Checkbox, Switch, Slider Components:: and RufletComponents:: CheckboxControl, SwitchControl, SliderControl, and their Cupertino classes (value)
RangeSlider, DateRangePicker RangeSliderControl, DateRangePickerControl (start_value, end_value)
RadioGroup, SearchBar, AutoComplete, Dropdown (incl. dropdown_m2), TimerPicker value
TextField Components::TextFieldControl, TextFieldControl, CupertinoTextFieldControl (value, selection)
DatePicker, TimePicker value, entry_mode (CupertinoDatePickerControl: value)
Picker, Tabs, NavigationBar/Drawer/Rail, PageView, Cupertino segmented buttons selected_index
SegmentedButton Components::SegmentedButtonControl (selected, selected_index), SegmentedButtonControl (selected)
Chip selected
ExpansionTile, ExpansionPanel expanded

Left out on purpose: open (every object has a private Kernel#open), Dropdown text (the private Kernel text helper), client values on classes that do not declare the property, Page/View/Window measurements, and properties the client never writes back. Everything else is still read with control.props["name"].

When the app answers the read itself

Apps on v0.0.23 may already answer these reads with their own method or method_missing. The reader leaves those in charge, except as listed under "Behavior changes":

  • An app method of that name defined before Ruflet loads (any ancestor, any visibility): that reader is not defined. install! returns the skipped pairs ([] with nothing app-defined).
  • Defined later on the class, a subclass, the object, or a module included into the class: it comes first in the lookup.
  • Defined later above the class (Ruflet::Control, PlatformControl, a framework module such as TextInputMethods, Object, Kernel; any visibility): the reader checks on every call and calls it with super, arguments and block unchanged. Where that method is private, or protected below Object, control.value raised on v0.0.23 (Behavior changes 3).
  • An app method_missing (in front of Ruflet's Kernel#method_missing, wrapping it, or after it: a module included into Kernel, a BasicObject#method_missing in place of Ruby's, a module prepended to BasicObject, a wrapper around SharedControlForwarders#method_missing): the reader calls method_missing with the arguments and block, so control.value goes where it went on v0.0.23, also when a private method of that name sits above the class or a protected one below Object. When the method after the reader is public, or protected on Object, Kernel or a module Object includes, the reader calls it instead, as CRuby's lookup did for control.value from code whose self is an Object (not for public_send or a BasicObject caller: Behavior changes 4). install! records Ruflet's two method_missing definitions and Ruby's built-in one on every call, so a framework reload (ruflet run hot reload) keeps them Ruflet's.
  • When that method_missing passes the read to super: on CRuby, Ruby's BasicObject#method_missing builds its error from the last method miss, and the reader's own call to method_missing is not a miss. So the reader first repeats, on a throwaway object (ClientStateReaders::MISSED_CALL), the miss control.value made on v0.0.23: of a method that does not exist, or of a private or protected one when the method after the reader is one. The error then matches v0.0.23's in class, message, name, receiver, args and private_call?, whatever missed before. Reads that reach no method_missing make no miss. REPEATS_MISS is probed at load in a Fiber of its own (CRuby keeps the last miss per Fiber), so require "ruflet" leaves the caller's last miss as it was. It is false in the VM: this mruby raises "private method called" before any method_missing runs, and its BasicObject#method_missing always says "undefined method", so there is nothing to repeat.
  • An extension helper named like a reader. register_control(:expanded, ...) after load defines a private Kernel helper. That helper is Ruflet's, not the app's (Behavior changes 5). Once the app makes it public or protected on Kernel, tile.expanded calls it, as on v0.0.23. In this mruby, registering an extension after load raises TypeError (Kernel.send(:private, helper) with a String, on v0.0.23 too), so this case is CRuby's.

Only when none of these applies does the reader answer: props[name] with no arguments, the ArgumentError of a zero-argument method with arguments; a block is ignored.

Behavior changes

All of them concern only the 51 (class, name) pairs. 1 is the bug fix itself, and 2 is what adding a public method means. 3-9 follow from it, because a Ruby method cannot see how it was called (with a receiver or not, through public_send, from which self). They apply only to an app that defines its own method of that name or its own method_missing, to a late extension helper of that name, to the VM, or to refinements. Each turns a call that raised into one that answers, or changes which method answers or which error is raised.

  1. No app method: reading one of the 51 properties raised NoMethodError on v0.0.23 and main, and now returns props[name]. A call with arguments now raises ArgumentError on both runtimes. On main, CRuby built an unrelated generic value control for toggle.value(1) (it ended up in the pending DSL app or the enclosing builder block), and mruby raised NoMethodError. A block alone is ignored. There are no setters.
  2. For those pairs, respond_to?, method, public_send and try see a public method, and each of the 42 classes has its reader module at ancestors[1]. Nothing else changes in any control class, Object, Kernel or BasicObject. Ruflet::Extensions gains kernel_helper(name).
  3. A private method of that name above the class (a top-level def value, a private Ruflet::Control#value), or a protected one below Object (on Ruflet::Control, PlatformControl, a module the class includes), defined after Ruflet loads, with no app method_missing: control.value and public_send(:value) now call it. v0.0.23 raised "private method 'value' called" or "protected method 'value' called".
  4. A protected method of that name on Object, Kernel or a module Object includes, defined after Ruflet loads: public_send(:value), and control.value from code whose self is not an Object (a method of a BasicObject subclass), now call it. v0.0.23 raised "protected method 'value' called", or went to the app's method_missing if it had one. control.value from code whose self is an Object called it on v0.0.23 and still does.
  5. An extension helper named like a reader (register_control(:expanded, ...) after load, CRuby only): a plain tile.expanded returns the state, where v0.0.23 raised "private method 'expanded' called". A call without a receiver from inside a table-class method (expanded in an ExpansionTile method) also returns the state, or the app method_missing's answer; v0.0.23 built an empty expanded control. Calls with arguments or a block still reach the helper, unless the app has its own method_missing (6).
  6. An app method_missing plus a private method of that name above the class, or a protected one below Object: calls that reached that method on v0.0.23 from inside the control (no receiver, self.value, send(:value), instance_eval), and protected calls from another control, now go to the method_missing. Ruflet's own extension helpers are such private methods, so expanded(content: ...) in an ExpansionTile method goes there too. control.value went to the method_missing on v0.0.23 as well.
  7. A call without a receiver (a bare value in a control method, self.value, send(:value), super from a value an app subclass defines) that an app method_missing passes to super now raises what control.value raises: NoMethodError "undefined method 'value'", private_call? false. On v0.0.23 the bare word raised NameError "undefined local variable or method", super raised NoMethodError "super: no superclass method 'value'", and all but the bare word had private_call? true. rescue NameError still catches every one of them.
  8. In the VM, where v0.0.23's mruby raised for a call with a receiver (a private method_missing, a private or protected method in front of it, a protected Object method, a method_missing after Ruflet's private Kernel#method_missing), the call now goes where CRuby sends it. When such a method_missing then calls super, mruby's error says "undefined method".
  9. Refinements (CRuby only) of a class above a table class: the reader answers as if the refinement were not active.

CRuby and the VM differ only in: refinements; registering an extension after load (raises in this mruby); a call with arguments when the app's method_missing comes after Ruflet's (CRuby builds a generic control for a Ruflet object, the VM passes the call on); and the super error messages in 7 and 8. From the code, not run (Ruby 3.1, the gemspec minimum, is not installed here): app_method_missing? compares the owner of the control's method_missing, so a class that only does public :method_missing counts as an app method_missing on 3.2+ but not on 3.1, where the reader answers instead of raising.

Verification

Head 9b99f34. It merges origin/main dd924eb into bef75c4 with a merge commit and no conflicts. No history was rewritten. Since bef75c4 the merge brings only main's packages/ruflet changes (#70, #75) and .gitignore; git diff --stat bef75c43 9b99f340 -- packages/ruflet_core packages/ruflet_server packages/ruflet_rails packages/ruflet_record tools ruby_runtime is empty. Against main, git diff --name-only dd924eb3 9b99f340 lists the 7 files of this PR: the ruflet_core lib (3) and readers test, the server and rails tests, and the harness test. There are no template, CLI or packaging files, so published gems that fetch template main are unaffected. Everything below ran on 9b99f34, on CRuby 4.0.5 with GEM_HOME unset and one process per test file, unless the line says otherwise.

  • Suites, in an export of 9b99f34 with RUFLET_TEMPLATE_ROOT at the local ruflet-template clone (as in CI), with 0 failures and 0 errors in each:
    • packages/ruflet: 18 files, 512 runs, 3233 assertions (compat_goldens_test.rb: 242 runs);
    • ruflet_core: 191 files, 1125 runs, 12390 assertions, 1 skip;
    • ruflet_server: 14 files, 51 runs, 187 assertions;
    • ruflet_rails (bundle exec): 17 files, 295 runs, 2812 assertions.
  • H1: ruby test/compat/compat.rb --jobs 4 in packages/ruflet checked 234 goldens, exit 0.
  • Readers tests:
    • packages/ruflet_core/test/client_state_readers_test.rb gives 41 runs, 619 assertions, 0 failures on seeds 1, 977, 4242, 31337 and 65000, and on Ruby 3.4.5 (seed 31337).
    • The head test file run against other sources (seed 4242) gives:
      • main dd924eb: 13 failures, 19 errors;
      • v0.0.23: 13 failures, 20 errors;
      • 2a95acf (round 7): 2 failures (test_a_call_without_a_receiver_raises_what_a_call_with_one_raised, test_an_app_method_missing_that_calls_super_raises_what_main_raised);
      • 25fc1ed (round 8): 1 failure (test_requiring_ruflet_leaves_the_last_miss_alone).
    • The embedded test (tools/embedded_vm_harness/tests/client_state_readers_test.rb) on CRuby: 359 assertions pass (2 runs, and on 3.4.5).
    • The wire test (ruflet_server/test/control_value_readers_wire_test.rb, 2 runs, 4 assertions) and ruflet_rails/test/html_app_test.rb (45 runs, 144 assertions) pass in the suites above.
  • Planted bugs, each applied alone: the core test (seed 1) catches all 12.
    • The load probe without its Fiber (round 8's begin/ensure); with no Fiber and no ensure; with the Fiber followed by a plain miss.
    • The repeat removed; added before super; added before props[key]; moved after method_missing.
    • REPEATS_MISS forced false; always the "undefined" miss; private and protected swapped; every method counted as private.
    • Ruby's BasicObject#method_missing recorded only on the first install!.
  • Probes, each result given as v0.0.23 / main / head:
    • The seven doc reads (date_picker, time_picker, dropdown, slider, switch .value) raise NoMethodError / NoMethodError / return the props value. switch.value(1) gives a generic value control / a generic value control / ArgumentError.
    • Behavior changes 3, with a top-level def value: switch.value and public_send(:value) raise "private method 'value' called" / the same / return the helper's value. A private Ruflet::Control#selection, read as text_field.selection, behaves the same way. With a protected Ruflet::Control#selected_index, tabs.selected_index and public_send raise "protected method" / the same / return the method's value.
    • Behavior changes 4, with a protected Object#value: t.value returns its value on all three. public_send(:value) and a BasicObject caller raise "protected method 'value' called" / the same / return its value. With an app Ruflet::Control#method_missing too, both give the method_missing's answer / the same / the protected method's value.
    • Behavior changes 5, after register_control(:expanded, ...): tile.expanded raises "private method 'expanded' called" / the same / returns true. tile.instance_eval { expanded } builds an expanded control / the same / returns true. With arguments, all three build the control.
    • Behavior changes 6, with a top-level def value and an app Ruflet::Control#method_missing: t.value gives the method_missing's answer on all three. t.instance_eval { value }, t.instance_eval { self.value } and t.send(:value) return the helper's value / the same / the method_missing's answer.
    • Behavior changes 7, with super from an app subclass's value and an app method_missing: "super: no superclass method 'value'" with private_call? true / the same / "undefined method 'value'" with private_call? false.
    • The last miss across require "ruflet", read back through BasicObject#method_missing after a rescued bare word, private, protected or super miss: identical before and after on all three. It is also identical on head on Ruby 3.4.5 (bare word, private, super).
  • mruby VM:
    • Built from an archive of 9b99f34 with a fresh clone of the pinned mruby 449627d, using tools/build_apple_vm_artifacts.sh macos narrowed to arm64 (this Mac has no Rosetta), and then the harness. All 278 .rb files under ruflet_core/lib and ruflet_server/lib appear verbatim in its 10_framework.rb.
    • The readers harness test: 346 assertions pass (3 runs; the 13 extension-helper assertions are CRuby's), and REPEATS_MISS is false. scoped_helper_test and icon_deferral_test pass.
    • Two other harness tests stop early: compat_test at line 67 (SystemExit is not defined in this mruby) and regexp_test at line 132 (String#partition with an OnigRegexp). Neither involves the readers.
    • The prebuilt ruby_runtime archives carry an older framework, so ruflet build --self apps get the readers once those artifacts are rebuilt.
  • Method surface: a CRuby listing (172,701 lines) of every named Ruflet::Control class plus Object, Kernel and BasicObject covers ancestors and every instance method with its visibility and owner. Against main, it differs in only three places: 42 ancestor lists (a ClientStateReaders module inserted at ancestors[1]), the 51 public readers (owned by those modules), and Ruflet::Extensions.kernel_helper.
  • Warnings: ruby -w, requiring ruflet, prints the same 2 warning lines on head and on main.
  • CI on 9b99f34: all 11 checks pass: Build linux, macos, web, windows, Android and iOS Simulator; Ruflet Explorer linux and windows, two runs each; and Verify Ruflet Explorer. "Publish completed prebuild revision" is skipped, as before. Verify Ruflet Explorer ran on Ruby 3.4.5, and its log shows the readers test at 41 runs, 619 assertions, 0 failures.

Other open PRs

I changed no other PR. git merge-tree --write-tree of 9b99f34 with each of the 14 other open PRs (#76-#84 and #86-#90; #91 belongs to another session) is clean, except #84. #84 conflicts with main dd924eb itself in packages/ruflet/lib/ruflet/cli/build_command.rb (#75's split). This PR does not touch that file, and #84 merges cleanly with bef75c4. On the merged trees with the PRs that change ruflet_core, ruflet_server, ruflet_rails or ruflet_record (#82, #83, #86, #87, #88, #89, #90), three tests pass: the core readers test (41 runs, 619 assertions), the embedded test on CRuby (359) and the wire test.

Note

On the docs site, control_dropdown.md writes field.value # => "s" after # later:. That holds only once the user picks Small; right after construction the value is nil (test_reader_returns_what_the_user_selected_on_the_client).

The control docs read a control's current value off the control itself
(`event.control.value` in on_change/on_select handlers, `field.value` and
`toggle.value` later on), but controls only exposed `props["value"]`, so
those reads raised NoMethodError on v0.0.23 and on main.

Each control now answers a bare read (no arguments, no block) of any
property its KEYWORDS declare, through method_missing/respond_to_missing?.
Events are not readers, there are no setters, public methods of the same
name keep winning, and every call with arguments or a block takes the
previous method_missing path unchanged. Values are the current ones: Page
already applies update_control and change/select event values to props
before handlers run. `controls` reads the live children list, and the
dropdown_m2 spellings read the Dropdown key they are stored under.

The Rails HTML recorder service matched actions with respond_to?, so the
AudioRecorder properties (data, key, configuration) would have become
"actions"; it now checks the recorder's real public methods, which keeps
every action resolving exactly as before.
Review of the first version: readers for every declared property, answered
through method_missing, made respond_to?/method/public_send/try answer for
784 names, and which names were readable depended on the runtime (CRuby
reached method_missing for private Kernel helpers such as open/icon/color,
the embedded mruby VM did not).

Readers are now ordinary public methods, defined once at load time from an
explicit table (Ruflet::UI::ClientStateReaders): only the properties the
Flutter renderers send back with update_control after user interaction
(value, selected, selected_index, start_value/end_value, expanded,
selection, entry_mode), and only on the classes that declare them. That is
51 readers on 42 classes; nothing else about any control changes. A reader
is never defined over an existing public or private method of the class or
an ancestor; `open` and Dropdown `text` are not in the table because they
are private Kernel methods on every object. The method_missing /
respond_to_missing? override, the `controls` and dropdown_m2 alias readers,
and the Rails recorder guard are gone: AudioRecorder gets no readers, so
html_app.rb is back to main.

The same 51 readers, and no other method or respond_to? change, exist on
CRuby and in the embedded VM built from these sources
(tools/embedded_vm_harness/tests/client_state_readers_test.rb).
@AdamMusa AdamMusa changed the title fix: read declared control properties like event.control.value fix: read client-synced control state like event.control.value Nov 7, 2026
No table entry collides with an existing method, so the guard was never
exercised: removing it, or narrowing it to public methods, kept every
test green. define_readers takes its own [class, names] pairs, and the
CRuby and embedded-VM tests now run it on classes with public,
protected, private, inherited and Kernel methods of those names. They
also pin that a reader rejects keywords and ignores a block.
The readers sat in front of every method an app could add above the
table class (Ruflet::Control, PlatformControl, framework modules, Object,
Kernel), so an app that had added its own `value` on v0.0.23 got the
reader instead.

Each table class now gets its readers from its own module, included into
the class, and a reader hands the call on whenever something else would
have answered it without the reader:
- a method of that name after the reader module in the lookup, public,
  protected or private, including Object and Kernel (super, with the
  arguments and block);
- a method_missing other than Ruflet's own Kernel#method_missing, on the
  object, a subclass, a control class, Object, or in place of Ruflet's.
Methods defined on the class itself, a subclass, the object, or a module
included into the class later come first in the lookup as usual.

Tests cover each place an app can put such a method, before and after
Ruflet loads. The embedded test no longer calls install! itself, so it
fails when the framework stops installing the readers.
`ruflet run` hot reload drops every watched file from $LOADED_FEATURES and
loads the script again. When the framework sources sit inside the app
directory, that loads ruflet_ui.rb a second time, which defines
Kernel#method_missing again. The readers compared it with the definition
they recorded at the first load, took the new one for an app's
method_missing, and handed every read to it, so `toggle.value` raised
NoMethodError after the first reload.

install! now records Kernel#method_missing on every call; ruflet_ui.rb
calls it right after defining it, on every load. Loading the readers file
again also no longer warns about METHOD_DEFINED_COUNTS_PRIVATE.
…ion helpers

On CRuby, a call with a receiver to a private or protected method goes to
method_missing. So on v0.0.23, an app with its own method_missing that
answers `value` also got `control.value` when it had a private or
protected method of that name above the control class, such as a
top-level `def value` in the script. The readers handed those calls to
that method instead (`chip.selected` returned the script's helper and set
an instance variable on the chip).

A reader now hands the call to the app's method_missing unless the method
after the reader module is public. Calls that reached such a private or
protected method from inside the control (no receiver, self., send) or a
protected one from another control now reach the method_missing too: a
method cannot tell how it was called. The module comment lists this.

A helper that Ruflet::Extensions.register_control defines after load for
an extension named like a reader (`expanded`) is a private Kernel DSL
helper, so the readers took it for an app method and `tile.expanded`
built an `expanded` control. register_control now records the helper it
defined (Ruflet::Extensions.kernel_helper), and a plain read (no
arguments, no block) ignores that unchanged helper. Calls with arguments
or a block still reach it, and an app's own method of that name still
wins.

Tests (core, and the embedded test on CRuby and mruby where they apply):
keyword arguments and blocks handed to an app method_missing; an app
method_missing with a private Object helper, a protected Ruflet::Control
method, a private framework-module method ahead of a public Object
method, and a public Object method; the reviewer's script; extension
helpers named `expanded` and `selection`, with app methods of those names;
the recorded helper surviving a framework reload. The comment on `skipped`
and the "app's method always wins" wording are corrected.
When an app has its own method_missing, a reader passes the call to it
unless the method after the reader is public. That visibility was asked
with public_method_defined? of the first module after the reader that
has the method, usually the superclass. In the embedded VM that is a
bootstrap.rb fallback over public_instance_methods, which lists a public
method even when a private one of the same name hides it. So with a
private Ruflet::Control#value over a public Object#value, `toggle.value`
went to the method_missing on CRuby, but to the private method in mruby.

The readers now find the module whose method `super` would call (the
first in the lookup that has the method itself, a visibility change
included) and read the visibility there. CRuby asks
method_defined?/private_method_defined?/public_method_defined? with
inherit false; mruby, whose predicates take no such flag, reads the
module's own method lists.

The extension-helper check uses the same lookup instead of
UnboundMethod#owner. register_control's Kernel helper is a visibility
change (Kernel makes the SharedControlForwarders method private), and
for such a method Ruby 3.1 reports the defining module as the owner,
not Kernel (3.2 changed this, bug #18729). On 3.1 a plain
`tile.expanded` would have built an `expanded` control again.

Tests: a private or protected Ruflet::Control#value, and a bare
`private :value`, in front of a public Object#value; a public one in
front of a private Object#value (core, and the embedded test on both
runtimes). A fresh-process core test makes UnboundMethod#owner answer as
on Ruby 3.1 and checks `tile.expanded`. An app method_missing now also
gets bare and argument calls of an extension helper from inside the
tile, which the module comment's "Not covered" list now says.
The reload test now also reads ClientStateReaders.skipped after the
second require. An install! that ran define_readers again would find the
readers it defined the first time and list all 51 pairs as skipped; no
test noticed that before.
register_control's Kernel helper (say `expanded`) is private, and a plain
`tile.expanded` reads the tile's state instead of building a control. The
check compared Kernel.instance_method(:expanded) with the recorded helper,
and == ignores visibility. So after `module Kernel; public :expanded; end`
the reader still answered, where v0.0.23 called the public helper and
built an `expanded` control. The helper now counts as Ruflet's only while
Kernel's entry is still private; once the app makes it public or
protected, `tile.expanded` calls it again.

Protected counts because CRuby lets a caller that is an instance of the
method's module call a protected method with a receiver, and every caller
is an Object. The same applies to any protected method of Object, Kernel
or a module Object includes: with an app method_missing, v0.0.23's
`control.value` called such a method, while the reader sent the call to
the method_missing. reachable_method_after? (was public_method_after?)
now treats those protected methods like public ones. A protected method
further down (Ruflet::Control, PlatformControl, an included module) still
sends the call to the method_missing, as on v0.0.23.

One known difference is left: with an app method_missing and a protected
Object/Kernel method, `public_send(:value)` went to the method_missing on
v0.0.23 and now reaches the protected method.
app_method_missing? calls Kernel#method unbound so that a control with a
`method` of its own (an HTTP-verb style property, say) cannot change the
answer. Nothing tested that: asking `control.method(:method_missing)`
instead passed every test, and in such an app it raises NoMethodError
(`owner` for nil) on every read of every reader. The core and embedded
tests now define `Ruflet::Control#method` and check that the reader, and
an app method_missing, still answer. The core test also gives one
control a singleton `method`.
…s comment

The "Not covered" bullet for a protected Object or Kernel method now says
what the embedded VM did on v0.0.23 (it raised for every such call with a
receiver), and the next bullet names Ruflet's own extension helper
instead of "such" a helper, which no longer referred to the bullet
above it. Comment only.
app_method_missing? looked only at the first method_missing in the
control's lookup. In an app whose method_missing comes after Ruflet's
own Kernel#method_missing (one in a module included into Kernel, before
or after Ruflet loads, or one on BasicObject in place of Ruby's own),
that first one is Ruflet's, so the reader returned props["value"].
On v0.0.23 and main, `toggle.value` reached the app's method_missing:
Ruflet's Kernel#method_missing, and SharedControlForwarders' after it,
call super at once for a call with no arguments and no block.

When the first method_missing is Ruflet's, the readers now also walk
the modules after Kernel (Kernel's own ancestors, then BasicObject's)
and count any method_missing there that is not Ruflet's
SharedControlForwarders one or Ruby's own BasicObject one. install!
records those two along with Kernel's, so a framework reload keeps
them Ruflet's. Ruby's is recorded only when it is built in (no
source_location and no parameter names, on CRuby and in the VM), so a
BasicObject#method_missing defined before Ruflet loads counts as the
app's. The walk stops at Ruby's own, which calls nothing after it.

The reader still hands the call to method_missing, so it goes through
Ruflet's Kernel#method_missing as on v0.0.23: a plain read reaches the
app's, and a call with an argument builds the generic control CRuby
built there. In the embedded VM, v0.0.23 raised for these calls (mruby
stops a call with a receiver at Ruflet's private Kernel#method_missing);
they now reach the app's method_missing, as on CRuby.

Tests: the four cases in fresh processes (core), a module included into
BasicObject that Ruby's own never reaches, and the same cases in the
embedded test, where a module included into SharedControlForwarders
stands in for one included into Kernel before Ruflet loads.
With an app method_missing, a protected `value` in a module that Object
includes (a script's top-level `include` puts it there) answers
`toggle.value`, as on v0.0.23. reachable_method_after? asks whether
Object's ancestors include the method's module, but no test had such a
module, so checking only Object and Kernel passed every test. A core
row (`toggle.value`, `instance_eval`, `public_send`) and an embedded
row (`toggle.value`, on CRuby and in the VM) now pin it.
The readers treat Ruflet's SharedControlForwarders#method_missing as
Ruflet's only while it is the definition install! recorded. An app that
wraps it (alias, then a method_missing of its own) got `toggle.value`
on v0.0.23 through Ruflet's Kernel#method_missing, and still does. No
test had such a wrapper, so skipping that comparison passed every test.
A fresh-process core row and an embedded row now pin it.
The walk after Ruflet's Kernel#method_missing starts after Kernel's own
place in Kernel.ancestors, so a module prepended to Kernel (a require
hook, say) is not mistaken for the modules Kernel includes. Starting at
index 1 instead would take Kernel's own method_missing for an app's and
send every read to it, and no test prepended anything to Kernel. A core
row and an embedded row now do.
On a framework without the fix, `toggle.value(1)` raised ArgumentError
in the new after-Kernel rows and stopped the embedded test before it
listed its failures. The row now rescues it and records the failure,
so the run shows all 9 failing rows (in the VM built from e79ba92 and
on CRuby with its sources).
…uper

On CRuby, Ruby's own BasicObject#method_missing builds its error from the
thread's last method miss. A reader that hands a read to an app
method_missing calls method_missing itself, which is no miss, so when the
app's called super the error described whatever missed last: after a
rescued bare word (or a bare local_auth / about_dialog, which Ruflet's
Kernel#method_missing answers after such a miss) it was a NameError that
escaped rescue NoMethodError, after a private miss "private method 'value'
called".

The reader now first repeats, on a throwaway object, the miss
control.value made without it: of a method that does not exist, or of a
private or protected one when the method after the reader is. The error
then matches main's in class, message, name, receiver, args and
private_call?. The embedded VM has no such state and skips it.
… again

install! records Ruby's own BasicObject#method_missing on every call, but
only the Kernel and SharedControlForwarders records were pinned: recording
Ruby's only on the first install! passed every test. The reload test now
defines an app BasicObject#method_missing before Ruflet loads, puts Ruby's
own back, and reloads the framework; the reader answers only once the
reload has recorded Ruby's again.
The REPEATS_MISS probe made a private call and then a plain miss on the
loading thread, so `require "ruflet"` replaced whatever had missed before
it: after a rescued bare word or private call, Ruby's own
BasicObject#method_missing called directly said "undefined method" where
main, v0.0.23 and 2a95acf still reported the earlier miss. The probe now
runs in a Fiber of its own. CRuby keeps the last miss per Fiber, so the
caller's stays as on main; REPEATS_MISS is still true on CRuby and false
in the embedded VM.

test_requiring_ruflet_leaves_the_last_miss_alone checks both earlier
misses in fresh processes; it passes on main and fails on 25fc1ed. The
comment of test_requiring_ruflet_is_enough no longer claims its check
covers this.
…erently

The module comment said every caller is an Object, but a method of a
BasicObject subclass is a caller whose self is not one: with a protected
value on Object, Kernel or a module Object includes, CRuby sent its
`control.value` to the app's method_missing (or raised without one), and
the reader calls the protected method. The comment now says so, both in
the "Not covered" bullet and where reachable_method_after? explains why
that method comes first, and it lists the calls that went from raising to
answering without an app method_missing: any call with a receiver to a
private method above the table class or a protected one below Object,
and public_send or a BasicObject caller for a protected one on Object.

`super` from a `value` an app subclass defines is another call without a
receiver: with an app method_missing that passes it on, v0.0.23 raised
"super: no superclass method 'value'" with private_call? true, and the
reader raises "undefined method" with private_call? false. The comment
lists it and test_a_call_without_a_receiver_raises_what_a_call_with_one_raised
pins it.
… alone

Repeating the miss before `super` to an app method, or before returning
props, passed every test: only code that calls method_missing directly
afterwards sees the extra miss. test_reads_that_reach_no_method_missing_leave_the_last_miss_alone
reads after a rescued bare word and after a rescued private call, with no
app method, a public Ruflet::Control#value and a private Object#value, and
checks that the thread's last miss is what it was before the read.
@AdamMusa
AdamMusa merged commit a9b5847 into main Nov 20, 2026
12 checks passed
AdamMusa added a commit that referenced this pull request Nov 20, 2026
#71 added public readers (field.value, tabs.selected_index and 38 more)
to the controls, so MethodContractCoverageTest failed on main once this
branch was merged with it: 40 methods had no spec.

Each reader returns what the control's props hold and sends nothing, so
each gets a local spec naming client_state_readers_test, which covers
them.
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