e580f75adf
`monomorphise_workspace` re-runs `synth` on every fn body to recover
residual class constraints; the env it uses is built by
`mono::build_workspace_env`, which delegates to `build_check_env` and
produces a workspace-flat `ctor_index` (every Def::Type ctor across
every module, keyed by bare ctor name → bare type name).
`check_in_workspace` (lib.rs:1247-1258) explicitly clears that flat
index after `build_check_env` and rebuilds it per-module so that
`Pattern::Ctor`'s local-first / imports-fallback resolution at
lib.rs:2486-2521 keeps the qualified-type-name comparison at
lib.rs:2526 intact: imports-fallback yields a qualified
`resolved_type_name` (`Mod.Type`), local-hit yields a bare one.
The mono pass never does the per-module overlay, so when a body in
module B pattern-matches a ctor `C` whose Def::Type lives in imported
module A, the workspace-flat index resolves `C` locally and yields the
bare type name. The scrutinee, however, was typed against the
qualified name, and the comparison fails with
`PatternTypeMismatch { ctor: "Cons", ty: "A.Type<...>" }`.
Surfaced by iter 23.2 Task 3, which adds `class Eq a` + Eq Int/Bool/Str
instances to the prelude. Pre-Task-3 the prelude is class-free, so
`workspace_has_typeclasses(ws) == false` and the mono pass early-outs
at `mono.rs:73`. Task 3 flips the gate; every workspace now traverses
bodies, which brings the latent bug to the surface for the
pre-existing `nested_ctor_pattern_first_two_sum` and
`std_either_list_demo` E2E tests.
Sibling regressions in the same family: `mono_xmod_qualified_ref.rs`
(env.imports not seeded), commit 13b36cc (env.globals not seeded for
self-recursive fns), commit 5c5180f (env.types / env.ctor_index not
seeded for user ADTs — the original "flat ctor_index" decision that
this bug now exposes as wrong-by-construction for cross-module ctor
pattern resolution).
The minimal fixture is two modules with five defs total:
test_mono_ctor_listmod (data List a = Nil | Cons a (List a)) and
test_mono_ctor_main (class Trivial a + instance Trivial Int + a fn
that pattern-matches Cons against the imported List<Int> + a main).
The test pins the inner cause: matches against the specific
`CheckError::PatternTypeMismatch` variant with the qualified
scrutinee type and bare ctor name, so it stays RED regardless of the
prelude's typeclass content.
117 lines
3.0 KiB
JSON
117 lines
3.0 KiB
JSON
{
|
|
"schema": "ailang/v0",
|
|
"name": "test_mono_ctor_main",
|
|
"imports": [{ "module": "test_mono_ctor_listmod" }],
|
|
"defs": [
|
|
{
|
|
"kind": "class",
|
|
"name": "Trivial",
|
|
"param": "a",
|
|
"methods": [
|
|
{
|
|
"name": "trivial",
|
|
"type": {
|
|
"k": "fn",
|
|
"params": [{ "k": "var", "name": "a" }],
|
|
"ret": { "k": "con", "name": "Int" },
|
|
"effects": []
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Trivial",
|
|
"type": { "k": "con", "name": "Int" },
|
|
"methods": [
|
|
{
|
|
"name": "trivial",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x"],
|
|
"paramTypes": [{ "k": "con", "name": "Int" }],
|
|
"retType": { "k": "con", "name": "Int" },
|
|
"body": { "t": "var", "name": "x" }
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "head_or_zero",
|
|
"doc": "Pattern-matches Cons from an imported module's List<Int>. Bug repro: with a class+instance present in the workspace, the mono pass walks this body and synth's local-flat ctor_index resolves Cons to bare \"List\", which mismatches the qualified scrutinee type \"test_mono_ctor_listmod.List<Int>\".",
|
|
"type": {
|
|
"k": "fn",
|
|
"params": [
|
|
{
|
|
"k": "con",
|
|
"name": "test_mono_ctor_listmod.List",
|
|
"args": [{ "k": "con", "name": "Int" }]
|
|
}
|
|
],
|
|
"ret": { "k": "con", "name": "Int" },
|
|
"effects": []
|
|
},
|
|
"params": ["xs"],
|
|
"body": {
|
|
"t": "match",
|
|
"scrutinee": { "t": "var", "name": "xs" },
|
|
"arms": [
|
|
{
|
|
"pat": {
|
|
"p": "ctor",
|
|
"ctor": "Cons",
|
|
"fields": [
|
|
{ "p": "var", "name": "h" },
|
|
{ "p": "wild" }
|
|
]
|
|
},
|
|
"body": { "t": "var", "name": "h" }
|
|
},
|
|
{
|
|
"pat": { "p": "ctor", "ctor": "Nil", "fields": [] },
|
|
"body": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"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": "head_or_zero" },
|
|
"args": [
|
|
{
|
|
"t": "ctor",
|
|
"ctor": "Cons",
|
|
"type": "test_mono_ctor_listmod.List",
|
|
"args": [
|
|
{ "t": "lit", "lit": { "kind": "int", "value": 7 } },
|
|
{
|
|
"t": "ctor",
|
|
"ctor": "Nil",
|
|
"type": "test_mono_ctor_listmod.List",
|
|
"args": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|