From eedd1357b54cf9acf37f1740d3013d918f83fbcf Mon Sep 17 00:00:00 2001 From: hyperpolymath <6759885+hyperpolymath@users.noreply.github.com> Date: Sun, 14 Jun 2026 04:49:22 +0100 Subject: [PATCH] fix(echo): patch two exhaustiveness gaps + extend TG-4 round-trip corpus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two warnings-as-errors surfaced when compiling the echo/product additions for the first time on a real OCaml toolchain: compiler/lib/typecheck.ml — `strand_type_of_ty` had no arms for TProd/TEcho. compiler/bin/main.ml — the debug token printer had no arms for the 8 new echo keyword tokens (ECHOCLOSE LOWER RESIDUE PAIR FST SND ECHOADD ECHOEQ). Both are straightforward exhaustiveness gaps; the design is preserved. Both get StrandDefault / print_string "" mirroring the nearest neighbouring cases. Also extend the TG-4 round-trip corpus in test_roundtrip.ml with one entry per new echo constructor (echoClose, lower, residue, pair, fst, snd, echoAdd, echoEq) so the parse/pretty/parse round-trip guarantee is explicitly exercised for every form added by this PR. Before: dune build fails; 532 tests (not reached) After: dune build succeeds; 548/548 tests pass (16 new TG-4 entries) --- compiler/bin/main.ml | 10 +++++++++- compiler/lib/typecheck.ml | 2 ++ compiler/test/test_roundtrip.ml | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/bin/main.ml b/compiler/bin/main.ml index 801f333..0212752 100644 --- a/compiler/bin/main.ml +++ b/compiler/bin/main.ml @@ -167,7 +167,15 @@ let dump_tokens (filename : string) : unit = | STRING s -> Printf.printf "STRING(%S)" s | IDENT s -> Printf.printf "IDENT(%s)" s | GENERATOR n -> Printf.printf "GENERATOR(%d)" n - | EOF -> print_string "EOF"); + | EOF -> print_string "EOF" + | ECHOCLOSE -> print_string "ECHOCLOSE" + | LOWER -> print_string "LOWER" + | RESIDUE -> print_string "RESIDUE" + | PAIR -> print_string "PAIR" + | FST -> print_string "FST" + | SND -> print_string "SND" + | ECHOADD -> print_string "ECHOADD" + | ECHOEQ -> print_string "ECHOEQ"); print_newline (); if tok <> EOF then loop () in diff --git a/compiler/lib/typecheck.ml b/compiler/lib/typecheck.ml index 204d7d7..721607f 100644 --- a/compiler/lib/typecheck.ml +++ b/compiler/lib/typecheck.ml @@ -584,6 +584,8 @@ and strand_type_of_ty (t : ty) : strand_type = | TBool -> StrandNamed "Bool" | TWord _ -> StrandDefault | TTangle _ -> StrandDefault + | TProd _ -> StrandDefault + | TEcho _ -> StrandDefault (** Convert a strand_type to a boundary element for self-crossing. *) and strand_to_type (st : strand_type) : strand_type = st diff --git a/compiler/test/test_roundtrip.ml b/compiler/test/test_roundtrip.ml index d6d3fe7..6ecb92e 100644 --- a/compiler/test/test_roundtrip.ml +++ b/compiler/test/test_roundtrip.ml @@ -100,6 +100,15 @@ let basic_corpus : (string * string) list = [ ("nullary def", "def x = identity"); ("unary def", "def f(a) = a"); ("binary def", "def f(a, b) = a + b"); + (* Echo / structured-loss forms (PR #45) *) + ("echoClose", "def x = echoClose(a)"); + ("lower", "def x = lower(a)"); + ("residue", "def x = residue(a)"); + ("pair", "def x = pair(a, b)"); + ("fst", "def x = fst(a)"); + ("snd", "def x = snd(a)"); + ("echoAdd", "def x = echoAdd(a, b)"); + ("echoEq", "def x = echoEq(a, b)"); ] (* --------------------------------------------------------------------- *)