Skip to content

A kept function's errors: its own file's name for it, said at the function - #75

Merged
jeany55 merged 1 commit into
mainfrom
signals-doc-and-message
Oct 26, 2026
Merged

jeany55 merged 1 commit into
mainfrom
signals-doc-and-message

Conversation

@jeany55

@jeany55 jeany55 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Found while compiling the examples for the new TrigScript library guide (scm-js/scm-js#84).

The bug. A signal handler that gives back an action, cleared.on((wave) => setResources(P1, "add", wave, "ore")), is refused, which is correct: a kept function can't return an action. But the error came out as

__trigscript__/signals.ts:81 the function handed to ignal } from "tri is kept as a value, …

There were two problems:

  • Garbled name. functionName read the node's text through the body being compiled (signals.ts) instead of the file the function is written in (main.ts), so it cut the wrong file's text at the right offsets.
  • Wrong place. The error was reported where the library stores the handler, not at the handler itself.

The fix:

  • Names and parameters are read from the function's own source file.
  • The return-type error is reported at the function, so it now reads main.ts:4 the function handed to cleared.on is kept as a value, ….
  • signals.ts's header example, which showed exactly the refused form, now uses braces. compiler/generated/stdlib.ts was re-embedded.

Checked: a test in tests/function-values.test.ts covers this; npm run typecheck passes, and vitest run gives 75 files and 1384 tests passed.

A friendlier option, not taken here: accept an expression-bodied arrow whose result is an action wherever the expected type returns void, treating the action as a statement. That would be a language change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U79fdupFuMLxYQmMJtffPN

…ction

functionName read a node's text through the body being compiled, so a handler written in
main.ts and kept by a library (Signal.on stores it in signals.ts) was named by a slice of
the library's text at main.ts's offsets: "the function handed to ignal } from \"tri".
The name is now read from the file the function is written in, and so is a parameter's.

The check that a kept function gives back a number, a boolean, a text, a unit, a function
or nothing is now said at the function itself, not where it is kept, which may be a
library's line far from the code to change.

signals.ts's header showed the very handler that is refused, `(wave) => setResources(…)`;
it has braces now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U79fdupFuMLxYQmMJtffPN
@jeany55
jeany55 merged commit 8c734d5 into main Oct 26, 2026
1 check passed
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