Przeglądaj źródła

[parser] deal with `var @`

closes #9639
Simon Krajewski 3 lat temu
rodzic
commit
2c3974d189

+ 8 - 1
src/syntax/grammar.mly

@@ -1184,7 +1184,14 @@ and parse_var_decl_head final s =
 	let meta = parse_meta s in
 	match s with parser
 	| [< name, p = dollar_ident; t = popt parse_type_hint >] -> (meta,name,final,t,p)
-	| [< >] -> no_keyword "variable name" s
+	| [< >] ->
+		(* This nonsense is here for the var @ case in issue #9639 *)
+		let rec loop meta = match meta with
+			| (Meta.HxCompletion,_,p) :: _ -> (meta,"",false,None,null_pos)
+			| _ :: meta -> loop meta
+			| [] -> no_keyword "variable name" s
+		in
+		loop meta
 
 and parse_var_assignment = parser
 	| [< '(Binop OpAssign,p1); s >] ->

+ 1 - 0
src/typing/typer.ml

@@ -612,6 +612,7 @@ and type_vars ctx vl p =
 			) in
 			let v = add_local_with_origin ctx TVOLocalVariable n t pv in
 			v.v_meta <- ev.ev_meta;
+			DisplayEmitter.check_display_metadata ctx v.v_meta;
 			if ev.ev_final then add_var_flag v VFinal;
 			if ctx.in_display && DisplayPosition.display_position#enclosed_in pv then
 				DisplayEmitter.display_variable ctx v pv;

+ 45 - 0
tests/display/src/cases/Metadata.hx

@@ -145,4 +145,49 @@ class Metadata extends DisplayTestCase {
 		eq(true, hasPath(fields(pos(1)), "@:generic"));
 		eq(true, hasPath(fields(pos(2)), "@:generic"));
 	}
+
+	/**
+		function main() {
+			var @{-1-}
+		}
+	**/
+	function test9639_1() {
+		eq(true, hasPath(fields(pos(1)), "@:generic"));
+	}
+
+	/**
+		function main() {
+			var @{-1-} local
+		}
+	**/
+	function test9639_2() {
+		eq(true, hasPath(fields(pos(1)), "@:generic"));
+	}
+
+	/**
+		function main() {
+			var @{-1-} local : Type
+		}
+	**/
+	function test9639_3() {
+		eq(true, hasPath(fields(pos(1)), "@:generic"));
+	}
+
+	/**
+		function main() {
+			var @{-1-} local =
+		}
+	**/
+	function test9639_4() {
+		eq(true, hasPath(fields(pos(1)), "@:generic"));
+	}
+
+	/**
+		function main() {
+			var @{-1-} local = 10
+		}
+	**/
+	function test9639_5() {
+		eq(true, hasPath(fields(pos(1)), "@:generic"));
+	}
 }