소스 검색

allow ComplexType return from @:genericBuild macros, deprecate Type return (closes #3176)

Simon Krajewski 11 년 전
부모
커밋
85c80a18d2
2개의 변경된 파일17개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 0
      extra/CHANGES.txt
  2. 16 2
      typer.ml

+ 1 - 0
extra/CHANGES.txt

@@ -37,6 +37,7 @@
 
 	macro : added Context.getLocalTVars
 	macro : added TypedExprTools.iter
+	macro : changed @:genericBuild macros to prefer ComplexType returns
 
 	Deprecations:
 

+ 16 - 2
typer.ml

@@ -4410,7 +4410,13 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 	| MMacroType ->
 		let cttype = { tpackage = ["haxe";"macro"]; tname = "Type"; tparams = []; tsub = None } in
 		let ttype = Typeload.load_instance mctx cttype p false in
-		unify mctx mret ttype mpos
+		try
+			unify_raise mctx mret ttype mpos;
+			ctx.com.warning "Returning Type from @:genericBuild macros is deprecated, consider returning ComplexType instead" p;
+		with Error (Unify _,_) ->
+			let cttype = { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = Some ("ComplexType") } in
+			let ttype = Typeload.load_instance mctx cttype p false in
+			unify_raise mctx mret ttype mpos;
 	);
 	(*
 		if the function's last argument is of Array<Expr>, split the argument list and use [] for unify_call_params
@@ -4506,7 +4512,15 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 					) in
 					(EVars ["fields",Some (CTAnonymous fields),None],p)
 				| MMacroType ->
-					ctx.ret <- Interp.decode_type v;
+					let t = if v = Interp.VNull then
+						mk_mono()
+					else try
+						let ct = Interp.decode_ctype v in
+						Typeload.load_complex_type ctx p ct;
+					with Interp.Invalid_expr ->
+						Interp.decode_type v
+					in
+					ctx.ret <- t;
 					(EBlock [],p)
 				)
 			with Interp.Invalid_expr ->