mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
fix tests
This commit is contained in:
parent
19c6bf4078
commit
f20e945cb9
2 changed files with 36 additions and 8 deletions
|
|
@ -28,6 +28,8 @@ fn parseCheckAndEvalModule(src: []const u8) !struct {
|
|||
evaluator: ComptimeEvaluator,
|
||||
problems: *check.problem.Store,
|
||||
builtin_module: builtin_loading.LoadedModule,
|
||||
checker: *Check,
|
||||
imported_envs: []*const ModuleEnv,
|
||||
} {
|
||||
const gpa = test_allocator;
|
||||
|
||||
|
|
@ -60,18 +62,36 @@ fn parseCheckAndEvalModule(src: []const u8) !struct {
|
|||
.builtin_indices = builtin_indices,
|
||||
};
|
||||
|
||||
var czer = try Can.init(module_env, &parse_ast, null);
|
||||
// Create module_envs map for canonicalization (enables qualified calls to List, Str, etc.)
|
||||
var module_envs_map = std.AutoHashMap(base.Ident.Idx, Can.AutoImportedType).init(gpa);
|
||||
defer module_envs_map.deinit();
|
||||
|
||||
// Use shared function to populate ALL builtin types - ensures Builtin.roc is single source of truth
|
||||
try Can.populateModuleEnvs(
|
||||
&module_envs_map,
|
||||
module_env,
|
||||
builtin_module.env,
|
||||
builtin_indices,
|
||||
);
|
||||
|
||||
var czer = try Can.init(module_env, &parse_ast, &module_envs_map);
|
||||
defer czer.deinit();
|
||||
|
||||
try czer.canonicalizeFile();
|
||||
|
||||
const imported_envs = [_]*const ModuleEnv{builtin_module.env};
|
||||
// Heap-allocate imported_envs so it outlives this function.
|
||||
// The interpreter's all_module_envs is a slice that points to this memory.
|
||||
const imported_envs = try gpa.alloc(*const ModuleEnv, 1);
|
||||
errdefer gpa.free(imported_envs);
|
||||
imported_envs[0] = builtin_module.env;
|
||||
|
||||
// Resolve imports - map each import to its index in imported_envs
|
||||
module_env.imports.resolveImports(module_env, &imported_envs);
|
||||
module_env.imports.resolveImports(module_env, imported_envs);
|
||||
|
||||
var checker = try Check.init(gpa, &module_env.types, module_env, &imported_envs, null, &module_env.store.regions, builtin_ctx);
|
||||
defer checker.deinit();
|
||||
const checker = try gpa.create(Check);
|
||||
errdefer gpa.destroy(checker);
|
||||
checker.* = try Check.init(gpa, &module_env.types, module_env, imported_envs, null, &module_env.store.regions, builtin_ctx);
|
||||
errdefer checker.deinit();
|
||||
|
||||
try checker.checkFile();
|
||||
|
||||
|
|
@ -79,13 +99,15 @@ fn parseCheckAndEvalModule(src: []const u8) !struct {
|
|||
problems.* = .{};
|
||||
|
||||
const builtin_types = BuiltinTypes.init(builtin_indices, builtin_module.env, builtin_module.env, builtin_module.env);
|
||||
const evaluator = try ComptimeEvaluator.init(gpa, module_env, &.{}, problems, builtin_types, null, &checker.import_mapping);
|
||||
const evaluator = try ComptimeEvaluator.init(gpa, module_env, imported_envs, problems, builtin_types, builtin_module.env, &checker.import_mapping);
|
||||
|
||||
return .{
|
||||
.module_env = module_env,
|
||||
.evaluator = evaluator,
|
||||
.problems = problems,
|
||||
.builtin_module = builtin_module,
|
||||
.checker = checker,
|
||||
.imported_envs = imported_envs,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -93,12 +115,18 @@ fn cleanupEvalModule(result: anytype) void {
|
|||
var evaluator_mut = result.evaluator;
|
||||
evaluator_mut.deinit();
|
||||
|
||||
var checker_mut = result.checker;
|
||||
checker_mut.deinit();
|
||||
test_allocator.destroy(result.checker);
|
||||
|
||||
var problems_mut = result.problems;
|
||||
problems_mut.deinit(test_allocator);
|
||||
test_allocator.destroy(result.problems);
|
||||
result.module_env.deinit();
|
||||
test_allocator.destroy(result.module_env);
|
||||
|
||||
test_allocator.free(result.imported_envs);
|
||||
|
||||
var builtin_module_mut = result.builtin_module;
|
||||
builtin_module_mut.deinit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ type=repl
|
|||
» foo("test")
|
||||
~~~
|
||||
# OUTPUT
|
||||
Crash: runtime error
|
||||
Crash: Compile-time error encountered at runtime
|
||||
---
|
||||
Evaluation error: error.TypeMismatch
|
||||
Crash: Cannot call function: compile-time error in function definition
|
||||
# PROBLEMS
|
||||
NIL
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue