ocaml: phase 4 'let open M in body' local opens (+3 tests, 478 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

Parser detects 'let open' as a separate let-form, parses M as a path
(Ctor(.Ctor)*) directly via inline AST construction (no source slicing
since cur-pos is only available in ocaml-parse-program), and emits
(:let-open PATH BODY).

Eval resolves the path to a module dict and merges its bindings into
the env for body evaluation. Now:

  let open List in map (fun x -> x * 2) [1;2;3]   = [2;4;6]
  let open Option in map (fun x -> x + 1) (Some 5) = Some 6
This commit is contained in:
2026-05-08 21:33:14 +00:00
parent 0530120bc7
commit 6dc535dde3
4 changed files with 59 additions and 1 deletions

View File

@@ -697,6 +697,14 @@
(fill (rest xs)))))))))
(fill bindings)
(ocaml-eval body env2))))))
((= tag "let-open")
;; `let open M in body` — extend env with M's bindings, eval body.
(let ((path-expr (nth ast 1)) (body (nth ast 2)))
(let ((mod-val (ocaml-resolve-module-path path-expr env)))
(cond
((dict? mod-val)
(ocaml-eval body (ocaml-env-merge-dict env mod-val)))
(else (error (str "ocaml-eval: let open on non-module: " mod-val)))))))
((= tag "let-rec")
;; Tie the knot via a mutable cell when rhs is function-typed.
;; The placeholder closure dereferences the cell on each call.