Browse Source

skip TCast(_, None) when checking for parameter default values (closes #2607)

Simon Krajewski 11 years ago
parent
commit
c7f32088e1
2 changed files with 17 additions and 3 deletions
  1. 11 0
      tests/unit/issues/Issue2607.hx
  2. 6 3
      typeload.ml

+ 11 - 0
tests/unit/issues/Issue2607.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue2607 extends unit.Test {
+	
+    inline static var CONST:Float = -1;
+	
+    function test(v = CONST) {
+        eq(v, -1);
+		t(Std.is(v, Float));
+    }
+}

+ 6 - 3
typeload.ml

@@ -1174,9 +1174,12 @@ let type_function ctx args ret fmode f do_display p =
 				let p = pos e in
 				let e = ctx.g.do_optimize ctx (type_expr ctx e (WithType t)) in
 				unify ctx e.etype t p;
-				match e.eexpr with
-				| TConst c -> Some c
-				| _ -> display_error ctx "Parameter default value should be constant" p; None
+				let rec loop e = match e.eexpr with
+					| TConst c -> Some c
+					| TCast(e,None) -> loop e
+					| _ -> display_error ctx "Parameter default value should be constant" p; None
+				in
+				loop e
 		) in
 		let v,c = add_local ctx n t, c in
 		if n = "this" then v.v_meta <- (Meta.This,[],p) :: v.v_meta;