ソースを参照

[parser] warn about #if display

Rudy Ges 3 日 前
コミット
a5b974aa9c
2 ファイル変更9 行追加1 行削除
  1. 5 0
      src-json/warning.json
  2. 4 1
      src/syntax/grammar.ml

+ 5 - 0
src-json/warning.json

@@ -125,6 +125,11 @@
 		"parent": "WTyper",
 		"enabled": false
 	},
+	{
+		"name": "WIfDisplay",
+		"doc": "Using `display` here doesn't work because #if conditions are evaluated at parse time. In macros, use `haxe.macro.Context.defined(\"display\")` instead.",
+		"parent": "WParser"
+	},
 	{
 		"name": "WHxb",
 		"doc": "Hxb (either --hxb output or haxe compiler cache) related warnings"

+ 4 - 1
src/syntax/grammar.ml

@@ -1807,7 +1807,10 @@ let rec validate_macro_cond ctx s e = match fst e with
 	| _ -> syntax_error ctx (Custom ("Invalid conditional expression")) ~pos:(Some (pos e)) s ((EConst (Ident "false"),(pos e)))
 
 and parse_macro_ident ctx t p s =
-	if t = "display" then Option.may (fun h -> ThreadSafeHashtbl.replace h (Path.UniqueKey.create p.pfile) t) ctx.config.special_identifier_files;
+	if t = "display" then begin
+		syntax_warning_with_pos ctx Warning.WIfDisplay p;
+		Option.may (fun h -> ThreadSafeHashtbl.replace h (Path.UniqueKey.create p.pfile) t) ctx.config.special_identifier_files
+	end;
 	(EConst (Ident t),p)
 
 let rec parse_macro_cond ctx s =