Skip to content

test_io_read_file_roundtrip: Windows path embedded in Vera string literal triggers \U escape #642

@aallan

Description

@aallan

Origin: Surfaced when the Windows CI matrix entries (added in PR #639 closing #637) ran for the first time. tests/test_codegen.py::TestIOOperations::test_io_read_file_roundtrip fails on Windows with:

lark.exceptions.VisitError: Error trying to process rule "STRING_LIT":

[E009] Error at line 4, column 23:
  Invalid escape sequence: \U

The pattern

A test fixture constructs a Vera program containing a string literal with what Vera's grammar interprets as an invalid escape sequence (\U). On Windows, the construction probably embeds a Windows path like C:\Users\runner\... directly into the literal — Vera's parser sees \U and rejects it.

Likely test code shape:

source = f'''
public fn main(-> @Unit) ... {{
  IO.write_file("{tmp_path}", "data")
}}
'''

If tmp_path on Windows is C:\Users\runner\AppData\..., the f-string interpolation drops \U literally into the Vera source. Vera's grammar (correctly) treats \U as an invalid escape because Vera doesn't support Python-style \Uxxxxxxxx 8-hex-digit Unicode escapes — and even if it did, \Use isn't valid hex.

Recommended fix

In the failing test, sanitise the path before embedding it into a Vera string literal:

# Bad on Windows:
source = f'IO.write_file("{tmp_path}", ...)'

# Good everywhere — escape backslashes for the Vera string literal:
sanitised = str(tmp_path).replace('\\', '/')  # forward slashes work cross-platform
source = f'IO.write_file("{sanitised}", ...)'

Or use pathlib.Path.as_posix() which gives forward-slash form on every OS.

Verify scope

This is reported as one test (test_io_read_file_roundtrip), but other IO.write_file / IO.read_file tests should be audited for the same pattern. Grep tests/ for f-strings that embed tmp_path or similar without sanitisation.

Out of scope

  • Adding \U escape support to Vera's grammar. Vera's escape set is intentionally minimal; expanding it is a language-spec decision unrelated to this Windows fix.
  • Generalised path sanitisation in the Vera parser. Vera string literals are opaque to the parser — sanitisation belongs at the test fixture, not in the language.

Acceptance criteria

  • test_io_read_file_roundtrip passes on windows-latest, 3.{11,12,13}.
  • Audit of similar test patterns finds no other latent \U-class failures.

Pairs with

Metadata

Metadata

Assignees

No one assigned

    Labels

    windowsOS-specific to Windows

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions