Skip to content

Commit f82b3d9

Browse files
committed
Refactor: clean up alternateDeclared.
1 parent b21da18 commit f82b3d9

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

analysis/src/References.ml

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ let declaredForExportedTip ~(stamps : stamps) ~(exported : exported) name tip =
185185
Hashtbl.find_opt exported.modules name |?> fun stamp ->
186186
Hashtbl.find_opt stamps.modules stamp |?>> fun x -> {x with item = ()}
187187

188+
(** Find alternative declaration: from res in case of interface, or from resi in case of implementation *)
188189
let alternateDeclared ~(file : File.t) ~package declared tip =
189190
match Hashtbl.find_opt package.pathsForModule file.moduleName with
190191
| None -> None
@@ -193,28 +194,16 @@ let alternateDeclared ~(file : File.t) ~package declared tip =
193194
match paths with
194195
| IntfAndImpl {resi; res} -> (
195196
maybeLog "Have both!!";
196-
let resiUri = Uri2.fromPath resi in
197-
let resUri = Uri2.fromPath res in
198-
if Uri2.isInterface file.uri then
199-
match Cmt.fromUri ~uri:resUri with
200-
| None -> None
201-
| Some {file; extra} -> (
202-
match
203-
declaredForExportedTip ~stamps:file.stamps
204-
~exported:file.contents.exported declared.name.txt tip
205-
with
206-
| None -> None
207-
| Some declared -> Some (file, extra, declared))
208-
else
209-
match Cmt.fromUri ~uri:resiUri with
197+
let alternateUri = if Uri2.isInterface file.uri then res else resi in
198+
match Cmt.fromUri ~uri:(Uri2.fromPath alternateUri) with
199+
| None -> None
200+
| Some {file; extra} -> (
201+
match
202+
declaredForExportedTip ~stamps:file.stamps
203+
~exported:file.contents.exported declared.name.txt tip
204+
with
210205
| None -> None
211-
| Some {file; extra} -> (
212-
match
213-
declaredForExportedTip ~stamps:file.stamps
214-
~exported:file.contents.exported declared.name.txt tip
215-
with
216-
| None -> None
217-
| Some declared -> Some (file, extra, declared)))
206+
| Some declared -> Some (file, extra, declared)))
218207
| _ -> None)
219208

220209
let rec resolveModuleReference ?(pathsSeen = []) ~file ~package

0 commit comments

Comments
 (0)