Skip to content

Reject a constant write_to_port port index at or above MAX_SERIAL_PORTS - #250

Draft
zimri-leisher wants to merge 1 commit into
develfrom
write-to-port-max-serial-ports
Draft

zimri-leisher wants to merge 1 commit into
develfrom
write-to-port-max-serial-ports

Conversation

@zimri-leisher

Copy link
Copy Markdown
Collaborator

MAX_SERIAL_PORTS is the sentinel one past the last real serial port, and the sequencer rejects any index at or above it with SERIAL_PORT_INVALID_INDEX. The compiler accepted it anyway, so this compiled and then always failed at run time (on wasm with no exit code at all):

write_to_port(Svc.Fpy.SerialPortIndex.MAX_SERIAL_PORTS, U32(1))

The port argument is already required to be a compile-time constant, so the check is now made there:

Serial port Svc.Fpy.SerialPortIndex.MAX_SERIAL_PORTS has index 5, which is
outside the 5 ports the sequencer has (Svc.Fpy.SerialPortIndex.MAX_SERIAL_PORTS is 5)

A dictionary whose enum declares no sentinel gives nothing to check against, so those indices are still left to the run-time check.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment thread src/fpy/semantics.py

from fpy.error import CompileError, diagnostic_context
from fpy.macros import TIME_MACRO
from fpy.macros import MAX_SERIAL_PORTS_NAME, TIME_MACRO, WRITE_TO_PORT_MACRO
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.

2 participants