iter ct.2.2: Pattern::Ctor type-driven lookup; delete imports-fallback
This commit is contained in:
@@ -1,55 +1,29 @@
|
||||
//! Bug regression: the workspace-monomorphisation pass must not mis-resolve
|
||||
//! Regression: the workspace-monomorphisation pass must not mis-resolve
|
||||
//! a cross-module constructor pattern. The mono pass re-runs `synth` on
|
||||
//! every fn body to recover residual class constraints; that env is built
|
||||
//! by `mono::build_workspace_env`, which delegates to `crate::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).
|
||||
//! and produces a workspace-flat `ctor_index` and `types` map.
|
||||
//!
|
||||
//! In contrast, `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
|
||||
//! (lib.rs:2486-2521) can keep the qualified-type-name comparison at
|
||||
//! lib.rs:2526 intact: the imports-fallback branch produces a qualified
|
||||
//! `resolved_type_name` (`Mod.Type`), the local-hit branch produces a bare
|
||||
//! one (`Type`).
|
||||
//! Post-ct.2, `Pattern::Ctor` lookup is type-driven — it consults the
|
||||
//! scrutinee's canonical `Type::Con.name` to find the TypeDef directly
|
||||
//! in `env.module_types`, then validates the ctor name within it. The
|
||||
//! mono pass's flat `ctor_index` is no longer consulted by this path;
|
||||
//! the per-module overlay (lib.rs:1247-1258) is now decorative for the
|
||||
//! pattern path and remains only for duplicate-type / duplicate-ctor
|
||||
//! detection at the workspace-build prologue.
|
||||
//!
|
||||
//! The mono pass never does the per-module overlay. So when a body in
|
||||
//! module B pattern-matches a constructor `C` whose Def::Type lives in
|
||||
//! imported module A, the workspace-flat ctor_index resolves `C` locally
|
||||
//! (in fact: anywhere in the workspace) and yields the bare type name
|
||||
//! `"Type"`. The scrutinee, however, was typed by the main pass against
|
||||
//! the qualified name `"A.Type"` (per the imports-fallback path), so the
|
||||
//! comparison
|
||||
//!
|
||||
//! ```ignore
|
||||
//! Type::Con { name, args } if name == &resolved_type_name => args.clone(),
|
||||
//! _ => return Err(CheckError::PatternTypeMismatch { ... }),
|
||||
//! ```
|
||||
//!
|
||||
//! at lib.rs:2526 fails with `cannot match constructor pattern C against
|
||||
//! type A.Type<...>`.
|
||||
//!
|
||||
//! 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
|
||||
//! pattern-match resolution).
|
||||
//! This test pins the cross-module pattern shape against a minimal
|
||||
//! 2-module fixture (`test_mono_ctor_main` + `test_mono_ctor_listmod`).
|
||||
//! Pre-ct.2 the bug surfaced as `PatternTypeMismatch { ctor: "Cons",
|
||||
//! ty: "test_mono_ctor_listmod.List<Int>" }` because the mono env
|
||||
//! resolved `Cons` to bare `List` via the flat index. Post-ct.2 the
|
||||
//! lookup is type-driven and `expected.name == "test_mono_ctor_listmod.List"`
|
||||
//! directly indexes the right TypeDef.
|
||||
//!
|
||||
//! Surfaced by iter 23.2 Task 3, which adds `class Eq a` + Eq Int/Bool/Str
|
||||
//! instances to `examples/prelude.ail.json`. Before Task 3 the prelude has
|
||||
//! only `Def::Type Ordering`, 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.
|
||||
//!
|
||||
//! Without the prelude change, two pre-existing E2E tests already
|
||||
//! exercise the bug shape (`nested_ctor_pattern_first_two_sum`,
|
||||
//! `std_either_list_demo`) and silently pass because the mono pass is a
|
||||
//! no-op on a class-free workspace. This test pins the inner cause
|
||||
//! against a minimal 2-module fixture so it stays RED regardless of the
|
||||
//! prelude's typeclass content.
|
||||
//! instances to `examples/prelude.ail.json`, flipping the
|
||||
//! `workspace_has_typeclasses` gate so every workspace exercises the
|
||||
//! mono pass.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user