Skip to content

enumerate() over a List[CeremonyEdit] fails to instantiate: std/traits.w:647 None => None return type mismatch, while the same loop over a small list compiles #3077

Closed

Description

@ehartford

In src/CeremonyFix.w (branch fix-ceremony-5, the --check-with option), this loop made with check src/main.w fail inside the standard library:

error: return type mismatch
 --> <embedded-std>/std/traits.w:647:21
647 |             None => None

that is Enumerated.next (impl[T, I: Iter[T]] Iter[(i64, T)] for Enumerated[T, I]) instantiated for edits.enumerate() with edits: List[CeremonyEdit] (type CeremonyEdit { path: str, start: i32, end: i32, replacement: str, what: str }). The loop that triggered it, in run_ceremony_fix (the other two loops in the same function had the same shape):

        let err_path = "out/fix-ceremony-check.err"
        while true:
            let fin = run_to_files([with_str_clone_ref(check_with), "check", with_str_clone_ref(entry)], out_path, err_path, 0)
            if fin.code == 0: break
            var progress = false
            for line in (with_fs_read_file(err_path)).split("\n"):
                if not line.contains("--> "): continue
                let loc = line.split("--> ")[1].split(":")
                if loc.len() < 2: continue
                let epath = loc[0]
                let eline: i32 = loc[1].parse() ?? 0
                // The refusal names a use; the rewrite that caused it is on that
                // line or the nearest rewritten line above it.
                var best = -1
                for (ei, e) in edits.enumerate():
                    if dropped[ei] or e.path != epath: continue
                    if edit_lines[ei] <= eline + 1 and edit_lines[ei] >= eline - 12 and (best < 0 or edit_lines[ei] > edit_lines[best]): best = ei
                if best < 0: continue
                for (ei, e) in edits.enumerate():
                    if not dropped[ei] and e.path == epath and edit_lines[ei] == edit_lines[best]:
                        dropped[ei] = true
                        progress = true
            if not progress:

The same shape as a small program compiles and runs:

type E { path: str, start: i32, what: str }
fn main:
    let edits = [E { path: "a", start: 1, what: "x" }, E { path: "b", start: 2, what: "y" }]
    let lines = [e.start * 10 for e in edits]
    let dropped = [false for e in edits]
    dropped[1] = true
    var kept = 0
    for (ei, e) in edits.enumerate():
        if dropped[ei]:
            kept = kept + 1
            print(f"{e.path}:{lines[ei]}: {e.what}")
    print(f"{kept}")

So the failure depends on something in the compiler's own instantiation context (a (i64, T) tuple instance already present with another T, or T bound as a view of CeremonyEdit). The three loops were rewritten as index loops to land the tool; the branch's history holds the failing version. Route: WITH_TRACE_INST=1 on with check src/main.w with the enumerate loop restored, then with reduce with the std error as the predicate.

Activity

  1. added 2 commits that reference this issue on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions