iter 22b.3.tester: e2e for coherence, default-keyword, cross-module mono
Adds three end-to-end tests for the 22b.3 mono pass, each with a matching one-property fixture under examples/. Defends mono-pass invariants 3, 4, and 6 from docs/specs/2026-05-09-22-typeclasses.md at the binary level (stdout-asserting, not AST-asserting): - coherence_two_instances_pick_correct_body_at_runtime — class R with instances at Int and Bool, both reachable from one main. Stdout `11\n22` proves both mono fns are synthesised AND each call site picks the matching body (no collapse). - class_default_method_runs_and_prints_default_value — empty instance body + class-level `default` clause must lower, link, and print the default value (`99`). Promotes the existing synthesise_mono_fn unit test to a binary-level guarantee. - cross_module_class_method_runs_and_prints_correct_value — class+instance in module A, called from module B's main. The qualified-name rewrite + cross-module synth-def placement was AST-tested in 22b.3.6; this pins down the emit-and-link path. All 18 typeclass_22b3 tests pass; full workspace green; 3 bench gates 0/0/0.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"schema": "ailang/v0",
|
||||
"name": "test_22b3_coherence_two_instances",
|
||||
"imports": [],
|
||||
"defs": [
|
||||
{
|
||||
"kind": "class", "name": "R", "param": "a",
|
||||
"methods": [{
|
||||
"name": "r",
|
||||
"type": {
|
||||
"k": "fn", "params": [{ "k": "var", "name": "a" }],
|
||||
"ret": { "k": "con", "name": "Int" }, "effects": []
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"kind": "instance",
|
||||
"class": "R",
|
||||
"type": { "k": "con", "name": "Int" },
|
||||
"methods": [{
|
||||
"name": "r",
|
||||
"body": {
|
||||
"t": "lam",
|
||||
"params": ["x"],
|
||||
"paramTypes": [{ "k": "var", "name": "a" }],
|
||||
"retType": { "k": "con", "name": "Int" },
|
||||
"body": { "t": "lit", "lit": { "kind": "int", "value": 11 } }
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"kind": "instance",
|
||||
"class": "R",
|
||||
"type": { "k": "con", "name": "Bool" },
|
||||
"methods": [{
|
||||
"name": "r",
|
||||
"body": {
|
||||
"t": "lam",
|
||||
"params": ["b"],
|
||||
"paramTypes": [{ "k": "var", "name": "a" }],
|
||||
"retType": { "k": "con", "name": "Int" },
|
||||
"body": { "t": "lit", "lit": { "kind": "int", "value": 22 } }
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"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": "app",
|
||||
"fn": { "t": "var", "name": "r" },
|
||||
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 0 } }]
|
||||
}]
|
||||
},
|
||||
"rhs": {
|
||||
"t": "do",
|
||||
"op": "io/print_int",
|
||||
"args": [{
|
||||
"t": "app",
|
||||
"fn": { "t": "var", "name": "r" },
|
||||
"args": [{ "t": "lit", "lit": { "kind": "bool", "value": true } }]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"schema": "ailang/v0",
|
||||
"name": "test_22b3_default_e2e",
|
||||
"imports": [],
|
||||
"defs": [
|
||||
{
|
||||
"kind": "class", "name": "D", "param": "a",
|
||||
"methods": [{
|
||||
"name": "dval",
|
||||
"type": {
|
||||
"k": "fn", "params": [{ "k": "var", "name": "a" }],
|
||||
"ret": { "k": "con", "name": "Int" }, "effects": []
|
||||
},
|
||||
"default": {
|
||||
"t": "lam",
|
||||
"params": ["x"],
|
||||
"paramTypes": [{ "k": "var", "name": "a" }],
|
||||
"retType": { "k": "con", "name": "Int" },
|
||||
"body": { "t": "lit", "lit": { "kind": "int", "value": 99 } }
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"kind": "instance",
|
||||
"class": "D",
|
||||
"type": { "k": "con", "name": "Int" },
|
||||
"methods": []
|
||||
},
|
||||
{
|
||||
"kind": "fn",
|
||||
"name": "main",
|
||||
"type": {
|
||||
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
|
||||
"effects": ["IO"]
|
||||
},
|
||||
"params": [],
|
||||
"body": {
|
||||
"t": "do",
|
||||
"op": "io/print_int",
|
||||
"args": [{
|
||||
"t": "app",
|
||||
"fn": { "t": "var", "name": "dval" },
|
||||
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 0 } }]
|
||||
}]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"schema": "ailang/v0",
|
||||
"name": "test_22b3_xmod_e2e_classmod",
|
||||
"imports": [],
|
||||
"defs": [
|
||||
{
|
||||
"kind": "class", "name": "XR", "param": "a",
|
||||
"methods": [{
|
||||
"name": "xr",
|
||||
"type": {
|
||||
"k": "fn", "params": [{ "k": "var", "name": "a" }],
|
||||
"ret": { "k": "con", "name": "Int" }, "effects": []
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"kind": "instance",
|
||||
"class": "XR",
|
||||
"type": { "k": "con", "name": "Int" },
|
||||
"methods": [{
|
||||
"name": "xr",
|
||||
"body": {
|
||||
"t": "lam",
|
||||
"params": ["x"],
|
||||
"paramTypes": [{ "k": "var", "name": "a" }],
|
||||
"retType": { "k": "con", "name": "Int" },
|
||||
"body": { "t": "lit", "lit": { "kind": "int", "value": 7 } }
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"schema": "ailang/v0",
|
||||
"name": "test_22b3_xmod_e2e_main",
|
||||
"imports": [{ "module": "test_22b3_xmod_e2e_classmod" }],
|
||||
"defs": [
|
||||
{
|
||||
"kind": "fn",
|
||||
"name": "main",
|
||||
"type": {
|
||||
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
|
||||
"effects": ["IO"]
|
||||
},
|
||||
"params": [],
|
||||
"body": {
|
||||
"t": "do",
|
||||
"op": "io/print_int",
|
||||
"args": [{
|
||||
"t": "app",
|
||||
"fn": { "t": "var", "name": "xr" },
|
||||
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 0 } }]
|
||||
}]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user