Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review some typeload code #11832

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions src/typing/typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let find_in_wildcard_imports ctx mname p f =
with Error { err_message = Module_not_found mpath } when mpath = path ->
raise Not_found
in
let r = f m ~resume:true in
let r = f m in
ImportHandling.mark_import_position ctx ppack;
r
with Not_found ->
Expand All @@ -146,48 +146,36 @@ let find_in_wildcard_imports ctx mname p f =
in
loop (ctx.m.import_resolution#extract_wildcard_packages)

(* TODO: move these generic find functions into a separate module *)
let find_in_modules_starting_from_current_package ~resume ctx mname p f =
let find_in_modules_starting_from_current_package ctx mname p f =
let rec loop l =
let path = (List.rev l,mname) in
try
ctx.g.do_load_module ctx path p
with Error { err_message = Module_not_found mpath } when mpath = path ->
match l with
| [] ->
let m =
try
ctx.g.do_load_module ctx path p
with Error { err_message = Module_not_found mpath } when resume && mpath = path ->
raise Not_found
in
f m ~resume:resume
| _ :: sl ->
try
let m =
try
ctx.g.do_load_module ctx path p
with Error { err_message = Module_not_found mpath } when mpath = path ->
raise Not_found
in
f m ~resume:true;
with Not_found ->
| [] ->
raise Not_found
| _ :: sl ->
loop sl
in
let pack = fst ctx.m.curmod.m_path in
loop (List.rev pack)
let m = loop (List.rev pack) in
f m

let find_in_unqualified_modules ctx name p f ~resume =
let find_in_unqualified_modules ctx name p f =
try
find_in_wildcard_imports ctx name p f
with Not_found ->
find_in_modules_starting_from_current_package ctx name p f ~resume:resume
find_in_modules_starting_from_current_package ctx name p f

let load_unqualified_type_def ctx mname tname p =
let find_type m ~resume =
if resume then
find_type_in_module m tname
else
find_type_in_module_raise ctx m tname p
let find_type m =
find_type_in_module_raise ctx m tname p
in
find_in_unqualified_modules ctx mname p find_type ~resume:false
try
find_in_unqualified_modules ctx mname p find_type
with Not_found ->
raise_error_msg (Module_not_found ([],mname)) p

let load_module ctx path p =
try
Expand Down
5 changes: 5 additions & 0 deletions tests/misc/projects/Issue11832/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import a.b.D;

function main() {

}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue11832/a/C.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package a;

class E {}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/a/b/C.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package a.b;
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue11832/a/b/D.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package a.b;

typedef D = C.E;
5 changes: 5 additions & 0 deletions tests/misc/projects/Issue11832/a/b/E.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a.b;

function main() {
C.E;
}
5 changes: 5 additions & 0 deletions tests/misc/projects/Issue11832/a/b/F.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a.b;

import C.E;

function main() {}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--main Main
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a/b/D.hx:3: characters 13-16 : Module a.b.C does not define type E
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/compile2-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--main a.b.E
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/compile2-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a/b/E.hx:4: characters 2-3 : Module a.b.C does not define type C
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/compile3-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--main a.b.F
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11832/compile3-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a/b/F.hx:3: characters 8-9 : Type not found : C
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue4781/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--main p.A
--interp
1 change: 1 addition & 0 deletions tests/misc/projects/Issue4781/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p/A.hx:2: characters 17-20 : Module p.B does not define type T
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue4781/p/A.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package p;
class A extends B.T {
}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue4781/p/B.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package p;
class B {
}
Loading