Browse Source

don't forget to cache files for stringified positions (closes #9336)

Aleksandr Kuzmenko 5 years ago
parent
commit
398822f972

+ 9 - 1
src/syntax/lexer.ml

@@ -226,7 +226,15 @@ let resolve_pos file =
 		f
 		f
 
 
 let find_file file =
 let find_file file =
-	try Hashtbl.find all_files file with Not_found -> try resolve_pos file with Sys_error _ -> make_file file
+	try
+		Hashtbl.find all_files file
+	with Not_found ->
+		try
+			let f = resolve_pos file in
+			Hashtbl.add all_files file f;
+			f
+		with Sys_error _ ->
+			make_file file
 
 
 let find_pos p =
 let find_pos p =
 	find_line p.pmin (find_file p.pfile)
 	find_line p.pmin (find_file p.pfile)

+ 16 - 0
tests/misc/projects/Issue9336/Main.hx

@@ -0,0 +1,16 @@
+import haxe.macro.Context;
+
+class Main {
+	#if !macro
+	static function main(){
+		test();
+	}
+	#end
+	static macro function test() {
+		var pos = Context.makePosition({min: 20, max: 23, file: 'my_template.mtt' });
+		Context.warning(Std.string(pos), pos);
+		Context.parse('foo', pos);
+		Context.warning(Std.string(pos), pos);
+		return macro null;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9336/compile.hxml

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

+ 2 - 0
tests/misc/projects/Issue9336/compile.hxml.stderr

@@ -0,0 +1,2 @@
+my_template.mtt:2: characters 3-6 : Warning : #pos(my_template.mtt:2: characters 3-6)
+my_template.mtt:2: characters 3-6 : Warning : #pos(my_template.mtt:2: characters 3-6)

+ 2 - 0
tests/misc/projects/Issue9336/my_template.mtt

@@ -0,0 +1,2 @@
+<div>&nbsp;</div>
+::foo()::