Browse Source

[cs] never try unwrapping Null<T> constants (closes #4968)

Dan Korostelev 8 years ago
parent
commit
7446f01b45
2 changed files with 19 additions and 0 deletions
  1. 2 0
      src/generators/gencs.ml
  2. 17 0
      tests/unit/src/unit/issues/Issue4968.hx

+ 2 - 0
src/generators/gencs.ml

@@ -2689,6 +2689,8 @@ let generate con =
 				match e.eexpr, real_type e.etype with
 					| TConst TThis, _ when gen.gcurrent_path = (["haxe";"lang"], "Null") ->
 						e
+					| TConst (TInt _ | TFloat _ | TBool _), _ ->
+						e
 					| _, TInst({ cl_path = (["haxe";"lang"], "Null") }, [t]) ->
 						let e = { e with eexpr = TParenthesis(e) } in
 						{ (mk_field_access gen e "value" e.epos) with etype = t }

+ 17 - 0
tests/unit/src/unit/issues/Issue4968.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+
+private class C {
+	public final v:Int;
+	function new(v:Int) this.v = v;
+	static function f(v:Int) return v;
+
+	public static inline function g(?v = 0) return new C(v);
+	public static inline function g2(?v = 0) return f(v);
+}
+
+class Issue4968 extends Test {
+	function test() {
+		eq(C.g().v, 0);
+		eq(C.g2(), 0);
+	}
+}