Selaa lähdekoodia

[parser] make type paths more robust again

we failed on `new | call()` because it tried to parse `call()` as a type path
Simon Krajewski 7 vuotta sitten
vanhempi
commit
3175ea5874
2 muutettua tiedostoa jossa 20 lisäystä ja 3 poistoa
  1. 12 3
      src/syntax/grammar.mly
  2. 8 0
      tests/display/src/cases/Issue7051.hx

+ 12 - 3
src/syntax/grammar.mly

@@ -771,9 +771,18 @@ and parse_constraint_param = parser
 			tp_meta = meta;
 		}
 
-and parse_type_path_or_resume p1 s = match s with parser
-	| [< t = parse_type_path >] -> t,false
-	| [< >] -> if would_skip_resume p1 s then (magic_type_path,punion_next p1 s),true else raise Stream.Failure
+and parse_type_path_or_resume p1 s =
+	let pnext = next_pos s in
+	let check_resume exc =
+		if do_resume() && is_resuming_file p1.pfile && encloses_resume (punion p1 pnext) then
+			(magic_type_path,punion_next p1 s),true
+		else
+			raise exc
+	in
+	try
+		let t = parse_type_path s in
+		t,false
+	with Stream.Failure | Stream.Error _ as exc -> check_resume exc
 
 and parse_class_herit = parser
 	| [< '(Kwd Extends,p1); t,_ = parse_type_path_or_resume p1 >] -> HExtends t

+ 8 - 0
tests/display/src/cases/Issue7051.hx

@@ -32,4 +32,12 @@ class Issue7051 extends DisplayTestCase {
 		eq(true, hasToplevel(toplevel, "type", "AWithCtor"));
 		eq(false, hasToplevel(toplevel, "type", "AWithoutCtor"));
 	}
+
+	/**
+	new {-1-}
+	call();
+	**/
+	@:funcCode function testBroken() {
+		eq(true, hasToplevel(toplevel(pos(1)), "type", "Array"));
+	}
 }