Repository navigation
fix(test): imported modules' top-level lets evaluate in their own scope under ailang test - #2629
Merged
Conversation
…pe under ailang test An imported module's top-level value binding that referred to another one by bare name (`let alias = plain`, or a std/array + std/list chain) was left unbound under `ailang test`: the harness evaluated value lets in the shared environment, where only the module under test's bare names exist, and dropped the error. Tests failed with "undefined variable: table" while `ailang run` printed the right answer. newHarnessEvaluator now evaluates them as runtime.extractBindings does for `ailang run`: declaration order, inside the module's own scope, imported modules first, and the first error is returned (same message as run) to every harness path instead of being swallowed. The harness's three pipeline compiles now use ModeCheck, as `run` does for a module file. ModeEval also evaluated the root's first declaration on a throwaway evaluator whose builtins had no resolver; a root value let built from an imported one never finished. The Executor's builtin-only resolver existed only for that evaluation and is removed. Tests: TestImportedTopLevelLetChain (evaluator + bytecode), TestRootTopLevelLetChain, TestTopLevelLetErrorSurfaces, fixtures in internal/testing/testdata/toplevel_let. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sunholo-voight-kampff
deleted the
fix/test-harness-imported-toplevel-let
branch
December 2, 2026 16:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
An imported module's top-level value binding that refers to another one by bare name is left unbound under
ailang test, whileailang runevaluates it correctly:let alias = plainis enough to trigger it. The same pattern in the module under test passes.--bytecodepasses. Inline tests fail the same way (harness evaluation failed: undefined variable: table).Root cause
newHarnessEvaluator(internal/testing/module_scope.go) builds module environments by hand. It evaluated every module's valuelets withevaluator.Evalin the shared environment. Only the module under test's bare names exist there, sobasein an imported module did not resolve. The error was then dropped (if val, err := …; err == nil && val != nil), sotablewas never bound and the failure showed up later as a different error.A second, related problem: the harness compiled in
pipeline.ModeEval(the REPL mode).ailang runusesModeCheckfor a module file. ModeEval also evaluated the root module's first declaration on a throwaway evaluator whose builtins were bound to an evaluator with no resolver, and nothing used the value. With a root valueletbuilt from an imported one (let doubled = map(\x. x * 2, tableOf())), the compile never finished. A goroutine dump shows unbounded evaluation insidepipeline.Run, and the run was killed after 15 s on origin/dev.ailang runon the same program prints[10, 14].Fix
runtime.extractBindingsdoes forrun:LoadedModule.Imports);failed to evaluate let bad in module broken: RT001: integer division by zero at broken.ail:8:14.newHarnessEvaluatornow returns an error. All 8 call sites propagate it: named batched, named per-body, properties, inline harness, cluster harness, expected-value rows, ensures harness, and the VM bridge. Nothing is swallowed.ModeCheck. The Executor's builtin-onlyglobalResolveronly fed ModeEval's discarded evaluation, so it is removed.Not the one-path refactor. Routing the harness through
runtime.ModuleRuntimewould mean:CombinedResolverfor the module resolver;inst.Bindingsinstead of the shared env.That is too large for a release-candidate fix. This PR copies run's evaluation rules into the one place the harness evaluates values and aligns the compile mode.
Audit of the rest of
module_scope.go:CombinedResolver.LetRecbinding is skipped, and using it fails loudly withRT_REC_002.bindModuleCtor/injectADTConstructorssilently skip missing constructors. That is optional scope setup, not a value.Tests
Fixtures are in
internal/testing/testdata/toplevel_let.TestImportedTopLevelLetChain/{evaluator,bytecode}: the imported std/array + std/list chain and thealiascase. The root modulea_testsorts beforezdepand builds its own value let from zdep's, which covers dependency order and the ModeEval hang. 3 named tests + 1 inline row.TestRootTopLevelLetChain: the same chain in the module under test.TestTopLevelLetErrorSurfaces:let bad = 10 / zeroin an imported module fails the test with the binding's own error, the messageailang runprints, and not "undefined variable".Mutation testing (scratch backup, mutate, run, restore; diff verified unchanged after each):
TestImportedTopLevelLetChain(both engines),TestTopLevelLetErrorSurfacesTestTopLevelLetErrorSurfacesTestImportedTopLevelLetChain(both engines)ModeEvalagain in the harness compilesCorpus check: I ran every
.ailfile with tests underexamples/,tests/andstd/(88 files) throughailang test --jsonwith the origin/dev binary and with this branch, and compared pass/fail/skip counts. 0 differences, 1,365 passing tests.Gates: all clean.
make test-changed,make test-coremake lint(0 issues)make check-file-sizes,make verify-examples,make check-changeloggo test ./cmd/ailang -run 'Test.*(Test|Named|Bytecode|Inline|Propert)'Already fixed at HEAD: the stapledons_godot callback-resolver reports (no change needed)
These reports, pinned to v0.52.0, were the reason for the investigation. Each symptom reproduces on a v0.52.0 build and passes on origin/dev, with the stdlib path pinned for both binaries:
$builtin.not_Boolunresolved in astd/list.anycallback of an imported helperstd/array.getunresolved in amapcallbackfoldlcallback (path dependency + lock)RecordUpdate)The per-body fallback path was also checked by forcing a batch failure with a reserved
__namedtest_*name. It passes for r1–r3. All four fixtures still pass on this branch under both engines.🤖 Generated with Claude Code
Fixes #2619