Skip to content

Nodes inside an f-string hole with escaped quotes carry wrong spans #2270

Closed

Description

@ehartford

Found by the D111 sweep (with check --ceremony-census, which reports each site's line and byte span from the AST node).

test/behavior/behav_1739_generic_struct_literal_collection_field.w line 35:

    print(f"{count_all([\"a\".clone(), \"b\".clone()])} {[1, 2, 3] |> count_all()}")

The two .clone() call nodes inside the hole were reported at line 27, bytes 1021..1032 and 1034..1045, which is text elsewhere in the file. A hole re-parsed after unescaping \" appears to keep offsets relative to the unescaped buffer, not the file.

A diagnostic in a later hole without escapes (f"{\"a\".len()} {nope}") points at the right column, so the shift is confined to nodes inside the hole that contains the escapes.

Expected: every node in a hole maps back to its bytes in the source file (diagnostics, census spans, analyze facts, lldb line info all read these).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced. An error inside a hole after escaped quotes is reported six columns early:

    $ cat main2.w   # line 5
        print(f"{count_all([\"a\", \"b\", undefined_name_2270])}")
    $ with check main2.w
    error: undefined variable
     --> main2.w:5:35
    5 |     print(f"{count_all([\"a\", \"b\", undefined_name_2270])}")
      |                                   ^^^^^^^^^^^^^^^^^^^
    

    The identifier starts at column 41.

    pre-release: a misleading diagnostic location in ordinary code; the fix is mapping hole offsets back through the unescape.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by e3b0ad0 (PR #2663, stack #2668; battery green on the stack top 9f92dbb). The commit message names the root-cause line and the regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions