Skip to content

Commit

Permalink
Fix visibility of module patterns (#140)
Browse files Browse the repository at this point in the history
Fixes #138.
  • Loading branch information
forell authored Jul 20, 2024
1 parent 776a356 commit bb82204
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/DblParser/Desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ let rec tr_pattern ~public (p : Raw.expr) =
let ps = List.map (tr_pattern ~public) ps in
begin match flds with
| [ { data = FldModule name; _ } ] ->
make (PCtor(cpath, CNModule name, ps))
make (PCtor(cpath, CNModule(public, name), ps))
| _ ->
let (targs, iargs) = map_inst_like (tr_named_pattern ~public) flds in
make (PCtor(cpath, CNParams(targs, iargs), ps))
Expand Down
2 changes: 1 addition & 1 deletion src/Lang/Surface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ and pattern_data =
and ctor_pattern_named =
| CNParams of named_type_arg list * named_pattern list
(** Named type parameters and named patterns of a constructor *)
| CNModule of module_name
| CNModule of is_public * module_name
(** Bind all named parameters under the specified module name *)

(** Pattern for named parameter *)
Expand Down
4 changes: 2 additions & 2 deletions src/TypeInference/Pattern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ let rec check_ctor_named ~pos ~env ~scope
let (env, bn1, ps1) =
check_ctor_named_args ~pos ~env ~scope nps ctor_named in
(env, scope, sub2, tvars, ps1, bn1)
| S.CNModule modname ->
| S.CNModule(public, modname) ->
(* TODO: This may seem inconsistent with the other case as implicits aren't
introduced to the current namespace, just the provided module name. *)
let env = Env.enter_module env in
let (env, tvars, ps1, sub2) =
open_named ~pos ~public:true env ctor.ctor_targs ctor.ctor_named in
let env = Env.leave_module env ~public:false modname in
let env = Env.leave_module env ~public modname in
(env, Env.scope env, sub2, tvars, ps1, T.Name.Map.empty)

and check_ctor_named_args ~pos ~env ~scope nps named =
Expand Down
6 changes: 6 additions & 0 deletions test/ok/ok0110_publicModulePattern.fram
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module M
data T = C of { x : Int }
pub let C { module N } = C { x = 42 }
end

let x = M.N.x

0 comments on commit bb82204

Please sign in to comment.