Pārlūkot izejas kodu

added is_macro_ctx to Typer.create (fixed all typing related unit tests)

Simon Krajewski 13 gadi atpakaļ
vecāks
revīzija
7526a332de
5 mainītis faili ar 8 papildinājumiem un 20 dzēšanām
  1. 2 2
      main.ml
  2. 0 12
      tests/unit/TestType.hx
  3. 1 1
      typecore.ml
  4. 1 1
      typeload.ml
  5. 4 4
      typer.ml

+ 2 - 2
main.ml

@@ -1013,7 +1013,7 @@ try
 		Common.log com ("Defines : " ^ (String.concat ";" (PMap.foldi (fun v _ acc -> v :: acc) com.defines [])));
 		let t = Common.timer "typing" in
 		Typecore.type_expr_ref := (fun ctx e need_val -> Typer.type_expr ~need_val ctx e);
-		let tctx = Typer.create com in
+		let tctx = Typer.create com false in
 		List.iter (Typer.call_init_macro tctx) (List.rev !config_macros);
 		List.iter (fun cpath -> ignore(tctx.Typecore.g.Typecore.do_load_module tctx cpath Ast.null_pos)) (List.rev !classes);
 		Typer.finalize tctx;
@@ -1144,7 +1144,7 @@ with
 				complete_fields (List.map (fun f -> f,"","") (packs @ classes))
 		| Some (c,cur_package) ->
 			try
-				let ctx = Typer.create com in
+				let ctx = Typer.create com false in
 				let rec lookup p =
 					try
 						Typeload.load_module ctx (p,c) Ast.null_pos

+ 0 - 12
tests/unit/TestType.hx

@@ -98,7 +98,6 @@ class TestType extends Test {
 	}
 	
 	function testUnifyMin() {
-		#if !macro
 
 		// array
 		
@@ -184,15 +183,12 @@ class TestType extends Test {
 		#if flash9
 		typedAs(function() { return 0; var v:UInt = 0; return v; } (), 1);
 		#end
-
-		#end
 	}
 
 	function testCallback()
 	{
 		var func = function(a:Int, b:String, c:Float) return a;
 
-		#if !macro
 		var tstringfloat = function(b:String, c:Float) return 0;
 		var tfloat = function(c:Float) return 0;
 		var tvoid = function() return 0;
@@ -230,8 +226,6 @@ class TestType extends Test {
 		typedAs(callback(func, _, "22", 12), tint);
 		typedAs(callback(func, 12, _, 12), tstring);
 		
-		#end
-		
 		// values
 		
 		eq(1, callback(func)(1, "2", 3));
@@ -285,7 +279,6 @@ class TestType extends Test {
 	
 	function testConstantAnonCovariance()
 	{
-		#if !macro
 		var func = function (str:String, ?str1: { x:Float, y:Int }, ?str2: { w:Float, h:Int } ) { };
 		var a: { v:Float };
 		var b:Dynamic = "bar";
@@ -305,12 +298,10 @@ class TestType extends Test {
 		t(typeError(a = { v:0, " foo":2 } ));
 		f(typeError(func("foo", { x:1.2, y:2 } )));
 		f(typeError(func("foo", { w:1.2, h:2 } )));
-		#end
 	}
 	
 	function testCovariantReturn()
 	{
-		#if !macro
 		var b:Base = null;
 		var c1:Child1 = null;
 		var c2_1:Child2_1 = null;
@@ -338,19 +329,16 @@ class TestType extends Test {
 		var c3 = new Cov3();
 		typedAs(c3.covariant(), c2_1);
 		t(Std.is(c3.covariant(), Child2_1));
-		#end
 	}
 	
 	function testContravariantArgs()
 	{
-		#if !macro
 		var b = function(arg:Base):Void { };
 		var c1 = function(arg:Child1):Void { };
 		
 		var c = new Ctrv2();
 		typedAs(c.contravariant, b);
 		typedAs(cast (c, Ctrv1).contravariant, c1);
-		#end
 	}
 	
 	function testInitFields()

+ 1 - 1
typecore.ml

@@ -49,7 +49,7 @@ type typer_globals = {
 	mutable get_build_infos : unit -> (module_type * Ast.class_field list) option;
 	(* api *)
 	do_inherit : typer -> Type.tclass -> Ast.pos -> Ast.class_flag -> bool;
-	do_create : Common.context -> typer;
+	do_create : Common.context -> bool -> typer;
 	do_macro : typer -> macro_mode -> path -> string -> Ast.expr list -> Ast.pos -> Ast.expr option;
 	do_load_module : typer -> path -> pos -> module_def;
 	do_optimize : typer -> texpr -> texpr;

+ 1 - 1
typeload.ml

@@ -694,7 +694,7 @@ let init_core_api ctx c =
 			let com2 = Common.clone ctx.com in
 			Common.define com2 "core_api";
 			com2.class_path <- ctx.com.std_path;
-			let ctx2 = ctx.g.do_create com2 in
+			let ctx2 = ctx.g.do_create com2 ctx.in_macro in
 			ctx.g.core_api <- Some ctx2;
 			ctx2
 		| Some c ->

+ 4 - 4
typer.ml

@@ -2746,9 +2746,8 @@ let get_macro_context ctx p =
 			| _ when List.exists (fun (_,d) -> "flash" ^ d = k) Common.flash_versions -> acc
 			| _ -> PMap.add k () acc
 		) com2.defines PMap.empty;
-		Common.define com2 "macro";
 		Common.init_platform com2 Neko;
-		let ctx2 = ctx.g.do_create com2 in
+		let ctx2 = ctx.g.do_create com2 true in
 		let mctx = Interp.create com2 api in
 		let on_error = com2.error in
 		com2.error <- (fun e p -> Interp.set_error mctx true; on_error e p);
@@ -2961,7 +2960,8 @@ let call_init_macro ctx e =
 (* ---------------------------------------------------------------------- *)
 (* TYPER INITIALIZATION *)
 
-let rec create com =
+let rec create com is_macro_ctx =
+	if is_macro_ctx then Common.define com "macro";
 	let ctx = {
 		com = com;
 		t = com.basic;
@@ -2988,7 +2988,7 @@ let rec create com =
 		in_loop = false;
 		in_super_call = false;
 		in_display = false;
-		in_macro = Common.defined com "macro";
+		in_macro = is_macro_ctx;
 		ret = mk_mono();
 		locals = PMap.empty;
 		local_types = [];