Jelajahi Sumber

Review some typeload code (#11832)

* delete some code and see what breaks

* move Not_found catch to the right place

* add test

* add more tests
Simon Krajewski 9 bulan lalu
induk
melakukan
50de739adc

+ 18 - 30
src/typing/typeload.ml

@@ -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 ->
@@ -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

+ 5 - 0
tests/misc/projects/Issue11832/Main.hx

@@ -0,0 +1,5 @@
+import a.b.D;
+
+function main() {
+
+}

+ 3 - 0
tests/misc/projects/Issue11832/a/C.hx

@@ -0,0 +1,3 @@
+package a;
+
+class E {}

+ 1 - 0
tests/misc/projects/Issue11832/a/b/C.hx

@@ -0,0 +1 @@
+package a.b;

+ 3 - 0
tests/misc/projects/Issue11832/a/b/D.hx

@@ -0,0 +1,3 @@
+package a.b;
+
+typedef D = C.E;

+ 5 - 0
tests/misc/projects/Issue11832/a/b/E.hx

@@ -0,0 +1,5 @@
+package a.b;
+
+function main() {
+	C.E;
+}

+ 5 - 0
tests/misc/projects/Issue11832/a/b/F.hx

@@ -0,0 +1,5 @@
+package a.b;
+
+import C.E;
+
+function main() {}

+ 1 - 0
tests/misc/projects/Issue11832/compile-fail.hxml

@@ -0,0 +1 @@
+--main Main

+ 1 - 0
tests/misc/projects/Issue11832/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+a/b/D.hx:3: characters 13-16 : Module a.b.C does not define type E

+ 1 - 0
tests/misc/projects/Issue11832/compile2-fail.hxml

@@ -0,0 +1 @@
+--main a.b.E

+ 1 - 0
tests/misc/projects/Issue11832/compile2-fail.hxml.stderr

@@ -0,0 +1 @@
+a/b/E.hx:4: characters 2-3 : Module a.b.C does not define type C

+ 1 - 0
tests/misc/projects/Issue11832/compile3-fail.hxml

@@ -0,0 +1 @@
+--main a.b.F

+ 1 - 0
tests/misc/projects/Issue11832/compile3-fail.hxml.stderr

@@ -0,0 +1 @@
+a/b/F.hx:3: characters 8-9 : Type not found : C

+ 2 - 0
tests/misc/projects/Issue4781/compile-fail.hxml

@@ -0,0 +1,2 @@
+--main p.A
+--interp

+ 1 - 0
tests/misc/projects/Issue4781/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+p/A.hx:2: characters 17-20 : Module p.B does not define type T

+ 3 - 0
tests/misc/projects/Issue4781/p/A.hx

@@ -0,0 +1,3 @@
+package p;
+class A extends B.T {
+}

+ 3 - 0
tests/misc/projects/Issue4781/p/B.hx

@@ -0,0 +1,3 @@
+package p;
+class B {
+}