From ba4834905211f382657a202f11e66b09f2a33308 Mon Sep 17 00:00:00 2001 From: Brummel Date: Mon, 11 May 2026 10:09:48 +0200 Subject: [PATCH] iter ct.4.4: compare_primitives_smoke E2E fixture (closes iter 23.3 Task 4) --- crates/ail/tests/e2e.rs | 19 ++ examples/compare_primitives_smoke.ail.json | 249 +++++++++++++++++++++ 2 files changed, 268 insertions(+) create mode 100644 examples/compare_primitives_smoke.ail.json diff --git a/crates/ail/tests/e2e.rs b/crates/ail/tests/e2e.rs index 5dce9bb..ebd66eb 100644 --- a/crates/ail/tests/e2e.rs +++ b/crates/ail/tests/e2e.rs @@ -908,6 +908,25 @@ fn ordering_match_via_prelude_prints_1() { assert_eq!(stdout, "1\n"); } +/// Iter 23.3 Task 4 (resumed in ct.4): the end-to-end +/// demonstration that the iter-23.1 cross-module Type::Con +/// mismatch bug is closed. `examples/compare_primitives_smoke.ail.json` +/// imports prelude, calls `compare` on three pairs each of +/// Int / Bool / Str (arranged LT / EQ / GT per type), and +/// pattern-matches the result. Expected stdout encodes the +/// 9-case decision lattice as `1\n2\n3` × 3. +/// +/// Pre-canonical-type-names, the bare `Ordering` returned by +/// `compare` mismatched the qualified `prelude.Ordering` +/// scrutinee at the user-side pattern lookup. Post-milestone, +/// the scrutinee is qualified throughout, the pattern lookup +/// is type-driven, and the run completes cleanly. +#[test] +fn compare_primitives_smoke_prints_1_2_3_thrice() { + let stdout = build_and_run("compare_primitives_smoke.ail.json"); + assert_eq!(stdout, "1\n2\n3\n1\n2\n3\n1\n2\n3\n"); +} + /// Iter 23.2: end-to-end coverage for the auto-loaded `Eq` class /// + three primitive instances. The fixture calls `eq` on Int / /// Bool / Str with both an equal and an unequal pair each; the diff --git a/examples/compare_primitives_smoke.ail.json b/examples/compare_primitives_smoke.ail.json new file mode 100644 index 0000000..fd2b410 --- /dev/null +++ b/examples/compare_primitives_smoke.ail.json @@ -0,0 +1,249 @@ +{ + "schema": "ailang/v0", + "name": "compare_primitives_smoke", + "imports": [], + "defs": [ + { + "kind": "fn", + "name": "main", + "type": { + "k": "fn", + "params": [], + "ret": { "k": "con", "name": "Unit" }, + "effects": ["IO"] + }, + "params": [], + "body": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "int", "value": 1 } }, + { "t": "lit", "lit": { "kind": "int", "value": 2 } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "int", "value": 1 } }, + { "t": "lit", "lit": { "kind": "int", "value": 1 } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "int", "value": 2 } }, + { "t": "lit", "lit": { "kind": "int", "value": 1 } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "bool", "value": false } }, + { "t": "lit", "lit": { "kind": "bool", "value": true } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "bool", "value": false } }, + { "t": "lit", "lit": { "kind": "bool", "value": false } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "bool", "value": true } }, + { "t": "lit", "lit": { "kind": "bool", "value": false } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "str", "value": "a" } }, + { "t": "lit", "lit": { "kind": "str", "value": "b" } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "seq", + "lhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "str", "value": "a" } }, + { "t": "lit", "lit": { "kind": "str", "value": "a" } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + }, + "rhs": { + "t": "do", + "op": "io/print_int", + "args": [{ + "t": "match", + "scrutinee": { + "t": "app", + "fn": { "t": "var", "name": "compare" }, + "args": [ + { "t": "lit", "lit": { "kind": "str", "value": "b" } }, + { "t": "lit", "lit": { "kind": "str", "value": "a" } } + ] + }, + "arms": [ + { "pat": { "p": "ctor", "ctor": "LT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 1 } } }, + { "pat": { "p": "ctor", "ctor": "EQ", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 2 } } }, + { "pat": { "p": "ctor", "ctor": "GT", "fields": [] }, + "body": { "t": "lit", "lit": { "kind": "int", "value": 3 } } } + ] + }] + } + } + } + } + } + } + } + } + } + } + ] +}