浏览代码

[typer] don't hard error on non-existent imports

see #9142
Simon Krajewski 5 年之前
父节点
当前提交
7ae21fa254
共有 2 个文件被更改,包括 25 次插入2 次删除
  1. 9 2
      src/typing/typeloadModule.ml
  2. 16 0
      tests/display/src/cases/Issue9142.hx

+ 9 - 2
src/typing/typeloadModule.ml

@@ -409,8 +409,7 @@ let init_module_type ctx context_init (decl,p) =
 		if Filename.basename p.pfile <> "import.hx" then ImportHandling.add_import_position ctx p path;
 		if DisplayPosition.display_position#is_in_file p.pfile then DisplayPath.handle_path_display ctx path p
 	in
-	match decl with
-	| EImport (path,mode) ->
+	let init_import path mode =
 		ctx.m.module_imports <- (path,mode) :: ctx.m.module_imports;
 		check_path_display path p;
 		let rec loop acc = function
@@ -530,6 +529,14 @@ let init_module_type ctx context_init (decl,p) =
 						error "No statics to import from this type" p
 				)
 			))
+	in
+	match decl with
+	| EImport (path,mode) ->
+		begin try
+			init_import path mode
+		with Error(Module_not_found _ as err,p) ->
+			display_error ctx (Error.error_msg err) p
+		end
 	| EUsing path ->
 		check_path_display path p;
 		let types,filter_classes = handle_using ctx path p in

+ 16 - 0
tests/display/src/cases/Issue9142.hx

@@ -0,0 +1,16 @@
+package cases;
+
+class Issue9142 extends DisplayTestCase {
+	/**
+		import NonExistent;
+
+		class Main {
+			static function main() {
+				"fo{-1-}o"
+			}
+		}
+	**/
+	function testNonExistentImport() {
+		eq("String", type(pos(1)));
+	}
+}