Commit 34e0e2f
feat(typecheck): String relational ops (<, >, <=, >=) (closes #458)
Adds a `TCon "String"` case to the comparison branch in
`Typecheck.synth_expr`'s `ExprBinary` handler, alongside the existing
Int and Float dispatches. Lex-compare semantics — JS's native string
comparison gives byte-wise lexicographic order out of the box, so the
JS-family backends (codegen_deno, js_codegen) need no change: the
existing `<` / `>` / `<=` / `>=` op emission already does the right
thing once typecheck stops rejecting String operands.
Pre-fix, `let _ = "a" < "b"` raised `TypeMismatch (String, Int)`,
forcing downstream ports (e.g. standards#284's `check-ts-allowlist`
port) to inline byte-wise `str_lt` helpers using
`char_to_int(string_get(...))` at every use site.
Regression fixture `tests/codegen-deno/string_lex_cmp.affine` +
harness exercise 22 assertions covering all four ops (functional
form + literal form), equal-string corner cases (<, <=, >= behaviour
all three directions), empty strings, and prefix-relations.
Non-ASCII string comparison is naturally exercised once #463 (the
companion Unicode-escape codegen fix for #460) lands — until then,
this fixture stays ASCII-only so it doesn't inherit the octal-escape
ESM SyntaxError. The relational typecheck is orthogonal to the
literal encoding; both ship together once both PRs are in.
Verified: `tools/run_codegen_deno_tests.sh` (14/14 harnesses green);
`dune test` (352/352 green).
Closes #458
Refs hyperpolymath/standards#284 (the seam-analyst PR that surfaced
this — `str_lt` workaround)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 4ae169d commit 34e0e2f
3 files changed
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1024 | 1024 | | |
1025 | 1025 | | |
1026 | 1026 | | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1027 | 1033 | | |
1028 | 1034 | | |
1029 | 1035 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments