Ver Fonte

Fix #8187 (#8474)

* allow enum constructors without arguments in static inlines

* test

* move test
Aurel há 6 anos atrás
pai
commit
8e15d573bf
2 ficheiros alterados com 14 adições e 0 exclusões
  1. 1 0
      src/optimization/optimizer.ml
  2. 13 0
      tests/unit/src/unit/issues/Issue8187.hx

+ 1 - 0
src/optimization/optimizer.ml

@@ -316,6 +316,7 @@ let rec make_constant_expression ctx ?(concat_strings=false) e =
 	let e = reduce_loop ctx e in
 	match e.eexpr with
 	| TConst _ -> Some e
+	| TField({eexpr = TTypeExpr _},FEnum _) -> Some e
 	| TBinop ((OpAdd|OpSub|OpMult|OpDiv|OpMod|OpShl|OpShr|OpUShr|OpOr|OpAnd|OpXor) as op,e1,e2) -> (match make_constant_expression ctx e1,make_constant_expression ctx e2 with
 		| Some ({eexpr = TConst (TString s1)}), Some ({eexpr = TConst (TString s2)}) when concat_strings ->
 			Some (mk (TConst (TString (s1 ^ s2))) ctx.com.basic.tstring (punion e1.epos e2.epos))

+ 13 - 0
tests/unit/src/unit/issues/Issue8187.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue8187 extends unit.Test {
+	static inline var enumValue = Leaf;
+	function test() {
+		eq(enumValue, Leaf);
+	}
+}
+
+private enum Tree {
+	Leaf;
+	Node(a:Tree, b:Tree);
+}