浏览代码

[matcher] send typed expressions through the converter

closes #7359
Simon Krajewski 7 年之前
父节点
当前提交
e884775916
共有 4 个文件被更改,包括 32 次插入2 次删除
  1. 4 0
      src/typing/macroContext.ml
  2. 3 0
      src/typing/matcher.ml
  3. 1 2
      src/typing/typer.ml
  4. 24 0
      tests/unit/src/unit/issues/Issue7359.hx

+ 4 - 0
src/typing/macroContext.ml

@@ -813,5 +813,9 @@ let interpret ctx =
 let setup() =
 	Interp.setup Interp.macro_api
 
+let type_stored_expr ctx e1 =
+	let id = match e1 with (EConst (Int s),_) -> int_of_string s | _ -> assert false in
+	get_stored_typed_expr ctx.com id
+
 ;;
 load_macro_ref := load_macro;

+ 3 - 0
src/typing/matcher.ml

@@ -484,6 +484,9 @@ module Pattern = struct
 				let pat = loop e in
 				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType t));
 				pat
+			| EMeta((Meta.StoredTypedExpr,_,_),e1) ->
+				let e1 = MacroContext.type_stored_expr ctx e1 in
+				loop (TExprToExpr.convert_expr e1)
 			| _ ->
 				fail()
 		in

+ 1 - 2
src/typing/typer.ml

@@ -2250,8 +2250,7 @@ and type_meta ctx m e1 with_type p =
 			| _ -> e()
 			end
 		| (Meta.StoredTypedExpr,_,_) ->
-			let id = match e1 with (EConst (Int s),_) -> int_of_string s | _ -> assert false in
-			MacroContext.get_stored_typed_expr ctx.com id
+			MacroContext.type_stored_expr ctx e1
 		| (Meta.NoPrivateAccess,_,_) ->
 			ctx.meta <- List.filter (fun(m,_,_) -> m <> Meta.PrivateAccess) ctx.meta;
 			e()

+ 24 - 0
tests/unit/src/unit/issues/Issue7359.hx

@@ -0,0 +1,24 @@
+package unit.issues;
+
+import haxe.macro.Context;
+import haxe.macro.Expr;
+
+class Issue7359 extends unit.Test {
+	function test() {
+		#if !macro
+		eq("no", m(11));
+		eq("yes", m(1));
+		#end
+	}
+
+	static macro function m(e) {
+		var stored = haxe.macro.Context.storeTypedExpr(haxe.macro.Context.typeExpr(e));
+		var got = haxe.macro.Context.getTypedExpr(haxe.macro.Context.typeExpr(e));
+
+		// When using storedTypedExpr switch is invalid
+		var c = {expr:macro "yes", guard:null, values:[stored]};
+
+		var s = {expr:ESwitch(macro 1, [c], macro "no"), pos:Context.currentPos()};
+		return s;
+	}
+}