@@ -2023,14 +2023,24 @@ let comp_pattern_match pat value =
2023
2023
| Some pat' -> pattern_match pat' value
2024
2024
| None -> Ienv.Extension. empty, UF. unused
2025
2025
2026
- let value_of_ident ienv unique_use occ path =
2026
+ (* * Given some [ienv], find the [Value.t] corresponding to an identifier.
2027
+
2028
+ There are two cases that it might be missing, both of which are related to
2029
+ "module and class boundary" (see below):
2030
+ - We are checking inside a module, and the identifier is refering to a value
2031
+ defined outside of the module. In such case, we force this identifier to
2032
+ [aliased].
2033
+ - Another case is used by [open_variables]. See comments there.
2034
+ *)
2035
+ let value_of_ident ienv ?(force_missing = true ) unique_use occ path =
2027
2036
match path with
2028
2037
| Path. Pident id -> (
2029
2038
match Ienv. find_opt id ienv with
2030
2039
(* TODO: for better error message, we should record in ienv why some
2031
2040
variables are not in it. * )
2032
2041
| None ->
2033
- force_aliased_boundary ~reason: Out_of_mod_class unique_use occ;
2042
+ if force_missing
2043
+ then force_aliased_boundary ~reason: Out_of_mod_class unique_use occ;
2034
2044
None
2035
2045
| Some paths ->
2036
2046
let value = Value. existing paths unique_use occ in
@@ -2042,8 +2052,8 @@ let value_of_ident ienv unique_use occ path =
2042
2052
None
2043
2053
| Path. Papply _ | Path. Pextra_ty _ -> assert false
2044
2054
2045
- (* TODO: replace the dirty hack.
2046
- The following functions are dirty hacks and used for modules and classes.
2055
+ (* Module and class boundary
2056
+
2047
2057
Currently we treat the boundary between modules/classes and their surrounding
2048
2058
environment coarsely. To be specific, all references in the modules/classes
2049
2059
pointing to the environment are treated as many and aliased. This translates
@@ -2061,8 +2071,15 @@ let open_variables ienv f =
2061
2071
(fun self e ->
2062
2072
(match e.exp_desc with
2063
2073
| Texp_ident (path , _ , _ , _ , unique_use ) -> (
2074
+ (* We test if a variable is open by looking it up in the current
2075
+ [ienv]: the [ienv] does not contain the internally-bound
2076
+ variables in the module. In other words, open variables will be
2077
+ found, and closed variables will be missing. For the latter, we
2078
+ of course should not force them to [aliased]. *)
2064
2079
let occ = Occurrence. mk e.exp_loc in
2065
- match value_of_ident ienv unique_use occ path with
2080
+ match
2081
+ value_of_ident ienv ~force_missing: false unique_use occ path
2082
+ with
2066
2083
| None -> ()
2067
2084
| Some value -> ll := value :: ! ll)
2068
2085
| _ -> () );
0 commit comments