Repository navigation
fix: capability method bodies did not know their own parameter types - #560
Merged
Merged
Conversation
_gen_capability_method emitted the signature and then generated the body
without registering the method's parameters, so inside the body every
argument resolved as unknown. print() picked its format from that, and fell
back to the float default:
capability ConsoleProgress {
effect Progress,
function on_start(idx: i32, total: i32, label: string) -> void {
print(idx) print(total) print(label)
},
}
before FLOW_LOG("%g", idx) FLOW_LOG("%g", total) FLOW_LOG("%g", label)
after FLOW_LOG("%d", idx) FLOW_LOG("%d", total) FLOW_LOG("%s", label)
The same body in a plain function has always generated %d, %d, %s. Only
capability methods were affected, and every one of them was.
On arm64 that prints a double read out of an int slot, so a capability method
printing its arguments printed garbage. Spotted in flow-scikit, where
ConsoleProgress_on_fit_start printed two of its three arguments wrongly and
clang had been reporting it as nine -Wformat warnings the build did not
surface.
The fix mirrors what _gen_function already does: save the scope, register
each parameter with the overload resolver and the type table, generate, then
restore in a finally so an error inside the body cannot leak the scope.
Effects and capabilities are a headline feature, so this is worth a test that
pins both halves: the formats themselves, and that a plain function and a
capability method with identical bodies generate identical output.
Unit 1517 passed, tier-2 687/687.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
godofecht
added a commit
that referenced
this pull request
Aug 19, 2026
…uth (#565) Two of the limitations recorded on the showcase were not limitations, and the third described a failure mode the compiler no longer has. Capabilities are not stateless. Capability methods have no `self`, which is true and worth saying, but the note went further and said Flow has no mutable globals, so a handler "cannot accumulate state (e.g. a real collecting test-spy or a metrics counter)". Both of those work: let mut call_count: i32 = 0 capability CountingLogger { effect Log, function info(msg: string) -> void { call_count = call_count + 1 }, } -> handler ran 3 times A spy collecting numbers into a static array works too. The real limit is the type: module statics must be a primitive, a fixed array of primitives, or ptr<T>, so a handler accumulating strings or structs has nowhere to put them. That is now what the page says, with issue #562 for the underlying question. Dynamic capability objects no longer fail the way the note describes. It said the `capability EffectName` parameter style "type-checks and generates C syntax-cleanly" and then silently falls back to zeroed defaults. It does not: strict type checking rejects it, and under --lenient it emits C referencing an undeclared identifier. Still bad, but loudly rather than silently, and worth saying accurately. Issue #561. The type-inference workaround is removed. `let m: string = msg` existed because capability method bodies did not know their own parameter types, so a string parameter printed as a float. Fixed in #560, so the example now passes the parameter straight to printf and still verifies. A stated limitation that is not real costs readers work, which is why these are worth correcting rather than leaving. Effects showcase: 27 of 28 blocks verified, the last one an intentional pattern illustration. Unit 1517 passed, links clean. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while investigating #547. Unrelated to that crash, and real on its own.
The bug
_gen_capability_methodemitted the signature and then generated the body without registering the method's parameters. Inside the body every argument therefore resolved as unknown, andprint()fell back to the float default.FLOW_LOG("%g", idx)FLOW_LOG("%g", total)FLOW_LOG("%g", label)FLOW_LOG("%d", idx)FLOW_LOG("%d", total)FLOW_LOG("%s", label)The identical body in a plain function has always generated
%d,%d,%s. Only capability methods were affected, and every one of them was.On arm64 that prints a double read out of an int slot, so any capability method printing its own arguments printed garbage. In flow-scikit's build,
ConsoleProgress_on_fit_startprinted two of its three arguments wrongly:clang had been reporting these as nine
-Wformatwarnings the whole time; the build just never surfaced them.The fix
Mirrors what
_gen_functionalready does: save the scope, register each parameter with the overload resolver and the type table, generate the body, restore in afinallyso an error inside the body cannot leak the scope into the next function.Tests
Two, because one alone would not have caught it:
%d,%d,%sand no%gappearsFLOW_LOGlinesBoth fail on the unfixed generator; I checked by reverting only
c_generator.pyand re-running.Not a fix for #547
Worth saying plainly, because it looked like one at first. Rebuilding flow-scikit with this change made the #547 SIGBUS disappear, 20 runs out of 20. That is not evidence of a fix — adding a dead function did the same thing. A minimal C program confirms that printing an int through
%fmisreads but leaves the allocator intact:The real cause of #547 is an undersized
mallocin the example itself, reported there with the AddressSanitizer trace.Validation
./flow test --tier2 --strict687/687ruff check srcclean