Browse Source

fixed negative const as type parameters in @:generic (closes #9149)

Aleksandr Kuzmenko 5 years ago
parent
commit
2c5d28b22b
2 changed files with 17 additions and 0 deletions
  1. 2 0
      src/syntax/grammar.mly
  2. 15 0
      tests/unit/src/unit/issues/Issue9149.hx

+ 2 - 0
src/syntax/grammar.mly

@@ -669,6 +669,8 @@ and parse_type_path_or_const plt = parser
 	(* we can't allow (expr) here *)
 	| [< '(BkOpen,p1); e = parse_array_decl p1 >] -> TPExpr (e)
 	| [< t = parse_complex_type >] -> TPType t
+	| [< '(Unop op,p1); '(Const c,p2) >] -> TPExpr (make_unop op (EConst c,p2) p1)
+	| [< '(Binop OpSub,p1); '(Const c,p2) >] -> TPExpr (make_unop Neg (EConst c,p2) p1)
 	| [< '(Const c,p) >] -> TPExpr (EConst c,p)
 	| [< '(Kwd True,p) >] -> TPExpr (EConst (Ident "true"),p)
 	| [< '(Kwd False,p) >] -> TPExpr (EConst (Ident "false"),p)

+ 15 - 0
tests/unit/src/unit/issues/Issue9149.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+import unit.Test;
+
+class Issue9149 extends Test {
+	public function test() {
+		eq(-3, new Bleh<-3>().say());
+	}
+}
+
+@:generic
+private class Bleh<@:const Root> {
+	public function new() { }
+	public function say() return Root;
+}